crashhacker

auto_collage.sh

Dec 26th, 2021 (edited)
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #-------------AUTO COLLAGE by CRASH----------------
  4. #creates a folder with full resolution and low resolution thumbnails (9 each) & makes a full resolution collage along with low resolution collage images.
  5. #USAGE : ./auto_collage.sh film.mkv
  6.  
  7. #package requirements
  8. #install ffmpeg (which should install ffprobe) & imagemagick using the following command in *buntu
  9. #sudo apt install ffmpeg* imagemagick* -y
  10.  
  11. if [ -z "$1" ]; then
  12. echo "You have to specify a video file"
  13. exit 1
  14. fi
  15.  
  16. video="$1"
  17. NUMBEROFSCREENS=9
  18. FOLDER=Auto_Thumbnails
  19. DURATION=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$video")
  20. #DURATION=$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$video")
  21. if [ $DURATION !$x "N/A" ]; then
  22. DURATION=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$video")
  23. fi
  24. if [ -z $DURATION ] || [ $DURATION == "N/A" ]; then
  25. echo "Could not get video duration"
  26. exit 1
  27. fi
  28. DURATION=${DURATION%.*}
  29. mkdir $FOLDER
  30. echo "===================================================================="
  31. echo "Generating screens for $video (duration: $DURATION)"
  32.  
  33.  
  34. for ((n=1;n<$(($NUMBEROFSCREENS + 1));n++)); do
  35. SECONDS=$(( $DURATION / $NUMBEROFSCREENS * $n ))
  36. SECONDS=$((SECONDS<DURATION-10?SECONDS:DURATION-10))
  37.  
  38. FRAMENAME="$FOLDER/auto_thumbnail_$(printf '%03d' ${n}).png"
  39. ORIG_FRAMENAME="$FOLDER/orig_thumbnail_$(printf '%03d' ${n}).png"
  40. MINUTES=$(( SECONDS / 60 ))
  41. TRAILSECONDS=$(( SECONDS % 60 ))
  42. TIMECODE=$(printf "%02d\:%02d" ${MINUTES} ${TRAILSECONDS})
  43.  
  44. BLACKCHECK="X"
  45. while [ "$BLACKCHECK" != "" ]; do
  46.   echo "Getting image #$n  ($SECONDS/$DURATION) seconds"
  47.  
  48. #Low Resolution Thumbnail
  49. BLACKCHECK=$(ffmpeg -y -ss $SECONDS -i "$video" -vframes 1 -vf "scale=360:ow/dar, blackframe=90:80, drawtext=text='$TIMECODE': fontcolor=white: fontsize=10: box=1: [email protected]: boxborderw=5: x=w-text_w-15: y=15" $FRAMENAME 2>&1 | grep blackframe)
  50.  
  51. #Full Resolution Thumbnail
  52. BLACKCHECK=$(ffmpeg -y -ss $SECONDS -i "$video" -vframes 1 -vf "blackframe=90:80, drawtext=text='$TIMECODE': fontcolor=white: fontsize=20: box=1: [email protected]: boxborderw=5: x=w-text_w-15: y=15" $ORIG_FRAMENAME 2>&1     | grep blackframe)
  53.   ((SECONDS==DURATION-10)) && break;
  54.   SECONDS=$(( SECONDS + 1 ))
  55. done
  56. done
  57.  
  58. OUTPUTFILE=AutoCollage_lowres.${video}.png
  59. OUTPUTFILE2=AutoCollage_highres.${video}.png
  60. montage $FOLDER/auto* -interlace Plane -background black -tile 3x -geometry +4+4 -border 5 "$OUTPUTFILE"
  61. montage $FOLDER/orig* -interlace Plane -background black -tile 3x -geometry +4+4 -border 5 "$OUTPUTFILE2"
  62. #rm -r $FOLDER
  63.  
Add Comment
Please, Sign In to add comment