55 "fmt"
66 "os"
77 "path/filepath"
8+ "runtime"
89 "slices"
910 "strings"
1011 "testing"
@@ -158,15 +159,14 @@ func TestBuildFFmpegArgsUsesFullVAAPITranscodePipeline(t *testing.T) {
158159 if outputFormatIndex < 0 || args [outputFormatIndex + 1 ] != "vaapi" {
159160 t .Fatalf ("missing VAAPI hardware frame output: %v" , args )
160161 }
161- vfIndex := slices .Index (args , "-vf" )
162- if vfIndex < 0 || ! strings .Contains (args [vfIndex + 1 ], "scale_vaapi=" ) || ! strings .Contains (args [vfIndex + 1 ], "format=nv12" ) {
163- t .Fatalf ("expected VAAPI scale filter, args=%v" , args )
164- }
165162 codecIndex := slices .Index (args , "-c:v" )
166163 if codecIndex < 0 || args [codecIndex + 1 ] != "h264_vaapi" {
167164 t .Fatalf ("expected VAAPI H.264 encoder, args=%v" , args )
168165 }
169- for _ , softwareOnly := range []string {"libx264" , "-preset" , "-tune" } {
166+ if slices .Contains (args , "-vf" ) {
167+ t .Fatalf ("full VAAPI pipeline should not scale, args=%v" , args )
168+ }
169+ for _ , softwareOnly := range []string {"libx264" , "-preset" , "-tune" , "-level" } {
170170 if slices .Contains (args , softwareOnly ) {
171171 t .Fatalf ("VAAPI pipeline should not include software encoder arg %q: %v" , softwareOnly , args )
172172 }
@@ -278,7 +278,7 @@ func TestResolveHardwareDecodeKeepsVAAPIWhenProbePasses(t *testing.T) {
278278 return nil
279279 })
280280
281- if options .HardwareDecode != "vaapi" || options .HardwareDevice != "/dev/dri/renderD128" {
281+ if options .HardwareDecode != "vaapi" || options .HardwareDevice != "/dev/dri/renderD128" || options . HardwarePipeline != "vaapi-full" {
282282 t .Fatalf ("options = %+v" , options )
283283 }
284284}
@@ -316,69 +316,10 @@ func TestResolveHardwareDecodeFalseSkipsHardwareProbe(t *testing.T) {
316316 }
317317}
318318
319- func TestResolveHardwareDecodeFallsBackToVAAPIEncodeWhenFullPipelineUnsupported (t * testing.T ) {
320- tempDir := t .TempDir ()
321- ffmpegPath := filepath .Join (tempDir , "ffmpeg" )
322- callsPath := filepath .Join (tempDir , "calls" )
323- script := fmt .Sprintf (`#!/bin/sh
324- echo "$@" >> %q
325- case " $* " in
326- *" -hwaccels "*)
327- printf 'Hardware acceleration methods:\nvaapi\n'
328- exit 0
329- ;;
330- *" -encoders "*)
331- printf ' V....D h264_vaapi H.264/AVC (VAAPI)\n'
332- exit 0
333- ;;
334- *" -filters "*)
335- printf ' ... scale_vaapi V->V Scale to/from VAAPI surfaces.\n'
336- exit 0
337- ;;
338- *" -init_hw_device "*"scale_vaapi="*)
339- echo 'Failed to create processing pipeline config: 12 (the requested VAProfile is not supported).' >&2
340- exit 1
341- ;;
342- *" -vaapi_device "*"hwupload"*)
343- exit 0
344- ;;
345- *" -init_hw_device "*)
346- exit 0
347- ;;
348- esac
349- exit 0
350- ` , callsPath )
351- if err := os .WriteFile (ffmpegPath , []byte (script ), 0o755 ); err != nil {
352- t .Fatal (err )
353- }
354- devicePath := filepath .Join (tempDir , "renderD128" )
355- if err := os .WriteFile (devicePath , nil , 0o600 ); err != nil {
356- t .Fatal (err )
357- }
358-
359- options , err := resolveHardwareDecodeOptionsStrict (ffmpegPath , FFmpegOptions {
360- HardwareDecode : "vaapi" ,
361- HardwareDevice : devicePath ,
362- }, nil )
363- if err != nil {
364- t .Fatal (err )
365- }
366-
367- if options .HardwarePipeline != "vaapi-encode" {
368- t .Fatalf ("hardware pipeline = %q" , options .HardwarePipeline )
369- }
370- calls , err := os .ReadFile (callsPath )
371- if err != nil {
372- t .Fatal (err )
373- }
374- for _ , want := range []string {"scale_vaapi=" , "-vaapi_device " + devicePath , "hwupload" , "-c:v h264_vaapi" } {
375- if ! strings .Contains (string (calls ), want ) {
376- t .Fatalf ("expected probe call containing %q, calls=%s" , want , calls )
377- }
378- }
379- }
380-
381319func TestDefaultHardwareProbeRejectsVAAPIWhenDeviceInitializationFails (t * testing.T ) {
320+ if runtime .GOOS == "windows" {
321+ t .Skip ("linux-only ffmpeg probe test" )
322+ }
382323 tempDir := t .TempDir ()
383324 ffmpegPath := filepath .Join (tempDir , "ffmpeg" )
384325 callsPath := filepath .Join (tempDir , "calls" )
@@ -393,10 +334,6 @@ case " $* " in
393334 printf ' V....D h264_vaapi H.264/AVC (VAAPI)\n'
394335 exit 0
395336 ;;
396- *" -filters "*)
397- printf ' ... scale_vaapi V->V Scale to/from VAAPI surfaces.\n'
398- exit 0
399- ;;
400337 *" -init_hw_device "*)
401338 echo 'Failed to initialise VAAPI connection' >&2
402339 exit 1
@@ -432,7 +369,10 @@ exit 0
432369 }
433370}
434371
435- func TestDefaultHardwareProbeRequiresFullVAAPIPipeline (t * testing.T ) {
372+ func TestDefaultHardwareProbeUsesVAAPIBaseOnly (t * testing.T ) {
373+ if runtime .GOOS == "windows" {
374+ t .Skip ("linux-only ffmpeg probe test" )
375+ }
436376 tempDir := t .TempDir ()
437377 ffmpegPath := filepath .Join (tempDir , "ffmpeg" )
438378 callsPath := filepath .Join (tempDir , "calls" )
@@ -447,10 +387,6 @@ case " $* " in
447387 printf ' V....D h264_vaapi H.264/AVC (VAAPI)\n'
448388 exit 0
449389 ;;
450- *" -filters "*)
451- printf ' ... scale_vaapi V->V Scale to/from VAAPI surfaces.\n'
452- exit 0
453- ;;
454390 *" -init_hw_device "*)
455391 exit 0
456392 ;;
@@ -476,7 +412,7 @@ exit 0
476412 if err != nil {
477413 t .Fatal (err )
478414 }
479- for _ , want := range []string {"-hwaccels" , "-encoders" , "-filters" , "- init_hw_device vaapi=probe:" + devicePath , "-filter_hw_device probe" , "scale_vaapi=" , "-c:v h264_vaapi" } {
415+ for _ , want := range []string {"-hwaccels" , "-encoders" , "-init_hw_device vaapi=probe:" + devicePath } {
480416 if ! strings .Contains (string (calls ), want ) {
481417 t .Fatalf ("expected hardware probe call containing %q, calls=%s" , want , calls )
482418 }
0 commit comments