[Libav-user] Configuring mp4 muxer to not recalculate time_base to an absurd timescale value

Corey Taylor corey.taylor.fl at gmail.com
Thu Jan 11 07:02:53 EET 2018

I was able to resolve this.  I said something incorrect earlier about
the RTP flags.  Clearly this has nothing to do with the timescaling ..
I just misread the same for loop.

You *must* re-scale the packet timestamps before calling
av_interleaved_write_frame with av_packet_recale_ts().

Call this with the AVCodecContext time_base as the tb_src and the
AVStream time_base as the tb_dest.  This will scale the pts, dts and
duration values.

 * Convert valid timing fields (timestamps / durations) in a packet from one
 * timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
 * ignored.
 * @param pkt packet on which the conversion will be performed
 * @param tb_src source timebase, in which the timing fields in pkt are
 *               expressed
 * @param tb_dst destination timebase, to which the timing fields will be
 *               converted
void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);


On Tue, Jan 9, 2018 at 2:50 PM, Corey Taylor <corey.taylor.fl at gmail.com> wrote:
>> I set the time_base value in the output AVStream to 1/90000, then stepped through the code to write the header, some frames, and then the trailer. Watching the time_base value in the debugger as I stepped through, I noticed that the values change to the 1/15360 value after the invocation of av_write_header(), which matches your findings. I am currently working around the issue by rescaling each frame's PTS/DTS to the new 1/15360 timebase, rather than using the actual timebase associated with the stream produced by the camera.
> Where you able to test if the older library modified the time-base at all?
> corey

More information about the Libav-user mailing list