summaryrefslogtreecommitdiff
path: root/localvideowebencode
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2014-09-21 13:02:47 +0200
committerJonas Smedegaard <dr@jones.dk>2014-09-21 14:48:51 +0200
commit8cc17063f29c1b91033b3aa7f12561342f1dc801 (patch)
tree936f8d27ffa0e19e46ab85457c98875294e64d6d /localvideowebencode
parent2a69a771bb65230597a2b12574344ebe820c534e (diff)
Add option --formats, and render only WebM and MPEG-4 (not Ogg) by default.
Diffstat (limited to 'localvideowebencode')
-rwxr-xr-xlocalvideowebencode78
1 files changed, 53 insertions, 25 deletions
diff --git a/localvideowebencode b/localvideowebencode
index cd9c5e8..ca1dc6a 100755
--- a/localvideowebencode
+++ b/localvideowebencode
@@ -19,7 +19,6 @@
#
# TODO: offer to skip rendering again if an output file exist already
# TODO: support --width and --height (resolving the other part from input/forced aspect ratio)
-# TODO: support --formats (comma-separated, to allow e.g. excluding webm even if supported)
set -e
@@ -61,6 +60,12 @@ html favoring open formats with optional non-JavaScript Flash fallback.
(default: 0.12)
-b, --bitrate Fixed video bitrate in bytes: e.g. 768k 1M
(default: none - use variable bitrate)
+ --formats Containers and codecs to use (comma-sparated):
+ container video codec audio codec
+ ogg Ogg Theora Vorbis
+ webm WebM VP8 Vorbis
+ mp4 MPEG-4 H.264 AAC
+ (default: webm,mp4)
--h264profile MPEG-4 AVC target profile: baseline main high
(default: baseline)
--h264preset MPEG-4 AVC target preset: slow ultrafast etc.
@@ -113,11 +118,12 @@ exit1() {
}
# defaults
+formats=webm,mp4
h264profile=baseline
samplelength=150
# parse cmdline options
-TEMP="`getopt -s sh -o hp:s:a:r:b:t: -l help,profile:,size:,aspect:,rate:,video:,refbpp:,bitrate:,h264profile:,h264preset:,webmpreset:,audio:,stem:,title:,filter:,sample:: -n "$PRG" -- "$@"`" || exit1 "Internal getopt error."
+TEMP="`getopt -s sh -o hp:s:a:r:b:t: -l help,profile:,size:,aspect:,rate:,video:,refbpp:,bitrate:,formats:,h264profile:,h264preset:,webmpreset:,audio:,stem:,title:,filter:,sample:: -n "$PRG" -- "$@"`" || exit1 "Internal getopt error."
eval set -- "$TEMP"
while true ; do
case "$1" in
@@ -129,6 +135,7 @@ while true ; do
--video) video="$2"; shift 2;;
--refbpp) refbpp="$2"; shift 2;;
-b|--bitrate) bitrate_fixed="$2"; shift 2;;
+ --formats) formats="$2"; shift 2;;
--h264profile) h264profile="$2"; shift 2;;
--h264preset) h264preset="$2"; shift 2;;
--webmpreset) webmpreset="$2"; shift 2;;
@@ -263,6 +270,15 @@ case "$video" in
*) exit1 "Unknown video style \"$video\".";;
esac
+for format in $(echo "$formats" | sed -e 's/,/ /g'); do
+ case $format in
+ ogg) ogg=yes;;
+ mp4) mp4=yes;;
+ webm) webm=yes;;
+ *) exit1 "Unknown format \"$format\".";;
+ esac
+done
+
case "$h264profile" in
baseline|main)
_melt_h264="properties=x264-medium-$h264profile ${h264preset:+-vpre=libx264-$h264preset}"
@@ -351,21 +367,24 @@ if [ -n "$normalize" ] && [ -n "$melt_recent" ] && [ -n "$channels" ]; then
_melt_loudness="$(perl -ne 'm!<property name="results">([^<]+)</property>! and print $1' $stem.xml)"
fi
-## Theora/Vorbis/Ogg
-$melt -group $_melt_in $infiles -group ${channels:+$_melt_audio_filters_early${_melt_loudness:+ -filter loudness results="$_melt_loudness"} $_melt_audio_filters }$filters -consumer avformat:"$stem.ogv" $_melt_ogg $_melt_vorbis $_melt_out
+if [ -n "$ogg" ]; then
+ $melt -group $_melt_in $infiles -group ${channels:+$_melt_audio_filters_early${_melt_loudness:+ -filter loudness results="$_melt_loudness"} $_melt_audio_filters }$filters -consumer avformat:"$stem.ogv" $_melt_ogg $_melt_vorbis $_melt_out
+fi
-## H.264/AAC/MP4
-[ -z "$bitrate_fixed" ] || $melt -group $_melt_in $infiles -group $filters -consumer avformat:/dev/null properties=x264-medium-pass1 $_melt_h264 $_melt_out
-$melt -group $_melt_in $infiles -group ${channels:+$_melt_audio_filters_early${_melt_loudness:+ -filter loudness results="$_melt_loudness"} $_melt_audio_filters }$filters -consumer avformat:"$stem.mp4" ${bitrate_fixed:+pass=2} $_melt_h264 $_melt_aac $_melt_out
-if [ -z "$melt_recent" ]; then
- mv "$stem.mp4" "$stem.mp4"~
- qt-faststart "$stem.mp4"~ "$stem.mp4"
- [ -f "$stem.mp4" ] && rm "$stem.mp4"~ || mv -f "$stem.mp4"~ "$stem.mp4"
+if [ -n "$mp4" ]; then
+ [ -z "$bitrate_fixed" ] || $melt -group $_melt_in $infiles -group $filters -consumer avformat:/dev/null properties=x264-medium-pass1 $_melt_h264 $_melt_out
+ $melt -group $_melt_in $infiles -group ${channels:+$_melt_audio_filters_early${_melt_loudness:+ -filter loudness results="$_melt_loudness"} $_melt_audio_filters }$filters -consumer avformat:"$stem.mp4" ${bitrate_fixed:+pass=2} $_melt_h264 $_melt_aac $_melt_out
+ if [ -z "$melt_recent" ]; then
+ mv "$stem.mp4" "$stem.mp4"~
+ qt-faststart "$stem.mp4"~ "$stem.mp4"
+ [ -f "$stem.mp4" ] && rm "$stem.mp4"~ || mv -f "$stem.mp4"~ "$stem.mp4"
+ fi
fi
-## VP8/Vorbis/WebM
-# TODO: use two-pass when supported by melt
-$melt -group $_melt_in $infiles -group ${channels:+$_melt_audio_filters_early${_melt_loudness:+ -filter loudness results="$_melt_loudness"} $_melt_audio_filters }$filters -consumer avformat:"$stem.webm" properties=webm $_melt_webm $_melt_vorbis $_melt_out
+if [ -n "$webm" ]; then
+ # TODO: use two-pass when supported by melt
+ $melt -group $_melt_in $infiles -group ${channels:+$_melt_audio_filters_early${_melt_loudness:+ -filter loudness results="$_melt_loudness"} $_melt_audio_filters }$filters -consumer avformat:"$stem.webm" properties=webm $_melt_webm $_melt_vorbis $_melt_out
+fi
# cleanup audio normalize hinting
rm -f $stem.xml
@@ -377,26 +396,35 @@ __width="${_width:+ width=\"$_width\"}"
__height="${_height:+ height=\"$_height\"}"
# Flash object needs extra space for controllers
__heightplus=${_height:+ height=\"$(($_height+4))\"}
-
+__ogg=${ogg:+<source src=\"$stem.ogv\" type=\"video/ogg\" />
+}
+__webm=${webm:+<source src=\"$stem.webm\" type=\"video/webm\" />
+}
+__mp4=${mp4:+<source src=\"$stem.mp4\" type=\"video/mp4\" />
+}
# TODO: resolve flash player to use
[ -z "$flashplayer" ] || flash=yes
+[ -n "$mp4" ] || [ -z "$flash" ] || error1 "Cannot enable flash when mp4 format is disabled."
+__flash=${flash:+<object$__width$__heightplus type=\"application/x-shockwave-flash\" data=\"$flashplayer.swf\">
+<param name=\"movie\" value=\"$flashplayer.swf\" />
+<param name=\"flashvars\" value=\"image=$stem.jpg&amp;file=$stem.mp4\" />
+}
+__oggfile=${ogg:+open format <a href=\"$stem.ogv\">Ogg</a>}
+__webmfile=${webm:+open format <a href=\"$stem.webm\">WebM</a>}
+__mp4file=${mp4:+closed Format <a href=\"$stem.mp4\">MPEG-4</a>}
+[ -z "$webm" ] || [ -z "$ogg$mp4" ] || webm_and_more=yes
+[ -z "$ogg" ] || [ -z "$mp4" ] || ogg_and_mp4=yes
cat >"$stem.html" <<EOF
<!-- Video for Everybody, Kroc Camen of Camen Design -->
<video$__width$__height preload controls>
-<source src="$stem.mp4" type="video/mp4" />
-<source src="$stem.webm" type="video/webm" />
-<source src="$stem.ogv" type="video/ogg" />
-${flash:+<object$__width$__heightplus type="application/x-shockwave-flash" data="$flashplayer.swf">
-<param name="movie" value="$flashplayer.swf" />
-<param name="flashvars" value="image=$stem.jpg&amp;file=$stem.mp4" />
-}<img src="$stem.jpg"$__width$__height alt="$title"
+$__mp4$__webm$__ogg$__flash<img src="$stem.jpg"$__width$__height alt="$title"
title="No video playback capabilities, please download the video below" />
${flash:+</object>
}</video>
<p><strong>Download Video:</strong>
-open format <a href="$stem.webm">WebM</a>,
-open format <a href="$stem.ogv">Ogg</a>,
-closed Format <a href="$stem.mp4">MPEG-4</a>.
+$__webmfile${webm_and_more:+,
+}$__oggfile${ogg_and_mp4:+,
+}$__mp4file.
</p>
EOF