[FFmpeg-user] Some mysterious about adding PTS to a variable frame rate mp4 video

Sean Feng sean at seanfeng.dev
Fri Jan 10 22:06:12 EET 2020


Hi all,

I have a mp4 video which is in VFR, and also a few negative frames 
before I cut it from another video. So the PTS of this video looks like 
this

    pts_time=-1.812278
    pts_time=-1.223744
    pts_time=-1.201211
    pts_time=-0.899378
    pts_time=-0.882033
    pts_time=0.000000
    pts_time=0.113378
    pts_time=0.129322
    pts_time=0.146244
    pts_time=0.211711
    pts_time=0.243133
    pts_time=0.390133
    pts_time=0.406111

Now, I want to add the timestamp to the video itself, I used this command

    fmpeg -nostdin -i input.mp4 -c:v libx264 -profile:v baseline -vf
    "drawtext=x=(w-(max_glyph_w*13))/2:
    y=H-h/10:fontcolor=white:fontsize=h/14:box=1:boxcolor=0x000000AA:text='%{pts\\:hms}'"
    -y -vsync 0 output.mp4

I used vsync 0 because I didn't want to lose any of those frames, and it 
looked fine in terms of number of the frames.

The problem is, when I use a media player to play the output video, I 
can see some of frames felt into the same timestamp. What I mean is the 
frame itself has the correct PTS as they had been drawn, however the 
timestamp of video isn't correct. If I get the PTS of the output video, 
I see this

    pts_time=0.000000
    pts_time=0.000000
    pts_time=0.251053
    pts_time=0.251053
    pts_time=0.251054
    pts_time=0.251054
    pts_time=0.502106
    pts_time=0.502106
    pts_time=1.004213
    pts_time=1.004213
    pts_time=1.004213
    pts_time=1.004213
    pts_time=1.004213
    pts_time=1.004214

Hope I am clear and any help is greatly appreciated!

Thanks!



More information about the ffmpeg-user mailing list