ffmpegmp4ffprobemkvpyav

ffprobe - shuffled frame metadata


I'm using mkvmerge to combine a mp4 CFR video with a text file containing VFR timestamps. The command used was

mkvmerge --timestamps 0:timestamps.txt input_video.mp4 -o output_video.mkv

Where the textfile timestamps.txt was of a v2 timestamp format. Here are the first few entries

# timecode format v2
0
6
21
36
53
71
87
103
123

I'm trying to print these timestamps back out with

ffprobe -v 0 -show_entries packet=pts,duration -of compact=p=0:nk=1 -select_streams v output_video.mkv

But I receive shuffled entries

0|6
6|15
21|15
36|17
53|18
123|15
87|16
71|16
103|20

If I read the frames with PyAV for example, I get the values in correct order.

import av
c = av.open("output_video.mkv")
for frame in c.decode(video=0):
     print(frame.pts)

Output:

0
6
21
36
53
71
87
103
123

Am I using ffprobe incorrectly? Any help would be very welcome!


Solution

  • If the video stream has B-frames then future P-frames which act as reference for B-frames are encoded first and stored in that order. They are reordered after decoding.

    For ffprobe, the entries in packet are arranged in decode or storage order. In frames, they are decoded and arranged in presentation order.