FFmpeg av_read_frame无法正确读取帧? [英] FFmpeg av_read_frame not reading frames properly?
问题描述
好的,所以我下载了.yuv格式的一些原始UHD序列,并在.mp4容器中以ffmpeg对其进行了编码(h264 4:4:4,100%质量,25fps).当我使用ffprobe找出要编码的帧数时,我得到600,所以这是24秒的视频.
Alright, so I've downloaded some raw UHD sequences in .yuv format and encoded them with ffmpeg in .mp4 container (h264 4:4:4, 100% quality, 25fps). When i use ffprobe to find out how many frames are encoded i get 600, so that's 24 secs of video.
但是,当我通过 av_read_frame
运行那些编码的视频序列时,在 av_read_frame
返回错误代码 -12 <之前,我只能得到40-50%的已处理帧/code>.因此,我很疯狂地猜测,流中间有一些数据包会被
av_read_frame
读取,并迫使函数返回 -12
.
BUT, when i run those encoded video sequences through av_read_frame
i only get like 40-50% of frames processed before av_read_frame
returns error code -12
. So I'm wild guessing that there are some data packages in middle of the streams which get read by av_read_frame
and forces a function to return -12
.
我的问题是什么,我应该如何处理此问题,以便可以编码完整的帧数(600)?当 av_read_frame
返回不同于 0
的值时,我应该 av_free_packet
并继续读取下一帧吗?由于 av_read_frame
返回值<0
用于错误代码,哪个错误代码用于 EOF
,以便我可以隔离文件代码的末尾?
What my questions are, how should i deal with this problem so i can encode full number of frames (600)? When av_read_frame
returns value different from 0
should i av_free_packet
and proceed to read next frame? Since av_read_frame
returns values < 0
for error codes, which error code is used for EOF
so i can insulate end of file code?
推荐答案
尽管很难说出解码出了什么问题,但 -12
仍然不是一个不可理解的神奇数字.
Though it's difficult to say what's wrong with your decoding, still -12
is not a magic number that can't be understood.
printf("%s\n", av_err2str(-12));
这将打印无法分配内存
,这是这里的真正问题.
This will print Cannot allocate memory
, which is the real problem here.
从 av_read_frame()
获得正返回值时,可以继续进行.
And when getting a positive return value from av_read_frame()
, it's ok to go on.
av_free_packet()
.
while(av_read_frame(fmt_ctx, &pkt) >= 0) {
// decode packet and other stuff
av_packet_unref(&pkt);
}
最后,通常无需担心EOF,因为 av_decode_video2()
或其他解码函数会将int参数设置为适当的值,以指示是否存在要解压缩的帧.
At last, usually there's no need to worry about EOF, since av_decode_video2()
or other decode functions will set a int parameter to proper value indicating whether there is frame to be decompressed.
如果您使用的是较新的ffmpeg(> = 3.1)解码/编码API或确实需要处理EOF,请将返回值与 AVERROR_EOF
进行比较.
If you're using a rather new ffmpeg(>=3.1) decoding/encoding API or really need to deal with EOF, compare the return value with AVERROR_EOF
.
这篇关于FFmpeg av_read_frame无法正确读取帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!