带有AVSEEK_FLAG_ANY的ffmpeg av_seek_frame导致灰屏 [英] ffmpeg av_seek_frame with AVSEEK_FLAG_ANY causes grey screen
问题描述
问题:
omxplayer的源代码使用AVSEEK_FLAG_BACKWARD
标志调用ffmpeg av_seek_frame()
方法.尽管不确定100%,但我认为这是针对最接近的i帧.相反,我想寻找精确的位置,因此我修改了源代码,以使av_seek_frame()
方法现在使用AVSEEK_FLAG_ANY
标志.现在,在电影放映后,我会出现灰屏,通常持续1秒钟,在此期间我可以听到音频.我已经在多台计算机上进行了尝试(实际上,我也在同时同步它们),所以这不是一次孤立的事件.我的猜测是,寻找非i帧在计算上会更加昂贵,从而导致最初的灰屏.
Problem:
omxplayer's source code calls the ffmpeg av_seek_frame()
method using the AVSEEK_FLAG_BACKWARD
flag. Although not 100% sure, I believe this seeks to the closest i-frame. Instead, I want to seek to exact locations, so I modified the source code such that the av_seek_frame()
method now uses the AVSEEK_FLAG_ANY
flag. Now, when the movie loads, I get a grey screen, generally for 1 second, during which I can hear the audio. I have tried this on multiple computers (I am actually synchronizing them, therefore, at the same time too) so it is not a n isolated incident. My guess is that seeking to non i-frames is computationally more expensive, resulting in the initial grey screen.
问题:如何使用ffmpeg指示音频等待视频就绪,然后再继续操作.
Question: How, using ffmpeg, can I instruct the audio to wait until the video is ready before proceeding.
推荐答案
实际上,
Actually, AVSEEK_FLAG_BACKWARD
indicates that you want to find closest keyframe having a smaller timestamp than the one you are seeking.
通过使用 AVSEEK_FLAG_ANY
完全到您要求的时间戳.但是此帧可能不是关键帧,这意味着无法对其进行完全解码.这说明了您的灰色屏幕",直到出现下一个关键帧为止.
By using AVSEEK_FLAG_ANY
, you get the frame that corresponds exactly to the timestamp you asked for. But this frame might not be a keyframe, which means that it cannot be fully decoded. That explains your "grey screen", that appears until the next keyframe is reached.
因此,解决方案是使用AVSEEK_FLAG_BACKWARD
向后搜索,然后从该关键帧读取下一帧(例如,使用av_read_frame()
),直到获得与时间戳相对应的帧.此时,您的帧将被完全解码,并且不再显示为灰色屏幕".
The solution would therefore be to seek backward using AVSEEK_FLAG_BACKWARD
and, from this keyframe, read the next frames (e.g. using av_read_frame()
) until you get to the one corresponding to your timestamp. At this point, your frame would be fully decoded, and would not appear as a "grey screen" anymore.
注意::由于某种原因,当我要查找的帧恰好是之前的帧时,使用AVSEEK_FLAG_BACKWARD
的av_seek_frame()
返回 next 关键帧.这个关键帧.否则,它将返回上一个关键帧(这就是我想要的).我的解决方案是更改我给av_seek_frame()
的时间戳,以确保它会在我要查找的帧之前 返回关键帧.
NOTE: It appears that, for some reason, av_seek_frame()
using AVSEEK_FLAG_BACKWARD
returns the next keyframe when the frame that I am seeking is the one directly before this keyframe. Otherwise it returns the previous keyframe (which is what I want). My solution is to change the timestamp I give to av_seek_frame()
to ensure that it will return the keyframe before the frame I am seeking.
这篇关于带有AVSEEK_FLAG_ANY的ffmpeg av_seek_frame导致灰屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!