summaryrefslogtreecommitdiff
path: root/localvideowebencode
blob: 5b4d4297502875163e1c1ae536ea667e2f192935 (plain)
  1. #!/bin/sh
  2. # Origins:
  3. # http://diveintohtml5.org/video.html
  4. # http://camendesign.com/code/video_for_everybody
  5. set -e
  6. # input filename (mandatory)
  7. infile="$1"; shift
  8. filebase=$(echo "$infile" | perl -pe 's/\.[^.]*//')
  9. # output size in WIDTHxHEIGHT (optional, default: 320x200)
  10. size=${1:-320x200}
  11. width=$(echo "$size" | perl -pe 's/[^x]*x//')
  12. height=$(echo "$size" | perl -pe 's/x[^x]*//')
  13. heightplus=${height:+$(($height+4))}
  14. ## Theora/Vorbis/Ogg
  15. ffmpeg2theora --videobitrate 200 --max_size "$size" --output "$filebase.ogv" "$infile"
  16. ## H.264/AAC/MP4
  17. HandBrakeCLI --preset "iPhone & iPod Touch" --vb 200 ${width:+--maxWidth "$width"} ${height:+--maxHeight "$height"} --two-pass --turbo --optimize --input "$infile" --output "$filebase.mp4"
  18. ## VP8/Vorbis/WebM
  19. ! ffmpeg -codecs | grep -iw vp8 || webm=yes
  20. [ -z "$webm" ] || ffmpeg -pass 1 -passlogfile "$infile" -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i "$infile" -vcodec libvpx -b 204800 -s "$size" -aspect 4:3 -an -f webm -y NUL
  21. [ -z "$webm" ] || ffmpeg -pass 2 -passlogfile "$infile" -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i "$infile" -vcodec libvpx -b 204800 -s "$size" -aspect 4:3 -acodec libvorbis -ac 2 -y "$filebase.webm"
  22. ## JPEG preview
  23. ffmpegthumbnailer -s0 -i "$filebase.ogv" -o "$filebase.jpg"
  24. ## TODO: resolve flash player to use
  25. [ -z "$flashplayer" ] || flash=yes
  26. cat >"$filebase.html" <<EOF
  27. <!-- Video for Everybody, Kroc Camen of Camen Design -->
  28. <video width="$width" height="$height" preload controls>
  29. <source src="$filebase.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
  30. <source src="$filebase.ogv" type='video/ogg; codecs="theora, vorbis"' />
  31. ${webm:+<source src="$filebase.webm" type='video/webm; codecs="vp8, vorbis"' />
  32. }${flash:+<object width="$width" height="$heightplus" type="application/x-shockwave-flash" data="$flashplayer.swf">
  33. <param name="movie" value="$flashplayer.swf" />
  34. <param name="flashvars" value="image=$filebase.jpg&amp;file=$filebase.mp4" />
  35. }<img src="$filebase.jpg" width="$width" height="$height" ${title:+alt="$title"}
  36. title="No video playback capabilities, please download the video below" />
  37. ${flash:+</object>
  38. }</video>
  39. <p><strong>Download Video:</strong>
  40. open classic Format:<a href="$filebase.ogv">"Ogg"</a>,
  41. ${webm:+open modern Format:<a href="$filebase.webm">"WebM"</a>,}
  42. closed Format:<a href="$filebase.mp4">"MP4"</a>.
  43. </p>
  44. EOF