summaryrefslogtreecommitdiff
path: root/localvideowebencode
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2011-09-21 02:15:30 +0200
committerJonas Smedegaard <dr@jones.dk>2011-09-21 02:15:30 +0200
commit64b73b8e379fed144731a1cbce561e69e8bb1da2 (patch)
tree87fd1514c43268a4e1f5480705f3dcc9b02896d1 /localvideowebencode
parentd2d9a90f4535a31bcd762c56680d8c7579be5eca (diff)
Use melt (not ffmpeg).
Diffstat (limited to 'localvideowebencode')
-rwxr-xr-xlocalvideowebencode128
1 files changed, 50 insertions, 78 deletions
diff --git a/localvideowebencode b/localvideowebencode
index 6c5b043..1d1564c 100755
--- a/localvideowebencode
+++ b/localvideowebencode
@@ -11,10 +11,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)
-# TODO: use (openshot and) melt:
-# * melt -consumer avformat:outfile.webm properties=consumer/avformat/webm infile.xml
-# * melt -consumer avformat:outfile.x264 properties=consumer/avformat/x264-medium-baseline infile.xml
-# * melt -consumer avformat:outfile.ogg f=ogg vcodec=libtheora b=1120k acodec=libvorbis aq=25 infile.xml
# TODO: add --speech option, using mono, lower audio rate, and (when solved how) speex
set -e
@@ -23,29 +19,46 @@ PRG=$(basename "$0")
showhelp() {
cat <<EOF
-Usage: $PRG --size SIZE [--profile PROFILE] [--title TITLE] INPUTFILE
+Usage: $PRG [OPTION...] [--] INPUTFILE [INPUTFILE...]
Encode video file in multiple web-optimized formats, and provide sample
html favoring open formats with optional non-JavaScript Flash fallback.
-s, --size Output size in WIDTHxHEIGHT or ffmpeg
abbreviation like vga qvga qcif hd480 etc.
(default: use input size)
- -p, --profile Quality profile (lo, hi, lowide, hiwide)
- (default: lo)
+ -a, --aspect Display Aspect Ratio in melt format e.g. @16/9
+ (default: no aspect hinting)
+ -b, --bitrate Bitrate in bytes, optionally ISO appreviated
+ (default: 768k)
+ -p, --profile Melt profile like square_ntsc quarter_pal_wide
+ qcif_15 etc.
+ (default: none - reuse input profile)
+ --h264profile MPEG-4 AVC target profile (baseline medium)
+ (default: baseline)
-t, --title Title used in html fallback graphics
- (default: basename of input file)
+ (default: basename of first input file)
-h, --help This help text
Examples:
- $PRG -s qvga -t "Funny guy" myvideo.dv
- $PRG -p hiwide -s hd480 -t "Funny guy" myvideo.dv
+ $PRG -s qvga -t "Funny guy" myvideo.dv outro.dv
+ $PRG -p sdi_486i_5994 -s hd480 -t "Funny guy" myvideo.dv
-Profile "lo" (default) is optimal for 320x240 (qvga).
-Profile "hi" is optimal for 640x240 (vga) content.
+If multiple input files are provided, they are merged together and
+output files are named based on first input file.
-NB! Old iPod has 640x480 limit, so use 640x360 (not hd480) with hiwide.
+Default options are optimal for 320x240 (qvga) and similar.
+Suggested bitrates:
-More info: <http://camendesign.com/code/video_for_everybody>
+ 320x240 (qvga): 768k
+ 640x480 (vga): 1120k
+
+NB! Old iPod require baseline encoding and has 640x480 size limit.
+Use e.g. quarter_ntsc_wide, svcd_ntsc_wide or svcd_pal_wide (varying in
+framerate and Pixel Aspect Ratio) for widescreen material.
+
+More info: <http://camendesign.com/code/video_for_everybody>
+ <http://www.streaminglearningcenter.com/>
+ <http://en.wikipedia.org/wiki/HTML5_video>
EOF
}
@@ -55,14 +68,21 @@ exit1() {
exit 1
}
+# defaults
+bitrate=768k
+h264profile=baseline
+
# parse cmdline options
-TEMP="`getopt -s sh -o hs:p:t: -l help,size:,profile:,title: -n "$PRG" -- "$@"`" || exit1 "Internal getopt error."
+TEMP="`getopt -s sh -o hs:a:b:p:t: -l help,size:,aspect:,bitrate:,profile:,h264profile,title: -n "$PRG" -- "$@"`" || exit1 "Internal getopt error."
eval set -- "$TEMP"
while true ; do
case "$1" in
-h|--help) showhelp; exit;;
-s|--size) size="$2"; shift 2;;
+ -a|--aspect) aspect="$2"; shift 2;;
+ -b|--bitrate) bitrate="$2"; shift 2;;
-p|--profile) profile="$2"; shift 2;;
+ --h264profile) h264profile="$2"; shift 2;;
-t|--title) title="$2"; shift 2;;
--) shift; break;;
*) exit1 "Internal error resolving options.";;
@@ -74,88 +94,40 @@ if [ $# -eq 0 ]; then
exit1 "Too few parameters!"
fi
-if [ $# -gt 1 ]; then
- showhelp
- exit1 "Too many parameters!"
-fi
-
# input filename (mandatory)
-infile="$1"; shift
+infile="$1"
[ -e "$infile" ] || exit1 "Input file missing!"
filebase=$(echo "$infile" | perl -pe 's/\.[^.]*//')
-# fallback profile
-profile=${profile:-lo}
-case "$profile" in
- lo)
- bitrate=768
- aspect=4:3
- ;;
- lowide)
- bitrate=768
- aspect=16:9
- ;;
- hi)
- bitrate=1120
- aspect=4:3
- ;;
- hiwide)
- bitrate=1120
- aspect=16:9
- ;;
-esac
-
# fallback graphics title
title=${title:-$filebase}
# TODO: Check and fail if all needed tools are not available
-_ffmpeg() {
- passes="$1"; shift
- ext="$1"; shift
- [ ! -f "$filebase.$ext" ] || exit1 "output file \"$filebase.$ext\" already exist. Remove it and try again."
- case $passes in
- 0)
- ffmpeg -i "$infile" $opts "$@" -f "$ext" -y "$filebase.$ext"
- ;;
- 1)
- [ ! -f "$filebase"-*.log ] || exit1 "logfiles already exist. Remove them (or wait for that other process to complete) and try again."
- ffmpeg -i "$infile" -pass 1 -passlogfile "$filebase" "$@" -an -f "$ext" -y /dev/null
- ;;
- 2)
- [ -f "$filebase"-*.log ] || exit1 "logfiles missing. Pass 2 cannot succeed without a prior pass 1."
- ffmpeg -i "$infile" -pass 2 -passlogfile "$filebase" "$@" -y "$filebase.$ext"
- rm "$filebase"-*.log
- case $ext in
- mp4)
- mv "$filebase.$ext" "$filebase.$ext"~
- qt-faststart "$filebase.$ext"~ "$filebase.$ext"
- [ -f "$filebase.$ext" ] && rm "$filebase.$ext"~ || exit1 "failed to optimize with qt-faststart."
- ;;
- esac
- ;;
- esac
-}
+# TODO: When verified beneficial, add option real_time=-2
+opts_common="${bitrate:+b=${bitrate}} ${size:+s=$size} ${aspect:+aspect=$aspect}"
+opts_audio="ac=2 ar=44100 ab=96k"
-opts_common="-threads 0 -b ${bitrate}k ${size:+-s $size} ${aspect:+-aspect $aspect}"
-opts_audio="-ac 2 -ar 44100 -ab 96k"
-opts_webm="-vcodec libvpx -keyint_min 0 -g 250 -skip_threshold 0"
+# bail out (before any expensive tasks) if logfiles exists
+[ ! -f x264-*.log* ] || exit1 "logfiles already exist. Remove them (or wait for that other process using them to complete) and try again."
## Theora/Vorbis/Ogg
-_ffmpeg 0 ogg $opts_common -vcodec libtheora -acodec libvorbis $opts_audio
+melt -consumer avformat:"$filebase.ogg" f=ogg vcodec=libtheora $opts_common acodec=libvorbis aq=25 $opts_audio "$@"
## H.264/AAC/MP4
-_ffmpeg 1 mp4 $opts_common -vcodec libx264 -vpre medium_firstpass -vpre baseline
-_ffmpeg 2 mp4 $opts_common -vcodec libx264 -vpre medium -vpre baseline -acodec libvo_aacenc $opts_audio
+melt -consumer avformat:/dev/null f=mp4 properties=x264-medium-$h264profile $opts_common pass=1 an=1 fastfirstpass=1 "$@"
+melt -consumer avformat:"$filebase.mp4" properties=x264-medium-$h264profile $opts_common pass=2 acodec=libvo_aacenc $opts_audio "$@"
+mv "$filebase.mp4" "$filebase.mp4"~
+qt-faststart "$filebase.mp4"~ "$filebase.mp4"
+[ -f "$filebase.mp4" ] && rm "$filebase.mp4"~ || exit1 "failed to optimize with qt-faststart."
## VP8/Vorbis/WebM
-! ffmpeg -codecs | grep -iw vp8 || webm=yes
-[ -z "$webm" ] || _ffmpeg 1 webm $opts_common $opts_webm
-[ -z "$webm" ] || _ffmpeg 2 webm $opts_common $opts_webm -acodec libvorbis $opts_audio
+# TODO: use two-pass when supported by melt
+melt -consumer avformat:"$filebase.webm" properties=webm $opts_common $opts_audio "$@"
## JPEG preview
-ffmpegthumbnailer -s0 -i "$filebase.ogg" -o "$filebase.jpg"
+ffmpegthumbnailer -s0 -i "$filebase.mp4" -o "$filebase.jpg"
# resolve width and height from preview image
size=$(jpeginfo "$filebase.jpg" | perl -ane 'print "$F[1]x$F[3]"')