Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
- cat << EOF
- hitomi script
- easily converts part of a video to gif or webm using ffmpeg.
- first give permission to execute:
- chmod +x hitomi.sh
- USAGE:
- ./hitomi.sh start end input_file output_file
- examples:
- ./hitomi.sh 00:12:32 00:15:21 boku_no_pico.mkv boku_no_pico.gif
- ./hitomi.sh 00:03:52.373 00:04:11.532 umaru.mp4 ebina.webm
- "The one with the sharper fangs wins. That's what Killing Bites is."
- EOF
- exit 0
- fi
- if [ $# -ne 4 ]; then
- echo "I need 4 arguments."
- echo "type ./hitomi.sh -h or --help, for more information."
- echo
- exit 1
- fi
- START="$1"
- END="$2"
- FILE="$3"
- OUTPUT="$4"
- CUTTED=a."$FILE" #still don't know how to rename files in ffmpeg :(
- ffmpeg -ss "$START" -i "$FILE" -to "$END" -c copy -copyts -an -sn "$CUTTED"
- if echo "$OUTPUT" | grep ".gif"
- then
- #blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
- #ffmpeg.org/ffmpeg-filters.html#palettegen
- filters="fps=8,scale=320:-1:flags=lanczos"
- ffmpeg -i "$CUTTED" -vf "$filters,palettegen" -y palette.png
- ffmpeg -i "$CUTTED" -i palette.png -lavfi "$filters [x]; [x][1:v] paletteuse" -gifflags +transdiff -y "$OUTPUT"
- rm palette.png
- elif echo "$OUTPUT" | grep ".webm"
- then
- #trac.ffmpeg.org/wiki/Encode/VP9
- ffmpeg -i "$CUTTED" -c:v libvpx -b:v 600k -pass 1 -speed 4 -f webm "$PWD/null"
- ffmpeg -i "$CUTTED" -c:v libvpx -b:v 600k -pass 2 -speed 1 -vf scale=640:-1 "$OUTPUT"
- rm ffmpeg2pass-0.log "$PWD/null"
- else
- echo "something went wrong"
- echo "type ./hitomi.sh -h or --help, for more information."
- echo
- exit 1
- fi
- rm "$CUTTED"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement