Add H265 support

Adds H265 as a selectable video codec with software (x265enc), VAAPI
(vah265enc), and NVENC (nvh265enc) pipeline paths in both the legacy
pipeline builder and the RTPCodec definition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub Budisky
2026-05-13 21:59:35 +02:00
committed by Miroslav Šedivý
parent c804b1ac24
commit 6071945485
3 changed files with 56 additions and 3 deletions
@@ -187,6 +187,39 @@ func NewVideoPipeline(rtpCodec codec.RTPCodec, display string, pipelineSrc strin
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)
}
case codec.H265().Name:
if err := gst.CheckPlugins([]string{"ximagesrc"}); err != nil {
return "", err
}
vbvbuf := uint(1000)
if bitrate > 1000 {
vbvbuf = bitrate
}
switch hwenc {
case HwEncVAAPI:
if err := gst.CheckPlugins([]string{"va"}); err != nil {
return "", err
}
pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! vah265enc rate-control=cbr bitrate=%d key-int-max=60 target-usage=7 ! video/x-h265,stream-format=byte-stream,profile=main"+pipelineStr, display, fps, bitrate)
case HwEncNVENC:
if err := gst.CheckPlugins([]string{"nvcodec"}); err != nil {
return "", err
}
pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! nvh265enc name=encoder rc-mode=cbr preset=p2 tune=low-latency gop-size=25 bitrate=%d vbv-buffer-size=%d ! h265parse config-interval=-1 ! video/x-h265,stream-format=byte-stream,profile=main"+pipelineStr, display, fps, bitrate, vbvbuf)
default:
// https://gstreamer.freedesktop.org/documentation/x265/index.html?gi-language=c
// gstreamer1.0-plugins-bad
if err := gst.CheckPlugins([]string{"x265"}); err != nil {
return "", err
}
pipelineStr = fmt.Sprintf(videoSrc+"x265enc bitrate=%d key-int-max=60 tune=zerolatency speed-preset=veryfast option-string=\"vbv-maxrate=%d:vbv-bufsize=%d\" ! video/x-h265,stream-format=byte-stream,profile=main"+pipelineStr, display, fps, bitrate, bitrate, vbvbuf)
}
default:
return "", fmt.Errorf("unknown codec %s", rtpCodec.Name)
}
+20
View File
@@ -35,6 +35,8 @@ func ParseStr(codecName string) (codec RTPCodec, ok bool) {
codec = AV1()
case H264().Name:
codec = H264()
case H265().Name:
codec = H265()
case Opus().Name:
codec = Opus()
case G722().Name:
@@ -136,6 +138,24 @@ func H264() RTPCodec {
}
}
func H265() RTPCodec {
return RTPCodec{
Name: "h265",
PayloadType: 116,
Type: webrtc.RTPCodecTypeVideo,
Capability: webrtc.RTPCodecCapability{
MimeType: webrtc.MimeTypeH265,
ClockRate: 90000,
Channels: 0,
SDPFmtpLine: "profile-id=1;level-id=93;tx-mode=SRST",
RTCPFeedback: RTCPFeedback,
},
// https://gstreamer.freedesktop.org/documentation/x265/index.html
// gstreamer1.0-plugins-bad
Pipeline: "x265enc bitrate=4096 key-int-max=60 tune=zerolatency speed-preset=veryfast option-string=\"vbv-maxrate=4096:vbv-bufsize=4096\" ! video/x-h265,stream-format=byte-stream,profile=main",
}
}
// TODO: Profile ID.
func AV1() RTPCodec {
return RTPCodec{