ffprobe – ffmpeg segmentation without re-encoding drops frames
I have an input file data
. When I run the command ffprobe -i data -show_streams -count_frames -select_streams v | grep nb_read_frames
, I count 39201 frames.
Now, I try to segment the video using command ffmpeg -i data -c copy -f segment -segment_time 120 -reset_timestamps 1 data_part_%d.mkv
. This command generate 11 segments. To count the total number of frames across all segments, I ran the following loop: for i in {0..10}; do ffprobe -i data_part_$i.mkv -show_streams -count_frames -select_streams v | grep nb_read_frames | cut -d '=' -f 2; done | awk '{s+=$1} END {print s}'
. This sums up to 36,684 frames, which is 2,517 frames less than the original count.
Some additional observations I made (not sure if they are relevant):
- I found a segment where
ffprobe
reported a duration of 2 minutes, but when I inspected the timestamps of the frames of that segment, the last timestamp was actually at 63 seconds. - When I play the segment with VLC, it is actually 2 minutes long. The last 57 seconds are all black frames. The black frames are expected: the
data
file also has a lot of consecutive black frames.
Why is there a discrepancy in the frame count between the original video and the segmented parts, and how can I avoid losing frames while segmenting without re-encoding?
Read more here: Source link