Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # videothumbs, a simple videothumbnailer
- #
- # Copyright (C) 2012 Julian Hughes julianhughes<at>gmailDOTcom
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>
- #check mplayer, ffmpeg, imagemagick are installed
- type montage >/dev/null 2>&1 || { echo >&2 "ImageMagick is not \
- installed or is not in your path."; exit 1; }
- type mplayer >/dev/null 2>&1 || { echo >&2 "mplayer is not installed \
- or is not in your path."; exit 1; }
- type ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg is not installed \
- or is not in your path."; exit 1; }
- #user options
- while getopts 'o:' OPTION
- do
- case $OPTION in
- o) oflag=1
- oval=$OPTARG
- ;;
- esac
- done
- shift $(($OPTIND-1))
- function ffscreens ()
- {
- for t in {1..40}; do ffmpeg -ss $(($t*$STEP)) -i "$i" -f image2 \
- -vframes 1 -vf scale="$WIDE":"$H" "$OUT"/$(printf "%02d\n" "$t").png
- done
- }
- for i in "$@" ;do
- FILE="${i%.*}"
- FILE="${FILE##*/}"
- EXT="${i##*\.}"
- OUT=/tmp/thumbs
- INFO="$OUT"/info
- mkdir -p "$OUT"
- #set output destination. Output dir exists and writable?
- #defaults to movie directory.
- if [ $oflag ]; then
- if [ ! -d "$oval" -o ! -w "$oval" ]; then
- printf "\n\n\tOutput directory is not writable or doesn't exist\n\n"
- exit
- fi
- IMGOUT=$oval/"${FILE##*/}".jpg
- else
- IMGOUT="${i%.*}".jpg
- fi
- #dump movie info to text file
- mplayer "$i" -noconfig all -identify -vo null -ao null \
- -frames 0 2>/dev/null |grep -E -e AUDIO -e "VIDEO|LENGTH" |\
- awk -F "ID_" '{print $2}'|sort -u |sed '/^$/d' >"$INFO"
- #for 4x10 images find movie length, divide by 40 for interval steps.
- LENGTH=$(grep LENGTH= "$INFO"|awk -F = '{print $2}')
- STEP="$(echo $LENGTH/40 |bc)"
- #images should show correct aspect for anamorphic video, so find height
- #and aspect ratio and calculate displayed width, rounded to integer.
- A=$(grep VIDEO_ASPECT= "$INFO" |awk -F = '{print $2}')
- H=$(grep VIDEO_HEIGHT= "$INFO" |awk -F = '{print $2}')
- WIDE="$(echo $A*$H |bc)"
- WIDE=$(printf "%.0f\n" $WIDE)
- #get basic codec and dimension info for printing title.
- W=$(grep VIDEO_WIDTH= "$INFO" |awk -F = '{print $2}')
- VIDEO=$(grep VIDEO_FORMAT= "$INFO" |awk -F = '{print $2}')
- AUDIO=$(grep AUDIO_CODEC= "$INFO" |awk -F = '{print $2}')
- CHAN=$(grep -m 1 AUDIO_NCH= "$INFO" |awk -F = '{print $2}')
- TITLE="\n\n""${i##*/}""\nVideo: "$VIDEO", "$W"x"$H"\nAudio: "$AUDIO", \
- "$CHAN" Channels"
- #dump uncompressed png images to temp dir while redirecting overly
- #verbose ffmpeg output to /dev/null
- ffscreens>/dev/null 2>&1
- #make montage, clean up, quit.
- montage -mode concatenate -geometry 252x -border 1 -tile 4x \
- "$OUT"/*.png -title "$TITLE" "$IMGOUT" && \
- rm -rf "$OUT"
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement