[FFmpeg-user] Generic way to deal with different pixel formats in a HW context

Jonathan Baecker jonbae77 at gmail.com
Wed Jan 29 23:49:31 EET 2025


Hi,

I want to run this command:

ffmpeg -hwaccel_device 0 -hwaccel cuda -hwaccel_output_format cuda -i 
input.mp4 -vf scale_cuda=-1:-1 -c:v h264_nvenc -f null -

If my input file has a pixel format of yuv420p then the command works 
fine, but if the file has gbrp the conversion fails:

ffmpeg version git-2024-11-08-3330b733d3 Copyright (c) 2000-2024 the 
FFmpeg developers
   built with gcc 14 (GCC)
   configuration: --disable-debug --disable-shared --disable-doc 
--enable-gpl --enable-version3 --enable-runtime-cpudetect 
--enable-avfilter --enable-zlib --enable-libklvanc --enable-fontconfig 
--enable-libass --enable-libfdk-aac --enable-libfribidi 
--enable-libfreetype --enable-libharfbuzz --enable-libmp3lame 
--enable-libopus --enable-libsoxr --enable-libsrt --enable-librist 
--enable-libtwolame --enable-libvpx --enable-libx264 --enable-libx265 
--enable-libzimg --enable-libzmq --enable-nonfree --enable-opengl 
--enable-openssl --enable-libsvtav1 --enable-librav1e --enable-libdav1d 
--enable-cuvid --enable-nvenc --enable-nvdec --enable-libpulse 
--enable-vulkan --enable-libplacebo --enable-libshaderc --enable-libvpl 
--enable-pic
   libavutil      59. 46.100 / 59. 46.100
   libavcodec     61. 24.100 / 61. 24.100
   libavformat    61.  9.100 / 61.  9.100
   libavdevice    61.  4.100 / 61.  4.100
   libavfilter    10.  6.101 / 10.  6.101
   libswscale      8.  9.101 /  8.  9.101
   libswresample   5.  4.100 /  5.  4.100
   libpostproc    58.  4.100 / 58.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 
'tests/assets/media_mix/short_audio.mp4':
   Metadata:
     major_brand     : isom
     minor_version   : 512
     compatible_brands: isomiso2mp41
     encoder         : Lavf59.31.100
   Duration: 00:00:10.00, start: 0.000000, bitrate: 2623 kb/s
   Stream #0:0[0x1](und): Video: hevc (Rext) (hev1 / 0x31766568), 
gbrp(pc, gbr/unknown/unknown, progressive), 1280x720 [SAR 1:1 DAR 16:9], 
2499 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
     Metadata:
       handler_name    : VideoHandler
       vendor_id       : [0][0][0][0]
       encoder         : Lavc59.43.100 libx265
   Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 
stereo, fltp, 127 kb/s (default)
     Metadata:
       handler_name    : SoundHandler
       vendor_id       : [0][0][0][0]
Stream mapping:
   Stream #0:0 -> #0:0 (hevc (native) -> h264 (h264_nvenc))
   Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Impossible to convert between the formats supported by the filter 'graph 
-1 input from stream 0:0' and the filter 'auto_scale_0'
[vf#0:0 @ 0x1d88d300] Error reinitializing filters!
[vf#0:0 @ 0x1d88d300] Task finished with error code: -38 (Function not 
implemented)
[vf#0:0 @ 0x1d88d300] Terminating thread with return code -38 (Function 
not implemented)
[vost#0:0/h264_nvenc @ 0x1d88db00] [enc:h264_nvenc @ 0x1d88d1c0] Could 
not open encoder before EOF
[vost#0:0/h264_nvenc @ 0x1d88db00] Task finished with error code: -22 
(Invalid argument)
[vost#0:0/h264_nvenc @ 0x1d88db00] Terminating thread with return code 
-22 (Invalid argument)
[out#0/null @ 0x1d88e300] Nothing was written into output file, because 
at least one of its streams received no packets.

I can add hwupload_cuda to the filter chain and it works again.

The problem is that I need a generic solution that works with both pixel 
formats without the need for different filter chains.

Is there any way to solve this?

Thanks a lot!

Jonathan



More information about the ffmpeg-user mailing list