Use copy for H264

monorepo
Varun Patil 2023-04-03 18:55:26 -07:00
parent b1aba2284f
commit a2a8fda91e
1 changed files with 22 additions and 14 deletions

View File

@ -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