Question

I'm trying to write a method that will provide the next frame and presentation time stamp when queried. The code currently looks something like this:

while( getNextFrame(image, pts) )
{
    // show current image
    drawImage(currentImage);
    sleep(pts);
    currentImage = image;
}

I've been following the Dranger tutorials to this point, but have stalled on reliably getting a PTS value for frames (http://www.dranger.com/ffmpeg/tutorial05.html). The PTS values returned are always 0.

Also, get_buffer() has been deprecated, so I'm now using the get_buffer2() method to set the global pts value. However, the release_buffer method has also been deprecated and I can't seem to find it's replacement. This leads me to believe that the method laid out in the tutorials may no longer be the best way of accomplishing this task.

In short, using up to date ffmpeg, what's the best way to grab frame pts values reliably?

Was it helpful?

Solution

Ok, you do not provide much information, So I am going to make some assumptions about your code.

int err, got_frame;
AVFormatContext *avctx;
AVPacket avpkt;
AVFrame *frame;
// You open file, initialize structures here
// You read packet here using av_read_frame()
{
    AVStream *stream = avctx->streams[avpkt.stream_index];
    if ( 0 > ( err = avcodec_decode_video2 ( stream->codec, frame, &got_frame, &avpkt ) && got_frame ) )
    {
        int64_t pts = av_frame_get_best_effort_timestamp ( frame );
        // TODO test for AV_NOPTS_VALUE
        pts = av_rescale_q ( pts,  stream->time_base, AV_TIME_BASE_Q );
        // pts is now in microseconds.
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top