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