[Libav-user] dts/pts/duration in packets

Max Vlasov max.vlasov at gmail.com
Wed Sep 2 08:34:55 CEST 2015


On Wed, Sep 2, 2015 at 6:01 AM, qw <applemax82 at 163.com> wrote:

I'm using avcodec_encode_video2() and avcodec_encode_audio2() to encode
> video and audio raw data respectively. Can the two encoding function
> calculate dts/pts/duration of output packets itself? Or I'll calculate
> those timestamp values by using other method? Does ffmpeg provide examples
> to calculate those timestamp values?
>
>
Basically the steps for both streams are (at least I use it for encoding)

- You initialize the stream codec.time_base with the preferred choice. The
best is frame rate for video (for example Num=1,  Den = 25 for Pal video)
and sample_rate for audio (Num = 1 Den 44100 for 44k sound). I suspect
other choices might work, only have in mind that rounding errors might
affect the accuracy of the final stream values

- Before calling avcodec_encode_*  function you set the packet pts value to
the correspondent next one. For choices above you should increase the video
value by one for video and the number of audio samples for audio.

- Before calling av_interleaved_write_frame you call  av_packet_rescale_ts
providing the packet with the changes explained above, the codec time_base
explained above and the stream time_base that is defined by the library
(you don't set it yourself).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20150902/66f93d29/attachment.html>


More information about the Libav-user mailing list