I scan the input video to extract specific frames using the ffmpeg select filter. The choice is based on a complex creteria, and the number of frames selected cannot be predicted (I am engaged in scene detection, but it can be something else - for example, the selection of all frames I , etc.),
I need to display the percentage of scanned (decoded) video (e.g. 10% or 90%).
I tried several ways to draw this parsing output, as people usually do when working with encoding, but this does not help during the scan (for example, Can ffmpeg show the progress bar? Or ffmpeg Progress Bar - Percentage of encoding in PHP )
ffmpeg -progress sceneProgr.txt -i input.wmv -vsync passthrough -an -vf select='gt(scene\,0.2)',showinfo scene%%05d.png
The result that he produces is as follows:
<..> frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A n:0 pts:16550 pts_time:16.55 pos:4205325 fmt:rgb24 sar:0/1 s:640x480 i:P iskey:1 type:I checksum:95895BC9 plane_checksum:[95895BC9] frame= 1 fps=0.7 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A n:1 pts:24591 pts_time:24.591 pos:6685325 fmt:rgb24 sar:0/1 s:640x480 i:P iskey:0 type:P checksum:FF4CC015 plane_checksum:[FF4CC015] 'frame=...' and 'n:...' lines are repeated for each of the extracted frames.
The lines frame=... and n:... refer to the numbers on the output , and therefore cannot be used to calculate the progress , as people usually do (since I can not predict how many frames will be found before the start and, in addition, they will not be evenly distributed across the input video).
If I specify the -progress progress.txt parameter -progress progress.txt file looks like this:
frame=5 fps=1.2 stream_0_0_q=0.0 total_size=N/A out_time_ms=43209833 out_time=00:00:43.209833 dup_frames=0 drop_frames=0 progress=continue frame=6 fps=1.3 stream_0_0_q=0.0 total_size=N/A out_time_ms=52252200 out_time=00:00:52.252200 dup_frames=0 drop_frames=0 progress=continue frame=6 fps=1.2 stream_0_0_q=0.0 total_size=N/A out_time_ms=52252200 out_time=00:00:52.252200 dup_frames=0 drop_frames=0 progress=continue
A new part is recorded approximately every second and refers to the last frame retrieved . Which is somewhat useful, since out_time refers to the position of the last frame extracted in the input video, so I can calculate the scan progress from it as
progress = out_time_ms/total_input_time
But this is not ideal , because it will only be updated when a new frame that matches the select criteria is retrieved. So, if I have most of the video without suitable frames, the progress will not change for a long time.
Wrapping up
I am looking for a way to calculate the progress of a video scan using select .
Any ideas are greatly appreciated.