[Ffmpeg-devel] av_seek_frame() issues with audio from MPEG-TS
abrown at daqtron.com
Thu Dec 8 01:44:46 CET 2005
>> I begin by finding the first video key frame
>> with a PTS that is not AV_NOPTS_VALUE. This will be my starting point of
>> playback for my new output stream. Now I need the audio to align up exactly
>> so that it starts precisely when the video starts. My idea was to take the
>> PTS of the video (no decoding yet so I'm still working with the AVPacket
>> container) and make a call into av_seek_frame() to grab the audio frame that
>> either starts exactly when the video frame does or just before it.
>> What I find is that the av_seek_frame() returns an audio frame with a PTS
>> greater than that of the video (by many audio frames in duration).
> Does this only happen at the start of the file?
> Can you check that it also happens when you first seek to somewhere
> within the TS file?
> I.e., could it be that there simply _are_ no audio frames with a
> PTS earlier than your initial video frame.
I found what is causing it but don't know enough yet to suggest a patch. The
av_seek_frame() function for mpegts is calling av_seek_frame_binary() which in
turn in using the mpegts function mpegts_get_pcr() to get and return the
timestamp. Therefore the timestamp returned is the PCR and not the audio's
PTS. Since audio and video use the same PCR, the av_seek_frame() will adjust
the file's pos to exactly the same value. The real problem comes in the fact
that because of buffering issues, the audio and video PTS are higher at a
particular spot in the file than the actual PCR (need to get the frame
buffer before its playtime to avoid underflow). This might be an issue only
affecting mpegts, but that's the format I'm most familiar with.
Any suggestions on how to modify the search to work on PTS instead of PCR?
More information about the ffmpeg-devel