summaryrefslogtreecommitdiff
path: root/localvideowebencode
blob: 7aaca47c52a9177b439d9012fe5be672a1bc94a2 (plain)
  1. #!/bin/sh
  2. # Origins:
  3. # http://diveintohtml5.org/video.html
  4. # http://camendesign.com/code/video_for_everybody
  5. # Possible flashplayers:
  6. # http://www.internetmarketingnotes.com/2010/07/free-embeddable-flash-video-flv-players-for-commercial-use/
  7. set -e
  8. # input filename (mandatory)
  9. infile="$1"; shift
  10. filebase=$(echo "$infile" | perl -pe 's/\.[^.]*//')
  11. # output size in WIDTHxHEIGHT (mandatory)
  12. # TODO: Make optional with input size as default
  13. # TODO: Make each half of size optional with default resolved from input aspect ratio
  14. size="$1"; shift
  15. width=$(echo "$size" | perl -pe 's/[^x]*x//')
  16. height=$(echo "$size" | perl -pe 's/x[^x]*//')
  17. heightplus=${height:+$(($height+4))}
  18. # fallback graphics title
  19. # TODO: implement --title option (set it in environment for now)
  20. title=${title:-$filebase}
  21. # TODO: Check and fail if all needed tools are not available
  22. ## Theora/Vorbis/Ogg
  23. ffmpeg2theora --videobitrate 200 --max_size "$size" --output "$filebase.ogv" "$infile"
  24. ## H.264/AAC/MP4
  25. HandBrakeCLI --preset "iPhone & iPod Touch" --vb 200 ${width:+--maxWidth "$width"} ${height:+--maxHeight "$height"} --two-pass --turbo --optimize --input "$infile" --output "$filebase.mp4"
  26. ## VP8/Vorbis/WebM
  27. ! ffmpeg -codecs | grep -iw vp8 || webm=yes
  28. # FIXME: check and fail if logfiles exist already
  29. [ -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
  30. [ -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"
  31. rm "$infile"-*.log
  32. ## JPEG preview
  33. ffmpegthumbnailer -s0 -i "$filebase.ogv" -o "$filebase.jpg"
  34. # TODO: resolve flash player to use
  35. [ -z "$flashplayer" ] || flash=yes
  36. cat >"$filebase.html" <<EOF
  37. <!-- Video for Everybody, Kroc Camen of Camen Design -->
  38. <video width="$width" height="$height" preload controls>
  39. <source src="$filebase.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
  40. <source src="$filebase.ogv" type='video/ogg; codecs="theora, vorbis"' />
  41. ${webm:+<source src="$filebase.webm" type='video/webm; codecs="vp8, vorbis"' />
  42. }${flash:+<object width="$width" height="$heightplus" type="application/x-shockwave-flash" data="$flashplayer.swf">
  43. <param name="movie" value="$flashplayer.swf" />
  44. <param name="flashvars" value="image=$filebase.jpg&amp;file=$filebase.mp4" />
  45. }<img src="$filebase.jpg" width="$width" height="$height" alt="$title"
  46. title="No video playback capabilities, please download the video below" />
  47. ${flash:+</object>
  48. }</video>
  49. <p><strong>Download Video:</strong>
  50. open format <a href="$filebase.ogv">Ogg</a>,
  51. ${webm:+open format <a href="$filebase.webm">WebM</a>,}
  52. closed Format <a href="$filebase.mp4">MP4</a>.
  53. </p>
  54. EOF