switch to VP8 with multiple qualities.

This commit is contained in:
Miroslav Šedivý 2021-02-06 18:18:49 +01:00
parent eb88c8dc62
commit 1838a74213
2 changed files with 67 additions and 47 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"demodesk/neko/internal/types" "demodesk/neko/internal/types"
"demodesk/neko/internal/types/codec"
"demodesk/neko/internal/config" "demodesk/neko/internal/config"
) )
@ -69,18 +70,6 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
) )
} }
videoPipeline := config.VideoPipeline
if videoPipeline == "" {
videoPipeline = fmt.Sprintf(
"ximagesrc display-name=%s show-pointer=false use-damage=false " +
"! video/x-raw " +
"! videoconvert " +
"! queue " +
"! %s " +
"! appsink name=appsink", config.Display, config.VideoCodec.Pipeline,
)
}
return &CaptureManagerCtx{ return &CaptureManagerCtx{
logger: logger, logger: logger,
desktop: desktop, desktop: desktop,
@ -89,9 +78,40 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
screencast: screencastNew(config.Screencast, screencastPipeline), screencast: screencastNew(config.Screencast, screencastPipeline),
audio: streamNew(config.AudioCodec, audioPipeline), audio: streamNew(config.AudioCodec, audioPipeline),
videos: map[string]*StreamManagerCtx{ videos: map[string]*StreamManagerCtx{
"hq": streamNew(config.VideoCodec, videoPipeline), "hd": streamNew(codec.VP8(), fmt.Sprintf(
"ximagesrc display-name=%s show-pointer=false use-damage=false " +
"! video/x-raw " +
"! videoconvert " +
"! queue " +
"! vp8enc target-bitrate=8192000 cpu-used=16 threads=4 deadline=1 error-resilient=partitions keyframe-max-dist=15 static-threshold=20 " +
"! appsink name=appsink", config.Display,
)),
"hq": streamNew(codec.VP8(), fmt.Sprintf(
"ximagesrc display-name=%s show-pointer=false use-damage=false " +
"! video/x-raw " +
"! videoconvert " +
"! queue " +
"! vp8enc target-bitrate=4096000 cpu-used=16 threads=4 deadline=1 error-resilient=partitions keyframe-max-dist=15 static-threshold=20 " +
"! appsink name=appsink", config.Display,
)),
"mq": streamNew(codec.VP8(), fmt.Sprintf(
"ximagesrc display-name=%s show-pointer=false use-damage=false " +
"! video/x-raw " +
"! videoconvert " +
"! queue " +
"! vp8enc target-bitrate=2048000 cpu-used=16 threads=4 deadline=1 error-resilient=partitions keyframe-max-dist=15 static-threshold=20 " +
"! appsink name=appsink", config.Display,
)),
"lq": streamNew(codec.VP8(), fmt.Sprintf(
"ximagesrc display-name=%s show-pointer=false use-damage=false " +
"! video/x-raw " +
"! videoconvert " +
"! queue " +
"! vp8enc target-bitrate=1024000 cpu-used=16 threads=4 deadline=1 error-resilient=partitions keyframe-max-dist=15 static-threshold=20 " +
"! appsink name=appsink", config.Display,
)),
}, },
videoIDs: []string{ "hq" }, videoIDs: []string{ "hd", "hq", "mq", "lq" },
} }
} }

View File

@ -13,8 +13,8 @@ type Capture struct {
AudioPipeline string AudioPipeline string
Display string Display string
VideoCodec codec.RTPCodec //VideoCodec codec.RTPCodec
VideoPipeline string //VideoPipeline string
BroadcastPipeline string BroadcastPipeline string
@ -40,26 +40,26 @@ func (Capture) Init(cmd *cobra.Command) error {
return err return err
} }
cmd.PersistentFlags().String("video", "", "video codec parameters to use for streaming") //cmd.PersistentFlags().String("video", "", "video codec parameters to use for streaming")
if err := viper.BindPFlag("video", cmd.PersistentFlags().Lookup("video")); err != nil { //if err := viper.BindPFlag("video", cmd.PersistentFlags().Lookup("video")); err != nil {
return err // return err
} //}
// video codecs // video codecs
cmd.PersistentFlags().Bool("vp8", false, "use VP8 video codec") //cmd.PersistentFlags().Bool("vp8", false, "use VP8 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") //cmd.PersistentFlags().Bool("vp9", false, "use VP9 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") //cmd.PersistentFlags().Bool("h264", false, "use H264 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
} //}
// audio codecs // audio codecs
cmd.PersistentFlags().Bool("opus", false, "use Opus audio codec") cmd.PersistentFlags().Bool("opus", false, "use Opus audio codec")
@ -113,17 +113,17 @@ func (Capture) Init(cmd *cobra.Command) error {
} }
func (s *Capture) Set() { func (s *Capture) Set() {
var videoCodec codec.RTPCodec //var videoCodec codec.RTPCodec
if viper.GetBool("vp8") { //if viper.GetBool("vp8") {
videoCodec = codec.VP8() // videoCodec = codec.VP8()
} else if viper.GetBool("vp9") { //} else if viper.GetBool("vp9") {
videoCodec = codec.VP9() // videoCodec = codec.VP9()
} else if viper.GetBool("h264") { //} else if viper.GetBool("h264") {
videoCodec = codec.H264() // videoCodec = codec.H264()
} else { //} else {
// default // // default
videoCodec = codec.VP8() // videoCodec = codec.VP8()
} //}
var audioCodec codec.RTPCodec var audioCodec codec.RTPCodec
if viper.GetBool("opus") { if viper.GetBool("opus") {
@ -144,8 +144,8 @@ func (s *Capture) Set() {
s.AudioPipeline = viper.GetString("audio") s.AudioPipeline = viper.GetString("audio")
s.Display = viper.GetString("display") s.Display = viper.GetString("display")
s.VideoCodec = videoCodec //s.VideoCodec = videoCodec
s.VideoPipeline = viper.GetString("video") //s.VideoPipeline = viper.GetString("video")
s.BroadcastPipeline = viper.GetString("broadcast_pipeline") s.BroadcastPipeline = viper.GetString("broadcast_pipeline")