I'm trying to segment a video using avconv's "select" filter to extract only a specific range of frames from the input file. As an example, imagine I have a 60fps video file called input.mp4, with 3000 frames (i.e. 50 seconds), and I run
avconv -i input.mp4 -vf "select='lt(n,2000)'" output1.mp4
avconv -i input.mp4 -vf "select='gte(n,2000)'" output2.mp4
What I expect is that output1.mp4 has the first 2000 frames of input.mp4 (and lasts ~33 seconds), and output2.mp4 has the last 1000 (and lasts ~17 seconds).
I count the frames by running
avconv -i video.mp4 -vcodec copy -an -f null /dev/null 2>&1 | grep 'frame='
and checking the value assigned to 'frame'.
What I actually get, is that output1.mp4 has 2000 frames and lasts ~33 seconds, but output2.mp4 has 2999 frames, and still lasts the full ~50 seconds. When I open output2.mp4, I notice that the first 2000 frames of the video are actually just a repetition of the 2000th frame of the input, i.e. the first 2000 frames seem to be correctly filtered, but replaced by the first of the accepted frames.
This is not a pts problem. I check the number of packets and their relative pts using avprobe:
avprobe -show_packets output2.mp4
echo $(avprobe -show_packets output2.mp4 2>/dev/null | grep PACKET | wc -l)/2 | bc
I see that there are actually 2999 packets.
What am I doing wrong?
Side questions:
- Assuming I'm doing something wrong, why does output2.mp4 contain 2999 rather than the full 3000?
- The behaviour doesn't change whether I use the "gte" or "gt" function in the filter. Why could that be?