使用vda加速的ffmpeg解码示例?

ffmpeg decode example using vda acceleration?

我正在测试 ffmpeg 的 vda hw 加速解码器,但到目前为止没有运气。

我使用的命令行是这样的:

./ffmpeg -hwaccel vda -i ~/Downloads/big_buck_bunny_720p_surround.avi -c:v rawvideo -pix_fmt yuv420p out.yuv

(输入视频可以在这里下载:http://mirrorblender.top-ix.org/peach/bigbuckbunny_movies/big_buck_bunny_720p_surround.avi

但它使用 sw 解码器,而不是请求的 vda hw 解码器。

我调试了ffmpeg.c,发现在函数get_format:

if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
    break;

desc->flag 没有设置 AV_PIX_FMT_FLAG_HWACCEL,所以它跳过硬件加速初始化。

原因是因为某些原因pix_fmt设置为AV_PIX_FMT_NONE,而不是命令指定的yuv420p

然后我将命令更改为:

./ffmpeg -hwaccel vda -i ~/Downloads/big_buck_bunny_720p_surround.avi -c:v rawvideo -pix_fmt vda_vld out.yuv

但我得到的是:

Impossible to convert between the formats supported by the filter 'format' and the filter 'auto-inserted scaler 0'


Error opening filters!

你能给我一个例子吗,使用 ffmpeg 将上面的视频转储到使用 vda 硬件解码器的 yuv 中?

来自 ffmpeg 邮件列表的更新。

我被告知改为尝试以下命令:

    ./ffmpeg -vcodec h264_vda -i ~/Downloads/big_buck_bunny_720p_surround.avi out.yuv

但这就是我得到的:

./ffmpeg -vcodec h264_vda -i ~/Downloads/big_buck_bunny_720p_surround.avi out.yuv

ffmpeg version 2.6.1 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
configuration: 
libavutil      54. 20.100 / 54. 20.100
libavcodec     56. 26.100 / 56. 26.100
libavformat    56. 25.101 / 56. 25.101
libavdevice    56.  4.100 / 56.  4.100
libavfilter     5. 11.102 /  5. 11.102
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  1.100 /  1.  1.100
[10:20:50.169] vtDecompressionDuctCreate signalled err=-8973 (err) (Could not select and open decoder instance) at /SourceCache/CoreMedia_frameworks/CoreMedia-1562.107/Sources/VideoToolbox/VTDecompressionSession.c line 1181
[h264_vda @ 0x7f9feb034600] Failed to init VDA decoder: -12473.
[avi @ 0x7f9feb00da00] Failed to open codec in av_find_stream_info
[NULL @ 0x7f9feb034600] missing picture in access unit with size 9960
[10:20:50.252] vtDecompressionDuctCreate signalled err=-8973 (err) (Could not select and open decoder instance) at /SourceCache/CoreMedia_frameworks/CoreMedia-1562.107/Sources/VideoToolbox/VTDecompressionSession.c line 1181
[h264_vda @ 0x7f9feb034600] Failed to init VDA decoder: -12473.
[NULL @ 0x7f9feb034600] missing picture in access unit with size 457

我想尝试这个的原因是因为我想首先将 vda 与 libavcodec 一起使用。但我看到的问题正是上述问题。看起来 ffmpeg 有同样的问题。

我给 libavcodec/vda_h264_dec.c 的作者发了一封电子邮件,他回复了以下消息:

I'm not very surprised that the VDA decoder cannot be properly inited here. I guess you probably eventually have to remux your video to use MP4 or MKV container.

I don't know exactly what happens there, but according to my experience playing with VDA framework before, that framework had quite a few limitations. I guess the limitation you met might be that, it required some extra data of the video to init the decoder, which made it support only some of the containers. I forget what the exact name of that extra data, but AFAIK, only MP4-compatible container could provide that.


我还记得mp4有个extradata字段,但不知道是什么

我很快尝试了以下命令,它起作用了:

./ffmpeg -hwaccel vda -i ~/Downloads/big_buck_bunny.mp4 -c:v rawvideo -pix_fmt yuv420p out.yuv​