[Libav-user] Raw H264 frames in mpegts container

Mart mart.vandesanden at yb.nl
Fri Sep 9 17:15:44 CEST 2011

As I understand and use it, to calculate the pts you need to take the 
time base of the stream into account. For example, my application uses a 
native time base that is in microseconds (thus if you have a frame rate 
of 15, the timestamp of each frame is increased by 1000000/15 = (about) 
66667). This can be calculated to the stream's time_base with the 
av_rescale_q function, in the following manner:

     pkt.pts = av_rescale_q(packet->timestamp().microseconds(), 
(AVRational){1,1000000}, stream_context->time_base);

The first argument is the timestamp of the frame in microseconds, the 
second is the microsecond time_base and the third argument is the 
streams time_base. So this functions transfers a value from one time 
base to another.

I hope this helps (and that it is correct, it seems to work for me :))!



On 09/08/2011 03:09 AM, psychesnet wrote:
> Hello Amir,
> My source H264 and AAC are raw data, I try to packet it into mpegts by
> ffmpeg, but my issue is how to sync video and audio. In my research, I can
> use pts to sync video and audio, but I do not calculate the pts value on raw
> data resource. On the Internet, there are a lot of sample code about how to
> packet H264+AAC to mpegts, but the pts value is copied from original input
> file, no calculate function to do.
> So, my issue is how to calculate the pts under mpegts container.
> Thanks a lot.
> --
> View this message in context: http://libav-users.943685.n4.nabble.com/Re-Raw-H264-frames-in-mpegts-container-tp3602662p3797635.html
> Sent from the libav-users mailing list archive at Nabble.com.
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user

Mart van de Sanden | yellowBird

yellowBird - See the world like never before
Brugstraat 32 / 9711 HZ Groningen / The Netherlands

M. (Mart) van de Sanden / Software Specialist

T +31 50 8222 822
F +31 50 8501 351
E  mart.vandesanden at yb.nl
W http://www.yb.nl

More information about the Libav-user mailing list