2

I have a small 30 second video that was taken from a long 10h video and processed. I am trying to find the position of the first frame from the 30 second video in the long 10h video. Because the small video has been processed, checksuming the frames doesn't work so I tried saving the first frame as an image,

ffmpeg -i clip.mp4 -qmin 1 -qscale:v 1 -vframes 1 -f image2 firstframe.jpg

and then using that image using that image to search it like this:

ffmpeg -i original_stream.ts -loop 1 -i firstframe.jpg -an -filter_complex "blend=difference:shortest=1,blackframe=99:32" -f null -

This sometimes works, but at times it returns more than 1 frame no matter what blackframe I'm using.

Also, if I try to use -ss to skip a part of the stream it doesn't return the precise time. For example,

  1. Without -ss:
    [Parsed_blackframe_1] frame:44250 pblack:99 pts:66375000 t:737.500000 type:P last_keyframe:44160
    
  2. With -ss 735:
    [Parsed_blackframe_1] frame:90 pblack:99 pts:227820 t:2.531333 type:P last_keyframe:0
    
  3. The times from the two examples above don't match up. Since t in example #1 is 737.500000, I would expect t in example #2 to be 2.500000, not 2.531333 :
    737.500000-735=2.500000
    
  4. Also, 735 x 90000 + 227820 ≠ 66375000

I think I can use the frame number as that seems to be the most accurate.

The whole reason I'm doing this is to extract the exact audio from the original stream that matches the 30 second clip so I need the exact position.

1
  • a) add -copyts with -ss to preserve timestamps; b) blend+blackframe is best generic method, avoid using an extracted image. Use trim and loop filters with clip.mp4 inside the filtergraph to supply frame to blend.
    – Gyan
    Commented Dec 18, 2021 at 4:28

1 Answer 1

0

input_video.mp4 is the name of the video file from which you want to extract a frame. output_frame.png is the name you want to give to the extracted frame. 3 is the frame number to extract. You can change this number to the frame you want. Make sure to count from 0, so the first frame is 0, the second frame is 1, and so on.

Thanks, Dealsdepot

1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 2, 2023 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .