如何对 h265 视频(较低分辨率和 fps)进行硬件解码并以 yuv420 格式作为原始视频传递
以下 ffmpeg 命令使用 qsv 在硬件中解码 h265 rtsp 视频流,将分辨率从 4k 降低到 1080p,将 fps 从 20 降低到 5,并尝试使用 pix_fmt yuv420p 将视频保存为 rawvideo。
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:[email protected]: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
问题是硬件解码器使用 nv12 作为其内部格式,这会导致警告:
编解码器“h264_qsv”的像素格式“yuv420p”不兼容,自动选择格式“nv12”
此处的目的是将原始视频传递到另一个将进行对象检测且仅支持 yuv420p 的进程。我尝试使用 vaapi 而不是 qsv 但这给了我同样的问题。如何使用 ffmpeg 转换 pix_format?
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:[email protected]: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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 reddit 上的评论。
问题是(根据我的理解),当我们使用硬件加速操作时,帧以硬件相关的格式保存。在这种情况下,nv12 无法驻留在 GPU 内存中进行转换。但是通过使用“hwdownload”指令,帧会被移动到普通内存中,我们可以转换为 yuv420p。
I finally found the answer to this thanks to a comment on reddit.
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.