Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # save this as webmize.sh and make it executable. Put it somewhere in $PATH, such as in /usr/local/bin
- # syntax: webmize.sh /path/to/sourcefile.mkv /path/to/targetfile.webm
- sourcefile=$1
- targetfile=$2
- echo -e "Webmize v. 0.1. \n Start time? Format: xx:xx:xx"
- read start
- echo "End time? Format: 00:00:00"
- read end
- startsec=$(date -u -d "$start" +"%s")
- endsec=$(date -u -d "$end" +"%s")
- duration=$(date -u -d "0 $endsec sec - $startsec sec" +"%H:%M:%S")
- durationsec=$(($endsec-$startsec))
- echo "Audio? [Y/n]"
- read audio
- echo "Target size in MB?"
- read targetsize
- if [ -a $targetsize ]; then
- bitrate=1
- else
- # 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.
- bitrate=$(echo "scale=2; ($targetsize/$durationsec)*10" | bc)
- fi
- echo "$bitrate"M
- if [ "$audio" == "n" ]; then
- echo "Encoding without audio"
- 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"
- else
- echo "Encoding with audio."
- ffmpeg -i "$sourcefile" -qmin 0 -qmax 50 -threads 4 -c:v libvpx -crf 8 -b:v "$bitrate"M -ss "$start" -sn -t "$duration" "$targetfile"
- fi
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement