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