From 3c17dbe282f97b1ab277099e403f044d9a6910f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 31 Mar 2023 21:43:20 +0200 Subject: [PATCH] h264 encoding profile constrained-baseline, #109. --- docs/getting-started/configuration.md | 2 +- docs/getting-started/examples.md | 4 ++-- server/internal/capture/pipelines.go | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md index d2e9c5c..d61b87a 100644 --- a/docs/getting-started/configuration.md +++ b/docs/getting-started/configuration.md @@ -79,7 +79,7 @@ nat1to1: - `gstreamer1.0-plugins-good` - `gstreamer1.0-plugins-bad` - `gstreamer1.0-plugins-ugly` - - e.g. `ximagesrc display-name=%s show-pointer=true use-damage=false ! video/x-raw,framerate=30/1 ! videoconvert ! queue ! video/x-raw,format=NV12 ! x264enc threads=4 bitrate=3500 key-int-max=60 vbv-buf-capacity=4000 byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream` + - e.g. `ximagesrc display-name=%s show-pointer=true use-damage=false ! video/x-raw,framerate=30/1 ! videoconvert ! queue ! video/x-raw,format=NV12 ! x264enc threads=4 bitrate=3500 key-int-max=60 vbv-buf-capacity=4000 byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline` #### `NEKO_MAX_FPS`: - The resulting stream frames per seconds should be capped *(0 for uncapped)*. - e.g. `0` diff --git a/docs/getting-started/examples.md b/docs/getting-started/examples.md index f6bd775..d965f78 100644 --- a/docs/getting-started/examples.md +++ b/docs/getting-started/examples.md @@ -95,9 +95,9 @@ services: ! videoconvert ! queue ! video/x-raw,framerate=30/1,format=NV12 - ! v4l2h264enc extra-controls="controls,h264_profile=0,video_bitrate=1250000;" + ! v4l2h264enc extra-controls="controls,h264_profile=1,video_bitrate=1250000;" ! h264parse config-interval=3 - ! video/x-h264,profile=baseline,stream-format=byte-stream + ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline NEKO_VIDEO_CODEC: h264 ``` diff --git a/server/internal/capture/pipelines.go b/server/internal/capture/pipelines.go index 69cc376..4253fc4 100644 --- a/server/internal/capture/pipelines.go +++ b/server/internal/capture/pipelines.go @@ -143,20 +143,20 @@ func NewVideoPipeline(rtpCodec codec.RTPCodec, display string, pipelineSrc strin return "", err } - pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! vaapih264enc rate-control=vbr bitrate=%d keyframe-period=180 quality-level=7 ! video/x-h264,stream-format=byte-stream"+pipelineStr, display, fps, bitrate) + pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! vaapih264enc rate-control=vbr bitrate=%d keyframe-period=180 quality-level=7 ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"+pipelineStr, display, fps, bitrate) } else { // https://gstreamer.freedesktop.org/documentation/openh264/openh264enc.html?gi-language=c#openh264enc // gstreamer1.0-plugins-bad // openh264enc multi-thread=4 complexity=high bitrate=3072000 max-bitrate=4096000 if err := gst.CheckPlugins([]string{"openh264"}); err == nil { - pipelineStr = fmt.Sprintf(videoSrc+"openh264enc multi-thread=4 complexity=high bitrate=%d max-bitrate=%d ! video/x-h264,stream-format=byte-stream"+pipelineStr, display, fps, bitrate*1000, (bitrate+1024)*1000) + pipelineStr = fmt.Sprintf(videoSrc+"openh264enc multi-thread=4 complexity=high bitrate=%d max-bitrate=%d ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"+pipelineStr, display, fps, bitrate*1000, (bitrate+1024)*1000) break } // https://gstreamer.freedesktop.org/documentation/x264/index.html?gi-language=c // gstreamer1.0-plugins-ugly - // video/x-raw,format=I420 ! x264enc bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream + // video/x-raw,format=I420 ! x264enc bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline if err := gst.CheckPlugins([]string{"x264"}); err != nil { return "", err } @@ -166,7 +166,7 @@ func NewVideoPipeline(rtpCodec codec.RTPCodec, display string, pipelineSrc strin vbvbuf = bitrate } - pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! x264enc threads=4 bitrate=%d key-int-max=60 vbv-buf-capacity=%d byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream"+pipelineStr, display, fps, bitrate, vbvbuf) + pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! x264enc threads=4 bitrate=%d key-int-max=60 vbv-buf-capacity=%d byte-stream=true tune=zerolatency speed-preset=veryfast ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"+pipelineStr, display, fps, bitrate, vbvbuf) } default: return "", fmt.Errorf("unknown codec %s", rtpCodec.Name)