summaryrefslogtreecommitdiff
path: root/localvideowebencode
blob: cb4b2e10367c0b9e16943db6a5f21c42d5fe51fe (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. exit1() {
  9. response="${1:+Error: }${1:-Internal error!}"
  10. echo >&2 "$response"
  11. exit 1
  12. }
  13. PRG=$(basename "$0")
  14. # parse cmdline options
  15. TEMP="`getopt -s sh -o s:t: -l size:,title: -n "$PRG" -- "$@"`" || exit1 "Internal getopt error."
  16. eval set -- "$TEMP"
  17. while true ; do
  18. case "$1" in
  19. -s|--size) size="$2"; shift 2;;
  20. -t|--title) title="$2"; shift 2;;
  21. --) shift; break;;
  22. *) exit1 "Internal error resolving options.";;
  23. esac
  24. done
  25. # input filename (mandatory)
  26. infile="$1"; shift || exit1 "Input file missing!"
  27. filebase=$(echo "$infile" | perl -pe 's/\.[^.]*//')
  28. # output size in WIDTHxHEIGHT (mandatory)
  29. # TODO: Make optional with input size as default
  30. # TODO: Make each half of size optional with default resolved from input aspect ratio
  31. [ -n "$size" ] || exit1 "Unknown output size!"
  32. width=$(echo "$size" | perl -pe 's/[^x]*x//')
  33. height=$(echo "$size" | perl -pe 's/x[^x]*//')
  34. heightplus=${height:+$(($height+4))}
  35. # fallback graphics title
  36. title=${title:-$filebase}
  37. # TODO: Check and fail if all needed tools are not available
  38. ## Theora/Vorbis/Ogg
  39. ffmpeg2theora --videobitrate 200 --max_size "$size" --output "$filebase.ogv" "$infile"
  40. ## H.264/AAC/MP4
  41. HandBrakeCLI --preset "iPhone & iPod Touch" --vb 200 ${width:+--maxWidth "$width"} ${height:+--maxHeight "$height"} --two-pass --turbo --optimize --input "$infile" --output "$filebase.mp4"
  42. ## VP8/Vorbis/WebM
  43. ! ffmpeg -codecs | grep -iw vp8 || webm=yes
  44. # FIXME: check and fail if logfiles exist already
  45. [ -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
  46. [ -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"
  47. rm "$infile"-*.log
  48. ## JPEG preview
  49. ffmpegthumbnailer -s0 -i "$filebase.ogv" -o "$filebase.jpg"
  50. # TODO: resolve flash player to use
  51. [ -z "$flashplayer" ] || flash=yes
  52. cat >"$filebase.html" <<EOF
  53. <!-- Video for Everybody, Kroc Camen of Camen Design -->
  54. <video width="$width" height="$height" preload controls>
  55. <source src="$filebase.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
  56. <source src="$filebase.ogv" type='video/ogg; codecs="theora, vorbis"' />
  57. ${webm:+<source src="$filebase.webm" type='video/webm; codecs="vp8, vorbis"' />
  58. }${flash:+<object width="$width" height="$heightplus" type="application/x-shockwave-flash" data="$flashplayer.swf">
  59. <param name="movie" value="$flashplayer.swf" />
  60. <param name="flashvars" value="image=$filebase.jpg&amp;file=$filebase.mp4" />
  61. }<img src="$filebase.jpg" width="$width" height="$height" alt="$title"
  62. title="No video playback capabilities, please download the video below" />
  63. ${flash:+</object>
  64. }</video>
  65. <p><strong>Download Video:</strong>
  66. open format <a href="$filebase.ogv">Ogg</a>,
  67. ${webm:+open format <a href="$filebase.webm">WebM</a>,}
  68. closed Format <a href="$filebase.mp4">MP4</a>.
  69. </p>
  70. EOF