[FFmpeg-user] Extract image every x frames?

Peter B. pb at das-werkstatt.com
Mon Aug 6 17:30:24 CEST 2012

Quoting Kosta Vlotis <kosta.brazzers at gmail.com>:

> On Mon, Aug 6, 2012 at 8:21 AM, Peter B. <pb at das-werkstatt.com> wrote:
>> I've found several examples of how to extract images from a video using
>> ffmpeg. Unfortunately, my use case seems less popular, and I'm not sure how
>> or if it is possible with ffmpeg:
>> I'd like to extract a frame exactly every 1500 frames - on material with
>> different fps rates.
> i may be wrong but "-r 1500" might do it

I don't think this works the way I'd need it to, because:
"$ffmpeg -i video.mpg -r 1 -f image2 out-%03d.jpg"
exports 1 image per second (if fps=25).

I'd rather need something like "-r 1/1500", but that won't work :(

I've now used ffprobe's XML-output (to get FPS) and a batch-loop and  
bc-math to calculate the 1500 frame stepsize as seconds to feed to  

while (true); do
         START=$(($MINUTE * $STEP_SIZE))
         START_SEC=$(echo "$START / $FPS" | bc -l)
         START_SEC=$(printf "%.3f" "$START_SEC")

         IMAGE_OUT=$(printf "$DIR_OUT/$SIGNATURE-%03d.jpg" $MINUTE)

         local CMD="$FFMPEG -i $VIDEO_IN -ss $START_SEC -vframes 1 -f  
image2 -sameq -vcodec mjpeg $IMAGE_OUT"
         echo $CMD
         eval "$CMD"

         MINUTE=$(($MINUTE + 1))
         if [ ! -s "$IMAGE_OUT" ]; then
             # If no image was generated, exit the loop:
             echo "done."

Not sexy, but it works...


More information about the ffmpeg-user mailing list