[FFmpeg-devel] H264 encoding and RTP muxing - calculating pts and dts

Alexandre Ferrieux alexandre.ferrieux
Tue Jul 20 13:54:45 CEST 2010


On 20/07/2010 13:35, Luca Abeni wrote:
>
>> I get the video frames in RGB from my web camera, convert it to YUV but I
>> don't know how to set DTS and PTS values for packet.
>
> You can use the video4linux2 input, and it will generate proper timestamps
> for the input frames; then, the H264 encoder will generate proper PTSs and
> DTSs based on the input timestamps, and you can use them for the RTP muxer.
>
> This basically is what ffmpeg.c does, and it works fairly well (just
> tested).


Side question: what is the behavior of ffmpeg when such a VFR input (assuming the grabbing rate is somehow irregular) is 
converted to a CFR container and codec like TS/mpeg2 ?

Suppose an input timeline with frames F1...Fn. Dots indicate time:

   F1.....F2....................F3....F4................F5

and a regular output timeline for mpeg2ts:

   G1.......G2.......G3.......G4.......G5.......G6.......G7

What is G4:

    - F2 (latest) ?
    - F3 (closest, non-causal) ?
    - F4 (one-to-one) ?
    - other ?



Also, would it be possible to tell a no-timestamps container+codec like mjpeg to insert gettimeofday()-based DTS/PTS ? 
The typical use is an IP cam, with an underpowered CPU, which is rarely reaching the announced framerate, the effective 
rate varying wildly depending on the complexity of the image.

TIA,

-Alex



More information about the ffmpeg-devel mailing list