Videos: Tweak FFmpeg arguments for Intel QSV Encoder #1337

This commit is contained in:
Michael Mayer 2021-09-29 13:52:29 +02:00
parent fce13182e6
commit 13d1abfb0d
2 changed files with 45 additions and 21 deletions

View file

@ -24,5 +24,5 @@ tensorflow-amd64-avx2-install:
ldconfig
intel-graphics:
apt-get update
apt-get install intel-opencl-icd intel-media-va-driver-non-free libmfx1
apt-get install intel-opencl-icd intel-media-va-driver-non-free libva i965-va-driver i965-va-driver-shaders libmfx libmfx1
apt-get -y autoremove && apt-get -y autoclean && apt-get clean && rm -rf /var/lib/apt/lists/*

View file

@ -26,6 +26,7 @@ import (
)
const DefaultAvcEncoder = "libx264" // Default FFmpeg AVC software encoder.
const IntelQsvEncoder = "h264_qsv"
// Convert represents a converter that can convert RAW/HEIF images to JPEG.
type Convert struct {
@ -361,7 +362,29 @@ func (c *Convert) AvcConvertCommand(f *MediaFile, avcName, codecName string) (re
// Don't transcode more than one video at the same time.
useMutex = true
if codecName == IntelQsvEncoder {
format := "format=rgb32"
result = exec.Command(
c.conf.FFmpegBin(),
"-qsv_device", "/dev/dri/renderD128",
"-init_hw_device", "qsv=hw",
"-filter_hw_device", "hw",
"-i", f.FileName(),
"-c:a", "aac",
"-vf", format,
"-c:v", codecName,
"-vsync", "vfr",
"-r", "30",
"-b:v", c.AvcBitrate(f),
"-maxrate", c.AvcBitrate(f),
"-f", "mp4",
"-y",
avcName,
)
} else {
format := "format=yuv420p"
result = exec.Command(
c.conf.FFmpegBin(),
"-i", f.FileName(),
@ -379,6 +402,7 @@ func (c *Convert) AvcConvertCommand(f *MediaFile, avcName, codecName string) (re
"-y",
avcName,
)
}
} else {
return nil, useMutex, fmt.Errorf("convert: file type %s not supported in %s", f.FileType(), txt.Quote(f.BaseName()))
}
@ -461,9 +485,9 @@ func (c *Convert) ToAvc(f *MediaFile, encoderName string) (file *MediaFile, err
err = errors.New(stderr.String())
}
// Log original ffmpeg error (unless empty).
// Log ffmpeg output for debugging.
if err.Error() != "" {
log.Error(err)
log.Debug(err)
}
// Log filename and transcoding time.