Search code examples
encodingffmpegh.264pts

Why do I lose PTS information when encoding to H264?


I have a video file, with this video stream:

ffmpeg -i original.avi

Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 4204 kb/s, 59.94 fps, 59.94 tbr, 59.94 tbn, 59.94 tbc

I can get the PTS information by running:

ffprobe -v 0 -of csv=p=0 -select_streams v -show_entries packet=pts_time original.avi

And I get the PTS for each frame line by line:

0.016683
0.116783
0.033367
0.050050
0.166833
0.083417
0.100100
0.216883
...

Now I need to encode the video to H264 and be able to get the same PTS information afterwards, so I used:

ffmpeg -i original.avi -vcodec libx264 output.avi

With this video stream:

Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 2289 kb/s, 59.94 fps, 59.94 tbr, 59.94 tbn, 119.88 tbc

But when I try to get the PTS information from the output.avi I only get:

N/A
N/A
N/A
N/A
N/A
N/A
...

What should I change in my command in order to keep the PTS information?


Solution

  • AVI doesn't really support H.264.

    There are some hacks in place that make it work, but it's not surprising that you'd have some side effects. Consider using MP4 or MKV instead.