Created
February 18, 2015 09:49
-
-
Save samelie/32ecbdd99e07b9d8806f to your computer and use it in GitHub Desktop.
ffmpeg last frame of video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Handy. Saved me a lot of work. Thanks.
Thanks for sharing!
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
Thanks for being the only one on the net to provide the best way to do this, which is to find the number of the last frame. Everyone else, including the genii at stack*, did this by using timestamps.