4

I'm trying to detect cuts between shots with ffprobe. I use the following command:

ffprobe -show_frames -of compact=p=0 -f lavfi "movie=test_clip.avi,select=gt(scene\,.4)" > test_clip_cuts.txt

It works just fine, there's no question. But now I want to detect the cuts in certain range only. Let's say from 3 to 8 seconds. How I could do that?

I tried to use -read_intervals 3%8 but it gave me an error:

Could not seek to position 3000000: Invalid argument
Could not read packets in interval id:0 start:3 end:8

Command -read_intervals %+3 (read from the very begining to 3rd second) works, but in weird way - it detects cuts up to 4th second (and over, I guess).

So I'm confused. What are those "intervals" and how to use them? Is it possible to set the range in regular seconds?

Just in case here is my test clip https://yadi.sk/i/nd-c12mYeQ2nb

2 Answers2

1

After reading through the libavfilter documentation, I found the best way to do this is with a combination of the movie seek_point option and the trim option:

ffprobe -show_frames -of compact=p=0 -f lavfi "movie=test_clip.avi:seek_point=3,trim=3:8,select=gt(scene\,0.4)" > test_clip_cuts.txt

If you'd prefer to use a start time and duration, you can use the syntax :seek_point=3,trim=3:duration=5

This runs the cut/scene detection on only the portion of the video that's specified. Using between gives the same output, but still runs the detection on the entire video which is far slower for large videos. I also can't seem to find between mentioned anywhere in the documentation. Using trim by itself is fast if the targeted portion of the video is near the beginning, but grows slower the further into the video you go. If the start time is omitted in the trim option when used with seek_point, the detection appears to sometimes start around a second earlier than expected, likely because seek_point is seeking to the nearest keyframe.

Roman Scher
  • 1,162
  • 2
  • 14
  • 18
  • 1
    I did a quick check and it works like a charm! I'll do more testing, but I guess it will be ok. Seven years of waiting is worth it =) – Roman Volodin Mar 10 '22 at 16:39
  • Learned today from testing, apparently including the start time in the trim option is important to detect precisely in the desired range, otherwise the seeking start point can be slightly off from expected. Updated the answer to reflect this – Roman Scher Mar 14 '22 at 16:34
0

Finally I've find the answer =)
To detect cut only between 3 and 8 seconds I have to replace

"movie=test_clip.avi,select=gt(scene\,.4)"

with

"movie=test_clip.avi,select=between(t\,3\,8)*gt(scene\,.4)"