From f0e25cb1e9adbf10cd8af7d7e9a37d6b55bb0d74 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 7 Feb 2024 17:25:57 +0100 Subject: [PATCH] Video: Add filter to Intel QSV FFmpeg transcoding flags #4030 #4052 Signed-off-by: Michael Mayer --- internal/ffmpeg/config.go | 2 ++ internal/ffmpeg/convert.go | 3 ++- internal/ffmpeg/convert_test.go | 2 +- internal/ffmpeg/format.go | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/ffmpeg/config.go b/internal/ffmpeg/config.go index cc828e1f5..a1f5c4c27 100644 --- a/internal/ffmpeg/config.go +++ b/internal/ffmpeg/config.go @@ -17,6 +17,8 @@ func (o Options) VideoFilter(format PixelFormat) string { // scale specifies the FFmpeg downscale filter, see http://trac.ffmpeg.org/wiki/Scaling. if format == "" { return fmt.Sprintf("scale='if(gte(iw,ih), min(%d, iw), -2):if(gte(iw,ih), -2, min(%d, ih))'", o.Size, o.Size) + } else if format == FormatQSV { + return fmt.Sprintf("vpp_qsv=framerate=30,scale_qsv=w='if(gte(iw,ih), min(%d, iw), -1)':h='if(gte(iw,ih), -1, min(%d, ih))'", o.Size, o.Size) } else { return fmt.Sprintf("scale='if(gte(iw,ih), min(%d, iw), -2):if(gte(iw,ih), -2, min(%d, ih))',format=%s", o.Size, o.Size, format) } diff --git a/internal/ffmpeg/convert.go b/internal/ffmpeg/convert.go index 96f2feb4a..bee9c1f15 100644 --- a/internal/ffmpeg/convert.go +++ b/internal/ffmpeg/convert.go @@ -53,10 +53,11 @@ func AvcConvertCommand(fileName, avcName string, opt Options) (result *exec.Cmd, result = exec.Command( ffmpeg, "-hwaccel", "qsv", + "-hwaccel_output_format", "qsv", "-qsv_device", "/dev/dri/renderD128", "-i", fileName, "-c:a", "aac", - // "-vf", opt.VideoFilter(FormatRGB32), // TODO: Add filter for downscaling of videos with Intel QSV. + "-vf", opt.VideoFilter(FormatQSV), "-c:v", opt.Encoder.String(), "-map", opt.MapVideo, "-map", opt.MapAudio, diff --git a/internal/ffmpeg/convert_test.go b/internal/ffmpeg/convert_test.go index 111623531..e47ba385a 100644 --- a/internal/ffmpeg/convert_test.go +++ b/internal/ffmpeg/convert_test.go @@ -79,7 +79,7 @@ func TestAvcConvertCommand(t *testing.T) { if err != nil { t.Fatal(err) } - assert.Equal(t, "/usr/bin/ffmpeg -hwaccel qsv -qsv_device /dev/dri/renderD128 -i VID123.mov -c:a aac -c:v h264_qsv -map 0:v:0 -map 0:a:0? -r 30 -b:v 50 -bitrate 50 -f mp4 -movflags +faststart -y VID123.mov.avc", r.String()) + assert.Equal(t, "/usr/bin/ffmpeg -hwaccel qsv -hwaccel_output_format qsv -qsv_device /dev/dri/renderD128 -i VID123.mov -c:a aac -vf vpp_qsv=framerate=30,scale_qsv=w='if(gte(iw,ih), min(1500, iw), -1)':h='if(gte(iw,ih), -1, min(1500, ih))' -c:v h264_qsv -map 0:v:0 -map 0:a:0? -r 30 -b:v 50 -bitrate 50 -f mp4 -movflags +faststart -y VID123.mov.avc", r.String()) }) t.Run("h264_videotoolbox", func(t *testing.T) { Options := Options{ diff --git a/internal/ffmpeg/format.go b/internal/ffmpeg/format.go index 420d1e7ba..29fc22e81 100644 --- a/internal/ffmpeg/format.go +++ b/internal/ffmpeg/format.go @@ -11,6 +11,6 @@ func (f PixelFormat) String() string { // Standard pixel formats. const ( FormatYUV420P PixelFormat = "yuv420p" - FormatRGB32 PixelFormat = "rgb32" FormatNV12 PixelFormat = "nv12,hwupload" + FormatQSV PixelFormat = "qsv" )