0

The following ffmpeg command decodes a h265 rtsp video stream in hardware using qsv, lowers resolution from 4k to 1080p, fps from 20 to 5 and tries to save the video as rawvideo using the pix_fmt yuv420p.

ffmpeg -hide_banner -loglevel warning -hwaccel qsv -c:v hevc_qsv -use_wallclock_as_timestamps 1 -fflags nobuffer -rtsp_transport tcp -stimeout 5000000 -i rtsp://admin:secret@10.20.1.14:554 -vf fps=fps=5,vpp_qsv=w=1280:h=720 -c:v h264_qsv -g 25 -profile:v main -b:v 1M -an -f rawvideo -pix_fmt yuv420p test_output.yuv

The problem is that the hardware decoder uses nv12 as it's internal format, which results in the warning:

Incompatible pixel format 'yuv420p' for codec 'h264_qsv', auto-selecting format 'nv12'

The intention here is to pass the raw video on to another process which will do object detection and only supports yuv420p. I tried using vaapi instead of qsv but this gave me the same problem. How can I convert the pix_format using ffmpeg?

brujoand
  • 815
  • 8
  • 15

1 Answers1

0

I finally found the answer to this thanks to a comment on reddit.

ffmpeg -hide_banner -loglevel warning -hwaccel qsv -c:v hevc_qsv -use_wallclock_as_timestamps 1 -fflags nobuffer -rtsp_transport tcp -stimeout 5000000 -i rtsp://admin:secret@10.20.1.14:554 -vf fps=fps=5,vpp_qsv=w=1280:h=720:format=nv12,hwdownload,format=nv12,format=yuv420p -an -f rawvideo test_output.yuv

The problem was (from my understanding), that when we use hardware accelerate operations the frames are kept in a hardware dependent format. In this case nv12, and converting while residing in gpu memory isn't possible. But by using the 'hwdownload' instruction the frames are moved into normal memory and we can convert to yuv420p.

brujoand
  • 815
  • 8
  • 15