Advertisement
Guest User

hitomi

a guest
Mar 16th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.70 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  4.     cat << EOF
  5.  
  6.     hitomi script
  7.     easily converts part of a video to gif or webm using ffmpeg.
  8.    
  9.     first give permission to execute:
  10.     chmod +x hitomi.sh
  11.  
  12.     USAGE:
  13.     ./hitomi.sh start end input_file output_file
  14.  
  15.     examples:
  16.     ./hitomi.sh 00:12:32 00:15:21 boku_no_pico.mkv boku_no_pico.gif
  17.     ./hitomi.sh 00:03:52.373 00:04:11.532 umaru.mp4 ebina.webm
  18.  
  19. "The one with the sharper fangs wins. That's what Killing Bites is."
  20.  
  21. EOF
  22.     exit 0
  23. fi
  24.  
  25. if [ $# -ne 4 ]; then
  26.     echo "I need 4 arguments."
  27.     echo "type ./hitomi.sh -h or --help, for more information."
  28.     echo
  29.     exit 1
  30. fi
  31.  
  32. START="$1"
  33. END="$2"
  34. FILE="$3"
  35. OUTPUT="$4"
  36. CUTTED=a."$FILE" #still don't know how to rename files in ffmpeg :(
  37.  
  38. ffmpeg -ss "$START" -i "$FILE" -to "$END" -c copy -copyts -an -sn "$CUTTED"
  39.  
  40. if echo "$OUTPUT" | grep ".gif"
  41. then
  42.  
  43. #blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
  44. #ffmpeg.org/ffmpeg-filters.html#palettegen
  45.  
  46.     filters="fps=8,scale=320:-1:flags=lanczos"
  47.     ffmpeg -i "$CUTTED" -vf "$filters,palettegen" -y palette.png
  48.     ffmpeg -i "$CUTTED" -i palette.png -lavfi "$filters [x]; [x][1:v] paletteuse" -gifflags +transdiff -y "$OUTPUT"
  49.     rm palette.png
  50.  
  51. elif echo "$OUTPUT" | grep ".webm"
  52. then
  53.  
  54. #trac.ffmpeg.org/wiki/Encode/VP9
  55.  
  56.     ffmpeg -i "$CUTTED" -c:v libvpx -b:v 600k -pass 1 -speed 4 -f webm "$PWD/null"
  57.     ffmpeg -i "$CUTTED" -c:v libvpx -b:v 600k -pass 2 -speed 1 -vf scale=640:-1 "$OUTPUT"
  58.     rm ffmpeg2pass-0.log "$PWD/null"
  59.  
  60. else
  61.     echo "something went wrong"
  62.     echo "type ./hitomi.sh -h or --help, for more information."
  63.     echo
  64.     exit 1
  65. fi
  66.  
  67. rm "$CUTTED"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement