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 ( const (
ENCODER_X264 = "libx264" ENCODER_COPY = "copy"
ENCODER_X264 = "libx264"
ENCODER_VAAPI = "h264_vaapi" ENCODER_VAAPI = "h264_vaapi"
ENCODER_NVENC = "h264_nvenc" ENCODER_NVENC = "h264_nvenc"
QUALITY_MAX = "max" QUALITY_MAX = "max"
CODEC_H264 = "h264" CODEC_H264 = "h264"
) )
type Stream struct { type Stream struct {
@ -363,15 +364,20 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
// encoder selection // encoder selection
CV := ENCODER_X264 CV := ENCODER_X264
// Check whether hwaccel should be used if s.m.probe.CodecName == CODEC_H264 && s.quality == QUALITY_MAX {
if s.c.VAAPI { // Use original stream
CV = ENCODER_VAAPI CV = ENCODER_COPY
extra := "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi" } else {
args = append(args, strings.Split(extra, " ")...) // Check whether hwaccel should be used
} else if s.c.NVENC { if s.c.VAAPI {
CV = ENCODER_NVENC CV = ENCODER_VAAPI
extra := "-hwaccel cuda" extra := "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi"
args = append(args, strings.Split(extra, " ")...) 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 // Input specs
@ -404,8 +410,11 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
} }
// Apply filter // Apply filter
filter := fmt.Sprintf("%s,%s=%s", format, scaler, strings.Join(scalerArgs, ":")) if CV != ENCODER_COPY {
args = append(args, []string{"-vf", filter}...) 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 // Apply bitrate cap if not max quality
if s.quality != QUALITY_MAX { if s.quality != QUALITY_MAX {
@ -419,7 +428,6 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
args = append(args, []string{ args = append(args, []string{
"-map", "0:v:0", "-map", "0:v:0",
"-c:v", CV, "-c:v", CV,
"-profile:v", "main",
}...) }...)
// Device specific output args // Device specific output args