Problem
I have a list of frames that I want to extract from some video file. The list might look like this:
1,6,6,10,15,20,20,25,25,50
In reality there are thousands of frames.
How do I extract these frames into images or video in efficient way?
What I have tried
select=eq(\\n,1)+eq(\\n,6)+...
but the problem is that I cannot export duplicates this way. Also I am not sure about the performance.cv.VideoCapture
functionality to read frame by frame and save the ones I need. The problem is that before the extraction, I need to change framerate of the video to some constant framerate (very important). That's why ffmpeg is preferred, because I could add fps filter to filterchain. I know that it's possible to read frames with opencv by using ffmpeg backend, but I couldn't find how to change the framerate beforehand. Reencoding the video before is not preferred as it wastes time and possibly decreases video quality.bash script:
#!/bin/bash
LST=(1 6 6 10)
TOT=${#LST[*]}
for (( i=0; i<=$(( $TOT -1 )); i++ )); do
ffmpeg -i "input 1.mkv" -filter:v "select='eq(n,${LST[$i]})'" -vsync vfr "/tmp/img_${i}_${LST[$i]}.jpg"
done
it is not fast, but works ☺
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.