bitrate as integer

This commit is contained in:
Marcel Battista 2021-02-14 19:13:52 +00:00
parent 4795d3ac96
commit 405ef7b9dd
3 changed files with 10 additions and 9 deletions

View File

@ -9,6 +9,7 @@ package gst
import "C"
import (
"fmt"
"strconv"
"sync"
"time"
"unsafe"
@ -79,7 +80,7 @@ func CreateRTMPPipeline(pipelineDevice string, pipelineDisplay string, pipelineS
}
// CreateAppPipeline creates a GStreamer Pipeline
func CreateAppPipeline(codecName string, pipelineDevice string, pipelineSrc string, bitrate string) (*Pipeline, error) {
func CreateAppPipeline(codecName string, pipelineDevice string, pipelineSrc string, bitrate int) (*Pipeline, error) {
pipelineStr := " ! appsink name=appsink"
var clockRate float32
@ -131,8 +132,8 @@ func CreateAppPipeline(codecName string, pipelineDevice string, pipelineSrc stri
} else {
var h264Str string
h264Str = "openh264enc multi-thread=4 complexity=high bitrate=3072000 max-bitrate=4096000 ! video/x-h264,stream-format=byte-stream"
if bitrate != "" {
h264Str = "openh264enc multi-thread=4 complexity=high bitrate=" + bitrate + "000 max-bitrate=" + bitrate + "999 ! video/x-h264,stream-format=byte-stream"
if bitrate > 0 {
h264Str = "openh264enc multi-thread=4 complexity=high bitrate=" + strconv.Itoa(bitrate) + "000 max-bitrate=" + strconv.Itoa(bitrate) + "999 ! video/x-h264,stream-format=byte-stream"
}
// https://gstreamer.freedesktop.org/documentation/x264/index.html?gi-language=c
@ -141,8 +142,8 @@ func CreateAppPipeline(codecName string, pipelineDevice string, pipelineSrc stri
if err := CheckPlugins([]string{"openh264"}); err != nil {
h264Str = "video/x-raw,format=I420 ! x264enc threads=4 byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream"
if bitrate != "" {
h264Str = "video/x-raw,format=I420 ! x264enc threads=4 bitrate=" + bitrate + " byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream"
if bitrate > 0 {
h264Str = "video/x-raw,format=I420 ! x264enc threads=4 bitrate=" + strconv.Itoa(bitrate) + " byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream"
}
if err := CheckPlugins([]string{"x264"}); err != nil {

View File

@ -145,7 +145,7 @@ func (manager *RemoteManager) createPipelines() {
manager.config.AudioCodec,
manager.config.Device,
manager.config.AudioParams,
"",
0,
)
if err != nil {
manager.logger.Panic().Err(err).Msg("unable to create audio pipeline")

View File

@ -18,7 +18,7 @@ type Remote struct {
ScreenWidth int
ScreenHeight int
ScreenRate int
Bitrate string
Bitrate int
}
func (Remote) Init(cmd *cobra.Command) error {
@ -47,7 +47,7 @@ func (Remote) Init(cmd *cobra.Command) error {
return err
}
cmd.PersistentFlags().String("bitrate", "", "set this video bitrate when possible")
cmd.PersistentFlags().Int("bitrate", 0, "set this video bitrate when possible")
if err := viper.BindPFlag("bitrate", cmd.PersistentFlags().Lookup("bitrate")); err != nil {
return err
}
@ -120,7 +120,7 @@ func (s *Remote) Set() {
s.Display = viper.GetString("display")
s.VideoCodec = videoCodec
s.VideoParams = viper.GetString("video")
s.Bitrate = viper.GetString("bitrate")
s.Bitrate = viper.GetInt("bitrate")
s.ScreenWidth = 1280
s.ScreenHeight = 720