[Libav-user] Muxing mpeg4-ts and raw audio to AVI file

Dmitry Gorbunov atskiisotona at gmail.com
Mon Aug 15 05:53:19 CEST 2011


Nicholas Butts wrote:
> 
>     if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE)
>         pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base,
> _videoStream->time_base);
> 

c->coded_frame->pts is a synthetic value produced by video encoder (usually
0, 1, 2, 3, etc). It may be good for constant frame rates, but sometimes
fails even then. And I believe that your case is related to variable frame
rate. I don't know for sure, but most hardware devices seem to produce
variable frame rate streams. My two web cameras do that at least.

You should use input_packet.dts (packet you read from input mpeg stream via
av_read_frame) and rescale it by input_stream->time_base and
output_stream->time_base:

pkt.pts = av_rescale_q(input_packet.pts, input_stream->time_base,
output_stream->time_base); // of course condition is not required

Why dts? Because it's more reliable than pts after decoding (I presume you
avcodec_decode_video on input packet to get raw video frame suitable for
encoding).

The above solution works for me on my web cameras, I hope it helps you.

--
View this message in context: http://libav-users.943685.n4.nabble.com/Libav-user-Muxing-mpeg4-ts-and-raw-audio-to-AVI-file-tp3740515p3743865.html
Sent from the libav-users mailing list archive at Nabble.com.


More information about the Libav-user mailing list