Search code examples
ffmpegcropscene

Detect scene change on part of the frame


I have a video file of an online lecture cosisting of a slideshow with audio in the background.
I want to save images of each slide as well as the timestamp of that slide. I do this using the scene and metadata filters:

ffmpeg -i week-01.mp4 -filter_complex "select='gt(scene,0.011)',metadata=print:file=frames/time.txt" -vsync vfr frames/img%03d.jpg

This works fine exept for one thing, there is a timer onscreen on the right in the video file. If i set the thershold small enough to pick up all the slide changes, it also picks up the timer changes.

So here is my question, Can I ask ffmpeg to:

  1. analize part of the frame (only the right side till roughly 75% to the left).
  2. Then, on detecting a scene change in this area, save the entire frame and the timestamp.

I though of making a script that

  1. crops the video and saves it alongside the origional
  2. analize the cropped video for scene changes and save the timestamps
  3. extract the frames from the origional video using the timestamps

Is there a better/faster/shorter way to do this? Thanks in advance!


Solution

  • You can do it in one command like this,

    ffmpeg -i week-01.mp4 -filter_complex "[0]split=2[full][no_timer];[no_timer]drawbox=w=0.25*iw:h=ih:x=0.75*iw:y=0[no_timer];[no_timer]select='gt(scene,0.011)',metadata=print:file=frames/time.txt[no_timer];[no_timer][full]overlay" -vsync vfr frames/img%03d.jpg

    Basically, make two copies of the video, use drawbox on one copy to paint solid black over the quarter of the screen on the right, analyze scene change and record scores to file; then overlay the full unpainted frame on top of the painted ones. Due to how overlay syncs frames, only the full frames with corresponding timestamps will be used to overlay on top of the base selected frames.