[Ffmpeg-devel] Audio and Video Frame Start/End Time

Rich Felker dalias
Fri Oct 7 04:42:19 CEST 2005


On Thu, Oct 06, 2005 at 11:51:52AM -0400, Paul Curtis wrote:
> I have moved on to the next level of this application. Basically, it 
> uses ffmpeg to read an MPEG2 stream, and pass the decoded audio and 
> video to the Helix Producer SDK. This works, but I'm having some 
> problems obtaining timing information.
> 
> The Helix SDK requires a start time and end time (in milliseconds) for 
> each "sample" provided. So, for example, I decode the audio, use the 
> pkt.pts, and calculate the audio "end time" based on channels & sample rate.

It's not possible to calculate the end time this way. The only way to
get the end time of an audio frame is either to decode it, or to get
the pts of the next frame.

> The video, however, is posing a problem. Since (as I read in an earlier 
> thread) that the AVPacket.pts value is not necessarily valid, I need to 
> calculate the video timing myself.

It should be valid, but for some demuxers it won't be because
computing the correct pts for certain formats is prohibitively painful
(at least if done by default). There was a proposal to make a flag
that forces demuxers to do whatever's necessary to get pts for all
packets, but I don't know if that ever went anywhere. :(

> My question is whether each frame decoded represents one frame of video 
> at the input frame rate. In other words, if I keep a count of the number 
> of frames decoded, and calculate the start and end times based on the 
> frame rate, is this the correct method? Have others found this same problem?

There's not necessarily a framerate. Framerate only makes sense if all
the frames have same duration.

> Should I be calculating the audio timing the same way?

No, since it doesn't work.. :)

> Should the timings start at zero?

Not necessarily.

Rich





More information about the ffmpeg-devel mailing list