SHARE
TWEET

Untitled

julian_hughes Mar 20th, 2013 207 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # videothumbs, a simple videothumbnailer
  3. #
  4. #  Copyright (C) 2012 Julian Hughes julianhughes<at>gmailDOTcom
  5. #
  6. #  This program is free software; you can redistribute it and/or modify
  7. #  it under the terms of the GNU General Public License as published by
  8. #  the Free Software Foundation; either version 3 of the License, or
  9. #  (at your option) any later version.
  10. #
  11. #  This program is distributed in the hope that it will be useful,
  12. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #  GNU General Public License for more details.
  15. #
  16. #  You should have received a copy of the GNU General Public License
  17. #  along with this program.  If not, see <http://www.gnu.org/licenses/>
  18.  
  19. #check mplayer, ffmpeg, imagemagick are installed
  20. type montage >/dev/null 2>&1 || { echo >&2 "ImageMagick is not \
  21. installed or is not in your path."; exit 1; }
  22. type mplayer >/dev/null 2>&1 || { echo >&2 "mplayer is not installed \
  23. or is not in your path."; exit 1; }
  24. type ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg is not installed \
  25. or is not in your path."; exit 1; }
  26.  
  27. #user options
  28. while getopts 'o:' OPTION
  29. do
  30.         case $OPTION in
  31.         o)      oflag=1
  32.                 oval=$OPTARG
  33.                 ;;
  34.         esac
  35. done
  36. shift $(($OPTIND-1))
  37.  
  38. function ffscreens ()
  39. {
  40. for t in {1..40}; do ffmpeg -ss $(($t*$STEP)) -i "$i" -f image2 \
  41. -vframes 1  -vf scale="$WIDE":"$H" "$OUT"/$(printf "%02d\n" "$t").png
  42. done
  43. }
  44.  
  45. for i in "$@" ;do
  46.  
  47. FILE="${i%.*}"
  48. FILE="${FILE##*/}"
  49. EXT="${i##*\.}"
  50. OUT=/tmp/thumbs
  51. INFO="$OUT"/info
  52.  
  53. mkdir -p "$OUT"
  54.  
  55. #set output destination. Output dir exists and writable?
  56. #defaults to movie directory.
  57. if [ $oflag ]; then
  58.         if [ ! -d "$oval" -o ! -w "$oval" ]; then
  59.         printf "\n\n\tOutput directory is not writable or doesn't exist\n\n"
  60.         exit
  61.         fi
  62.         IMGOUT=$oval/"${FILE##*/}".jpg
  63.         else
  64.         IMGOUT="${i%.*}".jpg
  65. fi
  66.  
  67. #dump movie info to text file
  68. mplayer "$i" -noconfig all -identify -vo null -ao null \
  69. -frames 0 2>/dev/null |grep -E -e AUDIO -e "VIDEO|LENGTH" |\
  70. awk -F "ID_" '{print $2}'|sort -u |sed '/^$/d' >"$INFO"
  71.  
  72. #for 4x10 images find movie length, divide by 40 for interval steps.
  73. LENGTH=$(grep LENGTH= "$INFO"|awk -F = '{print $2}')
  74. STEP="$(echo $LENGTH/40 |bc)"
  75.  
  76. #images should show correct aspect for anamorphic video, so find height
  77. #and aspect ratio and calculate displayed width, rounded to integer.
  78. A=$(grep VIDEO_ASPECT= "$INFO"  |awk -F = '{print $2}')
  79. H=$(grep VIDEO_HEIGHT= "$INFO" |awk -F = '{print $2}')
  80. WIDE="$(echo $A*$H |bc)"
  81. WIDE=$(printf "%.0f\n" $WIDE)
  82.  
  83. #get basic codec and dimension info for printing title.
  84. W=$(grep VIDEO_WIDTH= "$INFO" |awk -F = '{print $2}')
  85. VIDEO=$(grep VIDEO_FORMAT= "$INFO" |awk -F = '{print $2}')
  86. AUDIO=$(grep AUDIO_CODEC= "$INFO" |awk -F = '{print $2}')
  87. CHAN=$(grep -m 1 AUDIO_NCH= "$INFO" |awk -F = '{print $2}')
  88. TITLE="\n\n""${i##*/}""\nVideo: "$VIDEO", "$W"x"$H"\nAudio: "$AUDIO", \
  89. "$CHAN" Channels"
  90.  
  91. #dump uncompressed png images to temp dir while redirecting overly
  92. #verbose ffmpeg output to /dev/null
  93. ffscreens>/dev/null 2>&1
  94.  
  95. #make montage, clean up, quit.
  96. montage -mode concatenate -geometry 252x -border 1 -tile 4x \
  97. "$OUT"/*.png -title "$TITLE" "$IMGOUT" && \
  98. rm -rf "$OUT"
  99.  
  100. done
  101. exit 0
RAW Paste Data
Top