1

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?
llogan
  • 121,796
  • 28
  • 232
  • 243
user2152106
  • 143
  • 2
  • 6

1 Answers1

1

You are most likely seeing this due to the fact that there are other streams in the file. I was able to get rid of the problem that you've described by removing other streams in the second command:

avconv -i input.mp4 -vf "select='gte(n,2000)'" -an -sn output2.mp4

As i understand it, what's going on is that you have, for example, an audio stream, which you aren't dropping, so when you've dropped the video frames the video stream just got the fist frame that it could get its hands on and claimed that it will last until the next frame will arrive.

This way you will, of course, have to edit the audio and then mux it back into the video.

v010dya
  • 5,296
  • 7
  • 28
  • 48