[Libav-user] Audio playing to fast using fflplay

Andrey Utkin andrey.krieger.utkin at gmail.com
Thu May 16 17:24:53 CEST 2013


2013/5/15 iwastemoretimethanu <willbeas88 at gmail.com>:
>  * Changing pts values before the encode, after the encode, using the
>    native av_rescale_q() function to try and automatically set the pts
>    value.
>      o  I have done quite a bit of research on this and it seems to be
>        the consensus that pts is supposed to be set before the frame is
>        encoded into the packet, and I have a formula that should work
>        for both the audio and video pts:
>          + frame_count * (1000/STREAM_FRAME_RATE) * 90
>          + ^ frame scale              ^ getting ms
>                ^ pts is apparently supposed to be time * 90
>  * Reducing the frames per second to a safe value (well-below the
>    potential of the system)
>  * Switching between the av_interleaved_write_frame() and the manual
>    av_write_frame()

I've used another pts assignment formula in transcoding apps.
For audio, you should set pts of uncompressed-yet AVFrame with raw
samples to _offset from stream beginning, in samples_. It means if you
have audio @ 48000 Hz, the raw audio timestamps should be stamped in
units of  1/48000 of second.
Then you put this AVFrame into encoder and get AVPacket. I don't
remember to what AVPacket.dts, .pts is set to after this, you should
check. Either libavcodec rescales timestamp to timebase of media file
(i.e. 1/1000 for FLV, 1/90000 for MPEG TS), or you have to do it by
yourself.
That's all.

--
Andrey Utkin


More information about the Libav-user mailing list