Advertisement
Guest User

Скринлист генератор

a guest
Oct 16th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.36 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo 'Чтобы сделать скринлисты для группы файлов:'
  4. echo '1) скопируйте этот скрипт в каталог с файлами;'
  5. echo '2) зайдите в консоли в этот каталог;'
  6. echo '3) запустите, такой скрипт:'
  7. echo '   for i in *.mp4; do ./generate\ thumbs.sh "$i"; done'
  8.  
  9. # Скрипт взят отюда: https://www.binpress.com/tutorial/how-to-generate-video-previews-with-ffmpeg/138
  10. # внесены небольшие изменения
  11.  
  12. if [ -z "$1" ]; then
  13.     echo "usage: ./movie_preview.sh VIDEO [HEIGHT=120] [COLS=5] [ROWS=10] [OUTPUT]"
  14.     exit
  15. fi
  16.  
  17. MOVIE=$1
  18. HEIGHT=$2
  19. COLS=$3
  20. ROWS=$4
  21. OUT_FILENAME=$5
  22.  
  23. # get video name without the path and extension
  24. MOVIE_NAME=`basename $MOVIE`
  25. OUT_DIR=`pwd`
  26.  
  27. if [ -z "$HEIGHT" ]; then
  28.     HEIGHT=160
  29. fi
  30. if [ -z "$COLS" ]; then
  31.     COLS=4
  32. fi
  33. if [ -z "$ROWS" ]; then
  34.     ROWS=10
  35. fi
  36. if [ -z "$OUT_FILENAME" ]; then
  37.     OUT_FILENAME=`echo ${MOVIE}.jpg`
  38. fi
  39.  
  40. OUT_FILEPATH=`echo $OUT_DIR/$OUT_FILENAME`
  41.  
  42. TOTAL_IMAGES=`echo "$COLS*$ROWS" | bc`
  43.  
  44. # get total number of frames in the video
  45. # ffprobe is fast but not 100% reliable. It might not detect number of frames correctly!
  46. NB_FRAMES=`ffprobe -show_streams "$MOVIE" 2> /dev/null | grep nb_frames | head -n1 | sed 's/.*=//'`
  47.  
  48. if [ "$NB_FRAMES" = "N/A" ]; then
  49.     # as a fallback we'll use ffmpeg. This command basically copies this
  50.     # video to /dev/null and it counts frames in the process.
  51.     # It's slower (few seconds usually) than ffprobe but works everytime.
  52.     NB_FRAMES=`ffmpeg -nostats -i "$MOVIE" -vcodec copy -f rawvideo -y /dev/null 2>&1 | grep frame | awk '{split($0,a,"fps")}END{print a[1]}' | sed 's/.*= *//'`
  53. fi
  54.  
  55. # calculate offset between two screenshots, drop the floating point part
  56. NTH_FRAME=`echo "$NB_FRAMES/$TOTAL_IMAGES" | bc`
  57. echo "capture every ${NTH_FRAME}th frame out of $NB_FRAMES frames"
  58.  
  59. # make sure output dir exists
  60. mkdir -p $OUT_DIR
  61.  
  62. FFMPEG_CMD="ffmpeg -loglevel panic -i \"$MOVIE\" -y -frames 1 -q:v 1 -vf \"select=not(mod(n\,$NTH_FRAME)),scale=-1:${HEIGHT},tile=${COLS}x${ROWS}:padding=5:margin=10:color=0xFFFFFFFF\" \"$OUT_FILEPATH\""
  63. CONVERT_CMD="convert '$OUT_FILEPATH' -splice 0x20 -gravity NorthWest -pointsize 20 -annotate +5+5 '$MOVIE' '$OUT_FILEPATH'"
  64. eval $FFMPEG_CMD
  65. eval $CONVERT_CMD
  66. echo $OUT_FILEPATH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement