Advertisement
Guest User

webmize.sh

a guest
Nov 15th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. # save this as webmize.sh and make it executable. Put it somewhere in $PATH, such as in /usr/local/bin
  3. # syntax: webmize.sh /path/to/sourcefile.mkv /path/to/targetfile.webm
  4. sourcefile=$1
  5. targetfile=$2
  6. echo -e "Webmize v. 0.1. \n Start time? Format: xx:xx:xx"
  7. read start
  8. echo "End time? Format: 00:00:00"
  9. read end
  10. startsec=$(date -u -d "$start" +"%s")
  11. endsec=$(date -u -d "$end" +"%s")
  12. duration=$(date -u -d "0 $endsec sec - $startsec sec" +"%H:%M:%S")
  13. durationsec=$(($endsec-$startsec))
  14. echo "Audio? [Y/n]"
  15. read audio
  16. echo "Target size in MB?"
  17. read targetsize
  18. if [ -a $targetsize ]; then
  19.         bitrate=1
  20.     else
  21.         # tweak the coefficient up or down from 10 to tune this until you get output files as close as possible to your target size. 10 tends to lowball a bit, which makes it easier to avoid hitting the filesize limit.
  22.         bitrate=$(echo "scale=2; ($targetsize/$durationsec)*10" | bc)
  23. fi
  24. echo "$bitrate"M
  25. if [ "$audio" == "n" ]; then
  26.         echo "Encoding without audio"
  27. ffmpeg -i "$sourcefile" -qmin 0 -qmax 50 -threads 4 -c:v libvpx -crf 8 -b:v "$bitrate"M -ss "$start" -an -sn -t "$duration" "$targetfile"
  28.     else
  29.         echo "Encoding with audio."
  30. ffmpeg -i "$sourcefile" -qmin 0 -qmax 50 -threads 4 -c:v libvpx -crf 8 -b:v "$bitrate"M -ss "$start" -sn -t "$duration" "$targetfile"
  31. fi
  32. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement