Reputation: 486
I'm able to extract all frames that are not similar to the previous frame from a video file using ffmpeg -i video.mp4 -vf "select=gt(scene\,0.003),setpts=N/(30*TB)" frame%d.jpg
(source)
I would like to overlay the frame number onto each selected frame. I tried adding drawtext=fontfile=/Windows/Fonts/Arial.ttf: text='frame\: %{frame_num}': x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1: fontsize=30
to the filter after select and setpts, however %{frame_num} returns 1, 2, 3, ...
(source)
If I put drawtext before select and setpts, I get something like 16, 42, 181, ...
as frame numbers (which is exactly what I want), but since the scene detection runs after adding the text overlay, changes in the overlay may be detected as well.
Is it possible to do the scene detection and overlay independently from another? [in] split [out0][out1]
can be used to apply filters separately, but I don't know how to "combine" the results again.
Upvotes: 0
Views: 929
Reputation: 93299
You are on the right track. Use split first to create two streams. Run scene detection on one, and draw text on another. Then use overlay to paint the numbered stream on the pruned stream - only the corresponding pruned numbered frames will be emitted.
ffmpeg -i video.mp4 -vf "split=2[num][raw];[raw]select=gt(scene\,0.003)[raw];[num]drawtext=fontfile=/Windows/Fonts/Arial.ttf: text='frame\: %{frame_num}': x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1: fontsize=30[num];[raw][num]overlay=shortest=1,setpts=N/(30*TB)" -r 30 frame%d.jpg
Upvotes: 1