From a2a8fda91e6c3e5fa39e2f2c9ca6f4f030b04da5 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 3 Apr 2023 18:55:26 -0700 Subject: [PATCH] Use copy for H264 --- stream.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/stream.go b/stream.go index b568474d..a8339016 100644 --- a/stream.go +++ b/stream.go @@ -16,12 +16,13 @@ import ( ) const ( - ENCODER_X264 = "libx264" + ENCODER_COPY = "copy" + ENCODER_X264 = "libx264" ENCODER_VAAPI = "h264_vaapi" ENCODER_NVENC = "h264_nvenc" QUALITY_MAX = "max" - CODEC_H264 = "h264" + CODEC_H264 = "h264" ) type Stream struct { @@ -363,15 +364,20 @@ func (s *Stream) transcodeArgs(startAt float64) []string { // encoder selection CV := ENCODER_X264 - // Check whether hwaccel should be used - if s.c.VAAPI { - CV = ENCODER_VAAPI - extra := "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi" - args = append(args, strings.Split(extra, " ")...) - } else if s.c.NVENC { - CV = ENCODER_NVENC - extra := "-hwaccel cuda" - args = append(args, strings.Split(extra, " ")...) + if s.m.probe.CodecName == CODEC_H264 && s.quality == QUALITY_MAX { + // Use original stream + CV = ENCODER_COPY + } else { + // Check whether hwaccel should be used + if s.c.VAAPI { + CV = ENCODER_VAAPI + extra := "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi" + args = append(args, strings.Split(extra, " ")...) + } else if s.c.NVENC { + CV = ENCODER_NVENC + extra := "-hwaccel cuda" + args = append(args, strings.Split(extra, " ")...) + } } // Input specs @@ -404,8 +410,11 @@ func (s *Stream) transcodeArgs(startAt float64) []string { } // Apply filter - filter := fmt.Sprintf("%s,%s=%s", format, scaler, strings.Join(scalerArgs, ":")) - args = append(args, []string{"-vf", filter}...) + if CV != ENCODER_COPY { + filter := fmt.Sprintf("%s,%s=%s", format, scaler, strings.Join(scalerArgs, ":")) + args = append(args, []string{"-vf", filter}...) + args = append(args, []string{"-profile:v", "main"}...) + } // Apply bitrate cap if not max quality if s.quality != QUALITY_MAX { @@ -419,7 +428,6 @@ func (s *Stream) transcodeArgs(startAt float64) []string { args = append(args, []string{ "-map", "0:v:0", "-c:v", CV, - "-profile:v", "main", }...) // Device specific output args