1

I am trying to use ffmpeg to extract every 30th frame from a video stream. For this, I have consulted all of https://superuser.com/questions/573747/drop-every-even-or-odd-frames-using-ffmpeg How to extract every 10th frame from a video? https://superuser.com/questions/1274661/selecting-one-every-n-frames-from-a-video-using-ffmpeg but neither option works.

The one that comes closest in my case is

$ ffmpeg -i DSCF0001.AVI -vf "select='not(mod(n-1,30))',setpts=N/(30*TB)" output.mkv

This creates a video that, in the beginning, does exactly what I want but then simply freezes at some point and does not continue. On the command line I get, during encoding, this message:

[matroska @ 0x559dfb975d40] Starting new cluster due to timestampte= 356.7kbits/s speed=8.09x    
    Last message repeated 3 times
[matroska @ 0x559dfb975d40] Starting new cluster due to timestampte= 358.5kbits/s speed=8.09x    
    Last message repeated 3 times
[matroska @ 0x559dfb975d40] Starting new cluster due to timestampte= 354.1kbits/s speed=8.09x    
    Last message repeated 3 times

Which may or may not be related to the issue.

What is the correct command line to achieve my goal?

  • and you *really* need every 30th frame, and not the video sped up by a factor of 30, leading to only having 1/30 of the original frames? I ask because the video processing for both is potentially pretty different! – Marcus Müller Jul 06 '23 at 19:08
  • 1
    @MarcusMüller Yes, indeed every 30th frame is correct. The video is not linear, i.e. has time jumps and the recording device records exactly 30 consecutive frames until it switches scene. I just want one frame from every scene. – performancematters Jul 06 '23 at 20:30
  • in that case, I'd start by ruling out container and encoder woes. Can you explicitly try a different container than mkv, and a different encoder, like `-c:v libx265`? (x265's main advantage over x264 on a video level is that it more gracefully deals with sudden changes, making it kind of desirable for the type of material you describe post-decimation, anyways) – Marcus Müller Jul 06 '23 at 20:49
  • @MarcusMüller That actually improves things a bit! The video is now playing back fully and does not freeze-frame midway through. However, after the video stream is finished the output video continues playing with a freeze-frame, i.e., EOF does not seem to be handled correctly. – performancematters Jul 07 '23 at 04:42

0 Answers0