Skip to content

Instantly share code, notes, and snippets.

@samelie
Created February 18, 2015 09:49
Show Gist options
  • Save samelie/32ecbdd99e07b9d8806f to your computer and use it in GitHub Desktop.
Save samelie/32ecbdd99e07b9d8806f to your computer and use it in GitHub Desktop.
ffmpeg last frame of video
#!/bin/bash
fn="$1"
of=`echo $1 | sed s/mp4/jpg/`
lf=`ffprobe -show_streams "$fn" 2> /dev/null | grep nb_frames | head -1 | cut -d \= -f 2`
rm -f "$of"
let "lf = $lf - 1"
ffmpeg -i $fn -vf select=\'eq\(n,$lf\) -vframes 1 $of
@mhwinkler
Copy link

Thanks for sharing! You could save future users some headache by adding a safety check before you run rm -f ...

Something like:

if [ "$fn" == "$of" ]; then echo "Only accepts MP4"; exit 1; fi

Otherwise, any input file that isn't an mp4 will be permanently deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment