[Libav-user] Changes to time_base and PTS/DTS that break transcode example

Deron deron at pagestream.org
Fri Mar 31 17:07:59 EEST 2023

I wrote a continuous streaming app last year using libav. Worked well 
enough, but it suffers from drifting audio sync issues over time. So a 
couple weeks ago I had some free time and I was going to look at the 
issue as a learning opportunity.

The first thing I did was update to the latest ffmpeg libav* only to 
find out my app no longer works at all. Worst yet, neither does the 
example transcode. The first series of bisects lead me to the change in 
commit 5f9e848e686a3c0795939809712b260af5c1adb8 that required the first 

from current(!) [ffmpeg git]/doc/examples/transcode.c:

  266         snprintf(args, sizeof(args),
  267 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
  268                 dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
  269                 dec_ctx->time_base.num, dec_ctx->time_base.den,
  270                 dec_ctx->sample_aspect_ratio.num,
  271                 dec_ctx->sample_aspect_ratio.den);

Evidently dec_ctx->time_base no longer contains a valid time_base. 
However, updating that to now pull time_base from in_stream->time_base 
similar to ffmpeg only got me a tiny bit further.

Now, depending on the source file, transcode gives me continuous 
"non-strictly-monotonic PTS" or "Discarding initial frame(s) with no 
timestamp" or worse. Looking through ffmpeg sources, I see a great deal 
of code that modifies pts/dts. This is not just the tutorial/example 
changes that simply rescale from one time_base to another as the 
packets/frames are moved between queues. I can guess at what some of it 
does, but much of it I am unclear if this code is now required for all 
or is simply ffmpeg specific features (whatever those features might be).

Where can I find out what this ffmpeg code is for, or what I should be 
doing with regards to pts/dts now?

Thanks for any help,


More information about the Libav-user mailing list