Something went wrong. Try again.
My assorted media manipulation scripts
Something went wrong. Try again.
mediascripts framedumper
2.5 kB · 96 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697#!/usr/bin/env bash
usage() {cat - <<EOFUsage: $NAME -i <INPUT FILE>
-h|--help: show this help message-i|--input: file name for input-f|--frames: number of frames to fetch-d|--debug: print all commands and wait for keypress to continue
EOF}
while [ $# -gt 0 ]; do OPT="$1" case "${OPT}" in -i|--input) shift INPUT="${1}" shift;; -f|--frames) shift FRAMES="${1}" shift;; -d|--debug) DEBUG=1 shift;; -h|--help) usage exit;; *) echo "$0: invalid option ${1}" echo "$0 -h for usage options" usage exit 1;; esacdone
# Check for tool dependenciesSELF_FULLPATH=`realpath $0`SELF_DIR=`dirname $SELF_FULLPATH`# Override default tool list, we only need these twoTOOLS=(ffmpeg ffprobe mediainfo)# Does not depend on any other scriptsSCRIPTS=NONEif [ ! -r $SELF_DIR/toolchecker ]; then echo "toolchecker not found." exit 1else . $SELF_DIR/toolcheckerfi
if [ -z "$INPUT" ]; then echo "Must supply input (-i/--input) file" usage exit 1fi
if [ ! -s "$INPUT" ]; then echo "Error reading input file: $INPUT" exit 1fi
if [ ! -z "$FRAMES" ]; then if [ ! $FRAMES -gt 0 ]; then echo "Invalid sample count. Using defaults." FRAMES=50 fielse FRAMES=50fi
FRAMECOUNT=`$MEDIAINFO --Output="Video;%FrameCount%" "$INPUT"`RAWFRAMERATE=`$MEDIAINFO --Output="Video;%FrameRate%" "$INPUT"`FRAMERATE=`printf "%.${2:-0}f" $RAWFRAMERATE`FRAMESKIP=$(( $FRAMECOUNT / $FRAMES ))SPF=$(( $FRAMESKIP / $FRAMERATE ))FRAMEDIR=`basename "$INPUT" .mkv`if [ $DEBUG ]; then echo "Framecount: $FRAMECOUNT" echo "Framerate: $FRAMERATE" echo "Frameskip: $FRAMESKIP" echo "Seconds per frame: $SPF" echo "Framedir: $FRAMEDIR" echo nice -n 5 $FFMPEG -i "$INPUT" -vf fps=1/$SPF "${FRAMEDIR}/frame%04d.png" read -p "Press y to continue, any other key to exit..." confirm case $confirm in [Yy] ) true;; * ) exit;; esacfimkdir "$FRAMEDIR"#echo "$FFMPEG -i \"$INPUT\" -vf select=\"not(mod(n\,$FRAMESKIP))\",setpts=N/TB -r 1 -vframes $FRAMES ${FRAMEDIR}/inputframes%03d.png"#$FFMPEG -i "$INPUT" -vf select="not(mod(n\,$FRAMESKIP))",setpts=N/TB -r 1 -vframes $FRAMES "${FRAMEDIR}/inputframes%03d.png"nice -n 5 $FFMPEG -i "$INPUT" -vf fps=1/$SPF "${FRAMEDIR}/frame%04d.png"