codecs from string not bools.

This commit is contained in:
Miroslav Šedivý 2022-09-17 14:07:35 +02:00
parent ccbfe93765
commit 057ab2d886
4 changed files with 84 additions and 59 deletions

View File

@ -10,6 +10,7 @@
### Misc ### Misc
- Server: Split `remote` to `desktop` and `capture`. - Server: Split `remote` to `desktop` and `capture`.
- Server: Refactored `xorg` - added `xevent` and clipboard is handled as event (no looped polling anymore). - Server: Refactored `xorg` - added `xevent` and clipboard is handled as event (no looped polling anymore).
- Introduced `NEKO_AUDIO_CODEC=` and `NEKO_VIDEO_CODEC=` as a new way of setting codecs.
## [n.eko v2.6](https://github.com/m1k1o/neko/releases/tag/v2.6) ## [n.eko v2.6](https://github.com/m1k1o/neko/releases/tag/v2.6)

View File

@ -64,15 +64,10 @@ nat1to1: <ip>
### Video ### Video
#### `NEKO_VP8`: #### `NEKO_VIDEO_CODEC`:
- If vp8 should be used as video encoder for the stream *(default encoder)*. - vp8 *(default encoder)*
- e.g. `true` - vp9 *(parameter not optimized yet)*
#### `NEKO_VP9`: - h264 *(second best option)*
- If vp9 should be used as video encoder for the stream *(parameter not optimized yet)*.
- e.g. `false`
#### `NEKO_H264`:
- If h264 should be used as video encoder for the stream *(second best option)*.
- e.g. `false`
#### `NEKO_VIDEO_BITRATE`: #### `NEKO_VIDEO_BITRATE`:
- Bitrate of the video stream in kb/s. - Bitrate of the video stream in kb/s.
- e.g. 3500 - e.g. 3500
@ -93,18 +88,11 @@ nat1to1: <ip>
### Audio ### Audio
#### `NEKO_OPUS`: #### `NEKO_AUDIO_CODEC`:
- If opus should be used as audio encoder for the stream *(default encoder)*. - opus *(default encoder)*
- e.g. `true` - g722
#### `NEKO_G722`: - pcmu
- If g722 should be used as audio encoder for the stream. - pcma
- e.g. `false`
#### `NEKO_PCMU`:
- If pcmu should be used as audio encoder for the stream.
- e.g. `false`
#### `NEKO_PCMA`:
- If pcma should be used as audio encoder for the stream.
- e.g. `false`
#### `NEKO_AUDIO_BITRATE`: #### `NEKO_AUDIO_BITRATE`:
- Bitrate of the audio stream in kb/s. - Bitrate of the audio stream in kb/s.
- e.g. `196` - e.g. `196`
@ -158,6 +146,7 @@ Usage:
Flags: Flags:
--audio string audio codec parameters to use for streaming --audio string audio codec parameters to use for streaming
--audio_bitrate int audio bitrate in kbit/s (default 128) --audio_bitrate int audio bitrate in kbit/s (default 128)
--audio_codec string audio codec to be used (default "opus")
--bind string address/port/socket to serve neko (default "127.0.0.1:8080") --bind string address/port/socket to serve neko (default "127.0.0.1:8080")
--broadcast_pipeline string custom gst pipeline used for broadcasting, strings {url} {device} {display} will be replaced --broadcast_pipeline string custom gst pipeline used for broadcasting, strings {url} {device} {display} will be replaced
--broadcast_url string URL for broadcasting, setting this value will automatically enable broadcasting --broadcast_url string URL for broadcasting, setting this value will automatically enable broadcasting
@ -166,8 +155,8 @@ Flags:
--device string audio device to capture (default "auto_null.monitor") --device string audio device to capture (default "auto_null.monitor")
--display string XDisplay to capture (default ":99.0") --display string XDisplay to capture (default ":99.0")
--epr string limits the pool of ephemeral ports that ICE UDP connections can allocate from (default "59000-59100") --epr string limits the pool of ephemeral ports that ICE UDP connections can allocate from (default "59000-59100")
--g722 use G722 audio codec --g722 DEPRECATED: use audio_codec
--h264 use H264 video codec --h264 DEPRECATED: use video_codec
-h, --help help for serve -h, --help help for serve
--hwenc string use hardware accelerated encoding --hwenc string use hardware accelerated encoding
--icelite configures whether or not the ice agent should be a lite agent --icelite configures whether or not the ice agent should be a lite agent
@ -179,11 +168,12 @@ Flags:
--locks strings resources, that will be locked when starting (control, login) --locks strings resources, that will be locked when starting (control, login)
--max_fps int maximum fps delivered via WebRTC, 0 is for no maximum (default 25) --max_fps int maximum fps delivered via WebRTC, 0 is for no maximum (default 25)
--nat1to1 strings sets a list of external IP addresses of 1:1 (D)NAT and a candidate type for which the external IP address is used --nat1to1 strings sets a list of external IP addresses of 1:1 (D)NAT and a candidate type for which the external IP address is used
--opus use Opus audio codec --opus DEPRECATED: use audio_codec
--password string password for connecting to stream (default "neko") --password string password for connecting to stream (default "neko")
--password_admin string admin password for connecting to stream (default "admin") --password_admin string admin password for connecting to stream (default "admin")
--pcma use PCMA audio codec --path_prefix string path prefix for HTTP requests (default "/")
--pcmu use PCMU audio codec --pcma DEPRECATED: use audio_codec
--pcmu DEPRECATED: use audio_codec
--proxy enable reverse proxy mode --proxy enable reverse proxy mode
--screen string default screen resolution and framerate (default "1280x720@30") --screen string default screen resolution and framerate (default "1280x720@30")
--static string path to neko client files to serve (default "./www") --static string path to neko client files to serve (default "./www")
@ -191,8 +181,9 @@ Flags:
--udpmux int single UDP mux port for all peers --udpmux int single UDP mux port for all peers
--video string video codec parameters to use for streaming --video string video codec parameters to use for streaming
--video_bitrate int video bitrate in kbit/s (default 3072) --video_bitrate int video bitrate in kbit/s (default 3072)
--vp8 use VP8 video codec --video_codec string video codec to be used (default "vp8")
--vp9 use VP9 video codec --vp8 DEPRECATED: use video_codec
--vp9 DEPRECATED: use video_codec
Global Flags: Global Flags:
--config string configuration file path --config string configuration file path

View File

@ -98,7 +98,7 @@ services:
! v4l2h264enc extra-controls="controls,h264_profile=0,video_bitrate=1250000;" ! v4l2h264enc extra-controls="controls,h264_profile=0,video_bitrate=1250000;"
! h264parse config-interval=3 ! h264parse config-interval=3
! video/x-h264,profile=baseline,stream-format=byte-stream ! video/x-h264,profile=baseline,stream-format=byte-stream
NEKO_H264: 1 NEKO_VIDEO_CODEC: h264
``` ```
## Not using docker? ## Not using docker?

View File

@ -3,6 +3,8 @@ package config
import ( import (
"m1k1o/neko/internal/types/codec" "m1k1o/neko/internal/types/codec"
"github.com/pion/webrtc/v3"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -38,23 +40,28 @@ func (Capture) Init(cmd *cobra.Command) error {
return err return err
} }
// video codecs cmd.PersistentFlags().String("video_codec", "vp8", "video codec to be used")
// TODO: video.codec if err := viper.BindPFlag("video_codec", cmd.PersistentFlags().Lookup("video_codec")); err != nil {
cmd.PersistentFlags().Bool("vp8", false, "use VP8 video codec") return err
}
// DEPRECATED: video codec
cmd.PersistentFlags().Bool("vp8", false, "DEPRECATED: use video_codec")
if err := viper.BindPFlag("vp8", cmd.PersistentFlags().Lookup("vp8")); err != nil { if err := viper.BindPFlag("vp8", cmd.PersistentFlags().Lookup("vp8")); err != nil {
return err return err
} }
cmd.PersistentFlags().Bool("vp9", false, "use VP9 video codec") // DEPRECATED: video codec
cmd.PersistentFlags().Bool("vp9", false, "DEPRECATED: use video_codec")
if err := viper.BindPFlag("vp9", cmd.PersistentFlags().Lookup("vp9")); err != nil { if err := viper.BindPFlag("vp9", cmd.PersistentFlags().Lookup("vp9")); err != nil {
return err return err
} }
cmd.PersistentFlags().Bool("h264", false, "use H264 video codec") // DEPRECATED: video codec
cmd.PersistentFlags().Bool("h264", false, "DEPRECATED: use video_codec")
if err := viper.BindPFlag("h264", cmd.PersistentFlags().Lookup("h264")); err != nil { if err := viper.BindPFlag("h264", cmd.PersistentFlags().Lookup("h264")); err != nil {
return err return err
} }
// video codecs
cmd.PersistentFlags().String("hwenc", "", "use hardware accelerated encoding") cmd.PersistentFlags().String("hwenc", "", "use hardware accelerated encoding")
if err := viper.BindPFlag("hwenc", cmd.PersistentFlags().Lookup("hwenc")); err != nil { if err := viper.BindPFlag("hwenc", cmd.PersistentFlags().Lookup("hwenc")); err != nil {
@ -85,24 +92,31 @@ func (Capture) Init(cmd *cobra.Command) error {
return err return err
} }
// audio codecs cmd.PersistentFlags().String("audio_codec", "opus", "audio codec to be used")
// TODO: audio.codec if err := viper.BindPFlag("audio_codec", cmd.PersistentFlags().Lookup("audio_codec")); err != nil {
cmd.PersistentFlags().Bool("opus", false, "use Opus audio codec") return err
}
// DEPRECATED: audio codec
cmd.PersistentFlags().Bool("opus", false, "DEPRECATED: use audio_codec")
if err := viper.BindPFlag("opus", cmd.PersistentFlags().Lookup("opus")); err != nil { if err := viper.BindPFlag("opus", cmd.PersistentFlags().Lookup("opus")); err != nil {
return err return err
} }
cmd.PersistentFlags().Bool("g722", false, "use G722 audio codec") // DEPRECATED: audio codec
cmd.PersistentFlags().Bool("g722", false, "DEPRECATED: use audio_codec")
if err := viper.BindPFlag("g722", cmd.PersistentFlags().Lookup("g722")); err != nil { if err := viper.BindPFlag("g722", cmd.PersistentFlags().Lookup("g722")); err != nil {
return err return err
} }
cmd.PersistentFlags().Bool("pcmu", false, "use PCMU audio codec") // DEPRECATED: audio codec
cmd.PersistentFlags().Bool("pcmu", false, "DEPRECATED: use audio_codec")
if err := viper.BindPFlag("pcmu", cmd.PersistentFlags().Lookup("pcmu")); err != nil { if err := viper.BindPFlag("pcmu", cmd.PersistentFlags().Lookup("pcmu")); err != nil {
return err return err
} }
cmd.PersistentFlags().Bool("pcma", false, "use PCMA audio codec") // DEPRECATED: audio codec
cmd.PersistentFlags().Bool("pcma", false, "DEPRECATED: use audio_codec")
if err := viper.BindPFlag("pcma", cmd.PersistentFlags().Lookup("pcma")); err != nil { if err := viper.BindPFlag("pcma", cmd.PersistentFlags().Lookup("pcma")); err != nil {
return err return err
} }
@ -136,21 +150,31 @@ func (Capture) Init(cmd *cobra.Command) error {
} }
func (s *Capture) Set() { func (s *Capture) Set() {
var ok bool
// //
// video // video
// //
s.Display = viper.GetString("display") s.Display = viper.GetString("display")
videoCodec := codec.VP8() videoCodec := viper.GetString("video_codec")
if viper.GetBool("vp8") { s.VideoCodec, ok = codec.ParseStr(videoCodec)
videoCodec = codec.VP8() if !ok || s.VideoCodec.Type != webrtc.RTPCodecTypeVideo {
} else if viper.GetBool("vp9") { log.Warn().Str("codec", videoCodec).Msgf("unknown video codec, using Vp8")
videoCodec = codec.VP9() s.VideoCodec = codec.VP8()
} else if viper.GetBool("h264") { }
videoCodec = codec.H264()
if viper.GetBool("vp8") {
s.VideoCodec = codec.VP8()
log.Warn().Msg("you are using deprecated config setting 'NEKO_VP8=true', use 'NEKO_VIDEO_CODEC=vp8' instead")
} else if viper.GetBool("vp9") {
s.VideoCodec = codec.VP9()
log.Warn().Msg("you are using deprecated config setting 'NEKO_VP9=true', use 'NEKO_VIDEO_CODEC=vp9' instead")
} else if viper.GetBool("h264") {
s.VideoCodec = codec.H264()
log.Warn().Msg("you are using deprecated config setting 'NEKO_H264=true', use 'NEKO_VIDEO_CODEC=h264' instead")
} }
s.VideoCodec = videoCodec
videoHWEnc := "" videoHWEnc := ""
if viper.GetString("hwenc") == "VAAPI" { if viper.GetString("hwenc") == "VAAPI" {
@ -168,17 +192,26 @@ func (s *Capture) Set() {
s.AudioDevice = viper.GetString("device") s.AudioDevice = viper.GetString("device")
audioCodec := codec.Opus() audioCodec := viper.GetString("audio_codec")
if viper.GetBool("opus") { s.AudioCodec, ok = codec.ParseStr(audioCodec)
audioCodec = codec.Opus() if !ok || s.AudioCodec.Type != webrtc.RTPCodecTypeAudio {
} else if viper.GetBool("g722") { log.Warn().Str("codec", audioCodec).Msgf("unknown audio codec, using Opus")
audioCodec = codec.G722() s.AudioCodec = codec.Opus()
} else if viper.GetBool("pcmu") { }
audioCodec = codec.PCMU()
} else if viper.GetBool("pcma") { if viper.GetBool("opus") {
audioCodec = codec.PCMA() s.AudioCodec = codec.Opus()
log.Warn().Msg("you are using deprecated config setting 'NEKO_OPUS=true', use 'NEKO_VIDEO_CODEC=opus' instead")
} else if viper.GetBool("g722") {
s.AudioCodec = codec.G722()
log.Warn().Msg("you are using deprecated config setting 'NEKO_G722=true', use 'NEKO_VIDEO_CODEC=g722' instead")
} else if viper.GetBool("pcmu") {
s.AudioCodec = codec.PCMU()
log.Warn().Msg("you are using deprecated config setting 'NEKO_PCMU=true', use 'NEKO_VIDEO_CODEC=pcmu' instead")
} else if viper.GetBool("pcma") {
s.AudioCodec = codec.PCMA()
log.Warn().Msg("you are using deprecated config setting 'NEKO_PCMA=true', use 'NEKO_VIDEO_CODEC=pcma' instead")
} }
s.AudioCodec = audioCodec
s.AudioBitrate = viper.GetUint("audio_bitrate") s.AudioBitrate = viper.GetUint("audio_bitrate")
s.AudioPipeline = viper.GetString("audio") s.AudioPipeline = viper.GetString("audio")