Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # /dbt/'s super awesome webm conversion script for bash v.1.0
- #
- # Just call $ bash ./webm.sh <source file>, supply basic info and boom, you get
- # the converted webm in the subfolder ./webm!
- # Alternatively, copy this to any directory in your PATH, make it executable
- # and just call it by its name.
- # See bottom of file for example terminal session.
- #
- # Limited choices for faster work.
- # Resolution can be chosen freely out of three options (1280x720, 960x540 and
- # 640x360) because it depends on source file frame rate.
- # File size limits were chosen with some safety margin in mind; you can edit
- # them if you want however (lines 52 and 56 -> maxsize).
- #
- # Choosing resolution:
- # Start at 960x540. Convert. Does your webm look like shit or stutter? Go DOWN
- # to 640x360, bitrate might be too low for this resolution. Is your webm way
- # below the size limit? Go up to 1280x720.
- # Rule of thumb for 30 fps video:
- # up to 10 seconds -> 720p
- # up to 30 seconds -> 540p
- # over 30 seconds -> 360p
- # If your webm is really long and exceeds the size limit, lower the resolution.
- # A certain minimum bitrate is required so you likely won't be able to keep a
- # 30 second 720p webm under 3 MB.
- # get user input && calculate secondary params
- echo "output file name"
- read output
- echo "start time (hh:mm:ss.t)"
- read start
- echo "duration (seconds[.decimals])"
- read duration
- echo "y-resolution {720, 540, 360}"
- read v_res
- if [ "$v_res" = "720" ]; then
- h_res="1280"
- elif [ "$v_res" = "540" ]; then
- h_res="960"
- elif [ "$v_res" = "360" ]; then
- h_res="640"
- else
- echo "invalid resolution"
- exit
- fi
- echo "audio? [y|N]"
- read audio
- if [ "$audio" = "y" ]; then
- audiocmd="-c:a libvorbis -b:a 192K -vbr on"
- maxsize=3800
- else
- audio="N"
- audiocmd="-an"
- maxsize=3000
- fi
- bitrate=$(echo "(8*$maxsize/$duration)" | bc)
- # write user params into logfile
- echo "converting $1:" >> ./webm_log.txt
- echo "-----------------------" >> ./webm_log.txt
- echo "start: $start" >> ./webm_log.txt
- echo "duration: $duration s" >> ./webm_log.txt
- echo "max bitrate: $bitrate kbps" >> ./webm_log.txt
- echo "output file: ./webm/$output.webm" >> ./webm_log.txt
- echo "resolution: $h_res x $v_res" >> ./webm_log.txt
- echo "audio: $audiocmd" >> ./webm_log.txt
- echo "" >> ./webm_log.txt
- # write user params into stdout
- echo
- echo "converting $1:"
- echo "-----------------------"
- echo "start: $start"
- echo "duration: $duration s"
- echo "max bitrate: $bitrate kbps"
- echo "output file: ./webm/$output.webm"
- echo "resolution: $h_res x $v_res"
- echo "audio: $audiocmd"
- echo
- echo "Press [Enter] to start converting!"
- read confirm
- # first pass
- echo "ffmpeg -hide_banner -loglevel \"info\" -y -ss \"$start\" -t \"$duration\" -i \"$1\" -c:v libvpx -pass 1 -qmin 0 -qmax 50 -crf 10 -b:v 1M -threads 3 -speed 4 -g 128 -an -sn -f webm \"/dev/null\""
- ffmpeg -hide_banner -loglevel "info" -y -ss "$start" -t "$duration" -i "$1" -c:v libvpx -pass 1 -qmin 0 -qmax 50 -crf 10 -b:v 1M -threads 3 -speed 4 -g 128 -an -sn -f webm "/dev/null"
- # second pass
- mkdir "./webm"
- echo "ffmpeg -hide_banner -loglevel \"info\" -ss \"$start\" -t \"$duration\" -i \"$1\" -c:v libvpx -pass 2 -qmin 0 -qmax 50 -crf 10 -b:v \"$bitrate\" -s \"$h_res:$v_res\" $audiocmd -threads 3 -speed 0 -auto-alt-ref 1 -lag-in-frames 25 -g 128 -sn -f webm \"./webm/$output.webm\""
- ffmpeg -hide_banner -loglevel "info" -ss "$start" -t "$duration" -i "$1" -c:v libvpx -pass 2 -qmin 0 -qmax 50 -crf 10 -b:v "$bitrate"k -s "$h_res:$v_res" $audiocmd -threads 3 -speed 0 -auto-alt-ref 1 -lag-in-frames 25 -g 128 -sn -f webm "./webm/$output.webm"
- # cleanup
- rm ffmpeg2pass-0.log
- # Example terminal session, assuming this file and the video source are stored
- # in ~/Videos:
- #
- #kkb@xubuntu:~$ cd Videos && ll
- #total 1770580
- #drwxr-xr-x 3 kkb kkb 4096 Sep 16 19:21 ./
- #drwx------ 33 kkb kkb 12288 Sep 16 18:33 ../
- #-rw-rw-r-- 1 kkb kkb 1148006607 Aug 5 2015 Steel Panther 2015 08 03 West Hollywood, CA, USA House of Blues Webcast 720p-GNNedc13ENs.webm
- #-rw-rw-r-- 1 kkb kkb 664883790 Jun 12 23:34 Steel Panther - Live from Lexxi’s Mom’s Garage DVD (Full Concert)-FXXcvntSlmY.mkv
- #drwxrwxr-x 3 kkb kkb 28672 Sep 16 19:21 webm/
- #-rw-rw-r-- 1 kkb kkb 64366 Sep 10 22:26 webm.png
- #-rw-rw-r-- 1 kkb kkb 3612 Sep 16 18:31 webm.sh
- #-rw------- 1 kkb kkb 11284 Sep 15 23:29 webm.txt
- #kkb@xubuntu:~/Videos$ bash ./webm.sh "Steel Panther - Live from Lexxi’s Mom’s Garage DVD (Full Concert)-FXXcvntSlmY.mkv"
- #output file name
- #steel_panther
- #start time (hh:mm:ss.t)
- #00:10:10
- #duration (seconds[.decimals])
- #10
- #y-resolution {720, 540, 360}
- #720
- #audio? [y|N]
- #y
- #
- #converting Steel Panther - Live from Lexxi’s Mom’s Garage DVD (Full Concert)-FXXcvntSlmY.mkv:
- #-----------------------
- #start: 00:10:10
- #duration: 10 s
- #max bitrate: 3040 kbps
- #output file: ./webm/steel_panther.webm
- #resolution: 1280 x 720
- #audio: -c:a libvorbis -b:a 192K -vbr on
- #
- #Press [Enter] to start converting!
- #
- #ffmpeg -hide_banner -loglevel "info" -y -ss "00:10:10" -t "10" -i "Steel Panther - Live from Lexxi’s Mom’s Garage DVD (Full Concert)-FXXcvntSlmY.mkv" -c:v libvpx -pass 1 -qmin 0 -qmax 50 -crf 10 -b:v 1M -threads 3 -speed 4 -g 128 -an -sn -f webm "/dev/null"
- # <ffmpeg output>
- #mkdir: cannot create directory ‘./webm’: File exists
- #ffmpeg -hide_banner -loglevel "info" -ss "00:10:10" -t "10" -i "Steel Panther - Live from Lexxi’s Mom’s Garage DVD (Full Concert)-FXXcvntSlmY.mkv" -c:v libvpx -pass 2 -qmin 0 -qmax 50 -crf 10 -b:v "3040" -s "1280:720" -c:a libvorbis -b:a 192K -vbr on -threads 3 -speed 0 -auto-alt-ref 1 -lag-in-frames 25 -g 128 -sn -f webm "./webm/steel_panther.webm"
- # <ffmpeg output>
- #kkb@xubuntu:~/Videos$ mpv ./webm/steel_panther.webm
- # <mpv output>
- #kkb@xubuntu:~/Videos$ exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement