[FFmpeg-user] How to extract pts_time fast?

Moi15 Moi moi15moismokerlolilol at gmail.com
Sat Jul 27 18:36:16 EEST 2024


Hi,

My goal is to extract the timestamps of a video using ffprobe. Currently, I
do it with mkvextract like this: mkvextract FILE.mkv timestamps_v2
0:timestamps.txt.

I thought of extracting the timestamps like this: ffprobe -select_streams 0
-show_entries frame=pts_time -print_format json VIDEO.mkv. But I quickly
realized that ffprobe takes a long time to execute this command (around 1
minute for a 7-minute video). That's why I tried to find a quicker way to
extract the timestamps.

I tried to use the timestamps of the packets like this: ffprobe
-select_streams 0 -show_entries packet=pts_time -print_format json VIDEO.mkv.
It is much faster (less than 1 second for a 7 minutes video).

>From what I know, the pts_time provided with the packet may differ from the
frame one because it's possible but uncommon for multiple frames to be
carried in one packet, or for a frame to be split (as slices) across
multiple packets.

So, here is my question: is there a "heuristic" to know if the packet
timestamps will be the same as the frame timestamps? My idea was that if
the number of frames is different from the number of packets, then I need
to use the frame timestamps. I thought of counting the frames and packets
like this: ffprobe -select_streams 0 -show_entries
stream=nb_read_frames,nb_read_packets -count_frames -count_packets
-print_format json VIDEO.mkv.

moi15moi


More information about the ffmpeg-user mailing list