[FFmpeg-devel] Question about frame->pts, outlink->time_base, and outlink->frame_rate

Nicholas Robbins nickrobbins at yahoo.com
Tue Jan 28 15:11:20 CET 2014


I'm working on a filter, and I've gotten it to the point where it does most of what I need, however some of the behaviour is still not what I expect.

The filter modifies the PTS's of the frames in the video stream. filter_frame(AVFilterLink *inlink, AVFrame *frame) calculates the new PTS's and writes them to frame->pts. I know that they are correct because 

a) av_log(ctx, AV_LOG_DEBUG, "new=%"PRId64"\n", frame->pts) reports the correct PTS
b) if I put a filter after them that reports the PTS's it shows the new ones.

The new PTS's are much larger (about 8 times) the old ones, so there is no mistake about which is which.

Now to avoid fractional PTS's I scale the timebase by 8, via 

    outlink->time_base = av_mul_q(inlink->time_base,av_make_q(1,8))

in  config_out_props(AVFilterLink *outlink) (with inlink= outlink->src->inputs[0];)

Now my test stream has pkt_durations of 33, 34, 66, and 67 (stream timebase 1/1000 fps=30/1001 with some dropped frames.)  If I just adjust the timebase and PTS's as above, I get PTS with gaps of ~266 (section without dropped frames) or ~333 (section without dropped frames) this is infact what the av_log command produces.

However, when the stream gets written to a file, it still has timebase 1/1000 and PTS's with gaps of 33, 34, 66 or 67. They aren't quite the same PTS's however. They vary by one or two sometimes. 

So I tried changing some other things in config_out_props. I found that if I set outlink->frame_rate = av_make_q(1,0) it would still forget the new timebase, but it would use the new PTS's. Sort of. I found gaps of ~42 which is the new gaps divided by 8.  Seems like it converted the new PTS's from the new time_base to the old one and save them.

So this is mostly satisfactory. However, I really would like to make the timebase change stick, for less rounding error. What do I do to get the timebase change to stick?

Thanks for any help.

-Nicholas Robbins

More information about the ffmpeg-devel mailing list