feat: enable Intel Quicksync with support for FFmpeg 4.x to 7.1 (#4028)
* feat: enable Intel Quicksync with support for FFmpeg 4.x to 7.1 * fix(go): fix linter warning --------- Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
parent
bb4a7479b5
commit
8ce270b02f
@ -27,6 +27,7 @@ var supportedCodecs = map[string]string{
|
||||
(&Libx264Codec{}).Name(): "libx264",
|
||||
(&OmxCodec{}).Name(): "omx",
|
||||
(&VaapiCodec{}).Name(): "vaapi",
|
||||
(&QuicksyncCodec{}).Name(): "qsv",
|
||||
(&NvencCodec{}).Name(): "NVIDIA nvenc",
|
||||
(&VideoToolboxCodec{}).Name(): "videotoolbox",
|
||||
}
|
||||
@ -317,17 +318,22 @@ func (c *QuicksyncCodec) DisplayName() string {
|
||||
|
||||
// GlobalFlags are the global flags used with this codec in the transcoder.
|
||||
func (c *QuicksyncCodec) GlobalFlags() string {
|
||||
return ""
|
||||
flags := []string{
|
||||
"-init_hw_device", "qsv=hw",
|
||||
"-filter_hw_device", "hw",
|
||||
}
|
||||
|
||||
return strings.Join(flags, " ")
|
||||
}
|
||||
|
||||
// PixelFormat is the pixel format required for this codec.
|
||||
func (c *QuicksyncCodec) PixelFormat() string {
|
||||
return "nv12"
|
||||
return "qsv"
|
||||
}
|
||||
|
||||
// Scaler is the scaler used for resizing the video in the transcoder.
|
||||
func (c *QuicksyncCodec) Scaler() string {
|
||||
return ""
|
||||
return "scale_qsv"
|
||||
}
|
||||
|
||||
// ExtraArguments are the extra arguments used with this codec in the transcoder.
|
||||
@ -337,7 +343,7 @@ func (c *QuicksyncCodec) ExtraArguments() string {
|
||||
|
||||
// ExtraFilters are the extra filters required for this codec in the transcoder.
|
||||
func (c *QuicksyncCodec) ExtraFilters() string {
|
||||
return ""
|
||||
return "hwupload=extra_hw_frames=64,format=qsv"
|
||||
}
|
||||
|
||||
// VariantFlags returns a string representing a single variant processed by this codec.
|
||||
@ -348,16 +354,16 @@ func (c *QuicksyncCodec) VariantFlags(v *HLSVariant) string {
|
||||
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
||||
func (c *QuicksyncCodec) GetPresetForLevel(l int) string {
|
||||
presetMapping := map[int]string{
|
||||
0: "ultrafast",
|
||||
1: "superfast",
|
||||
2: "veryfast",
|
||||
3: "faster",
|
||||
4: "fast",
|
||||
0: "veryfast",
|
||||
1: "fast",
|
||||
2: "medium",
|
||||
3: "slow",
|
||||
4: "veryslow",
|
||||
}
|
||||
|
||||
preset, ok := presetMapping[l]
|
||||
if !ok {
|
||||
defaultPreset := presetMapping[1]
|
||||
defaultPreset := presetMapping[2]
|
||||
log.Errorf("Invalid level for quicksync preset %d, defaulting to %s", l, defaultPreset)
|
||||
return defaultPreset
|
||||
}
|
||||
|
50
core/transcoder/transcoder_qsv_test.go
Normal file
50
core/transcoder/transcoder_qsv_test.go
Normal file
@ -0,0 +1,50 @@
|
||||
package transcoder
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/owncast/owncast/models"
|
||||
)
|
||||
|
||||
func TestFFmpegQuicksyncCommand(t *testing.T) {
|
||||
latencyLevel := models.GetLatencyLevel(2)
|
||||
codec := QuicksyncCodec{}
|
||||
|
||||
transcoder := new(Transcoder)
|
||||
transcoder.ffmpegPath = filepath.Join("fake", "path", "ffmpeg")
|
||||
transcoder.SetInput("fakecontent.flv")
|
||||
transcoder.SetOutputPath("fakeOutput")
|
||||
transcoder.SetIdentifier("jdofFGg")
|
||||
transcoder.SetInternalHTTPPort("8123")
|
||||
transcoder.SetCodec(codec.Name())
|
||||
transcoder.currentLatencyLevel = latencyLevel
|
||||
|
||||
variant := HLSVariant{}
|
||||
variant.videoBitrate = 1200
|
||||
variant.isAudioPassthrough = true
|
||||
variant.SetVideoFramerate(30)
|
||||
variant.SetCPUUsageLevel(2)
|
||||
transcoder.AddVariant(variant)
|
||||
|
||||
variant2 := HLSVariant{}
|
||||
variant2.videoBitrate = 3500
|
||||
variant2.isAudioPassthrough = true
|
||||
variant2.SetVideoFramerate(24)
|
||||
variant2.SetCPUUsageLevel(4)
|
||||
transcoder.AddVariant(variant2)
|
||||
|
||||
variant3 := HLSVariant{}
|
||||
variant3.isAudioPassthrough = true
|
||||
variant3.isVideoPassthrough = true
|
||||
transcoder.AddVariant(variant3)
|
||||
|
||||
cmd := transcoder.getString()
|
||||
|
||||
expectedLogPath := filepath.Join("data", "logs", "transcoder.log")
|
||||
expected := `FFREPORT=file="` + expectedLogPath + `":level=32 ` + transcoder.ffmpegPath + ` -hide_banner -loglevel warning -init_hw_device qsv=hw -filter_hw_device hw -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_qsv -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -map a:0? -c:a:0 copy -filter:v:0 "hwupload=extra_hw_frames=64,format=qsv" -preset medium -map v:0 -c:v:1 h264_qsv -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -filter:v:1 "hwupload=extra_hw_frames=64,format=qsv" -preset veryslow -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset veryfast -var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2 " -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt qsv -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg-%d.ts -max_muxing_queue_size 400 -method PUT -http_persistent 1 http://127.0.0.1:8123/%v/stream.m3u8`
|
||||
|
||||
if cmd != expected {
|
||||
t.Errorf("ffmpeg command does not match expected.\nGot %s\n, want: %s", cmd, expected)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user