Differences between revisions 11 and 12
Revision 11 as of 2010-09-21 11:40:23
Size: 5269
Editor: SamatJain
Comment: Add MEncoder command
Revision 12 as of 2011-01-05 22:57:51
Size: 5280
Editor: SamatJain
Comment:
Deletions are marked like this. Additions are marked like this.
Line 157: Line 157:
 * [[http://oggconvert.tristanb.net/|OggConvert]]: GNOME-based utility that uses GStreamer and allows easy conversion to Theora, Dirac, and Vorbis  * [[http://oggconvert.tristanb.net/|OggConvert]]: GNOME-based utility that uses GStreamer and enables easy conversion to Theora, Dirac, VP8/WebM, and Vorbis

There is a counterpart for this page at WebM for VP8/WebM.

What are the different ways (Ogg) Theora video can be encoded when using the command-line? There are apparently several different ways, of which I want to try to document here.

MPlayer and YUV

Bernhard Rosenkraenzer provided the following script for encoding Theora via MPlayer. MPlayer is used to output both audio and video into lossless formats (PCM and YUV respectively), which are then fed into the reference Theora encoder. The below script has been modified to run on Debian.

This is probably most suitable for headless servers. Also, MPlayer's output quality is excellent (it also has the most sophisticated output filters), so it may also yield the best-looking output.

   1 #!/bin/sh
   2 # Theora encoder -- encodes any video file playable by mplayer to Theora
   3 # (c) 2003 Ark Linux, written by Bernhard Rosenkraenzer <bero at arklinux.org>
   4 #
   5 # Released under the GNU GPL v2 or if, and only if, the GPL v2 is ruled
   6 # invalid in a court of law, any subsequent version of the GPL.
   7 #
   8 # theora-encoder [-a x] [-A x] [-v x] [-V x] [-o x] [-aa x] [-va x] [-aspect x] file
   9 #       -a      Set audio quality (-1 [worst] to 10 [best])
  10 #       -A      Set audio bitrate (not recommended, use -a instead)
  11 #       -v      Set video quality (0 [worst] to 10 [best])
  12 #       -V      Set video bitrate (not recommended, use -v instead)
  13 #       -o      Set output filename
  14 #       -aa     Pass an argument to the audio decoder [mplayer] unchanged
  15 #       -va     Pass an argument to the video decoder [mplayer] unchanged
  16 #               (e.g. to use mplayer's deinterlacer:
  17 #               theora-encoder -o test.ogg -va -vop -va pp=lb test.avi
  18 #       -aspect Set the aspect ratio of the input file (usually 
  19 #               autodetected)
  20 #       file    input file name
  21 #
  22 ARGS=""
  23 AUDIO=""
  24 VIDEO=""
  25 while [ "`echo $1 |cut -b1`" = "-" ]; do
  26         case $1 in
  27         -a|--audio-quality)
  28                 shift
  29                 ARGS="$ARGS -a $1"
  30                 ;;
  31         -A|--audio-bitrate)
  32                 shift
  33                 ARGS="$ARGS -A $1"
  34                 ;;
  35         -v|--video-quality)
  36                 shift
  37                 ARGS="$ARGS -v $1"
  38                 ;;
  39         -V|--video-bitrate)
  40                 shift
  41                 ARGS="$ARGS -V $1"
  42                 ;;
  43         -o|--output)
  44                 shift
  45                 DEST="$1"
  46                 if [ "`echo $DEST |cut -b1`" != "/" ]; then
  47                         DEST="`pwd`/$DEST"
  48                 fi
  49                 DEST="\"$DEST\""
  50                 ARGS="$ARGS -o $DEST"
  51                 ;;
  52         -aa|--audio-arg)
  53                 # Pass an argument to the audio decoder
  54                 shift
  55                 AUDIO="$AUDIO \"$1\""
  56                 ;;
  57         -va|--video-arg)
  58                 # Pass an argument to the video decoder
  59                 shift
  60                 VIDEO="$VIDEO \"$1\""
  61                 ;;
  62         -aspect)
  63                 # Aspect ratio of input file
  64                 shift
  65                 VIDEO="$VIDEO -aspect \"$1\""
  66                 ;;
  67         *)
  68                 echo "WARNING: Unknown option $1 ignored!" >&2
  69         esac
  70         shift
  71 done
  72 if [ -z "$1" -o "$#" != "1" ]; then
  73         cat >&2 <<EOF
  74 Usage: $0 [-a audioquality|-A audiobitrate] [-v videoquality|-V videobitrate] [-o outputfile] inputfile
  75 EOF
  76         exit 1
  77 fi
  78 SRC="$1"
  79 if [ "`echo $SRC |cut -b1`" != "/" ]; then
  80         SRC="`pwd`/$SRC"
  81 fi
  82 SRC="\"$SRC\""
  83 DIR=`mktemp -d /tmp/theoraXXXXXX`
  84 cat >$DIR/run.sh <<EOF
  85 trap "rm -rf $DIR" 0 1 2 3 4 6 8 9 11 13 15
  86 cd $DIR
  87 mkfifo -m 0600 stream.yuv stream.wav
  88 mplayer -ao pcm:file=stream.wav -vo null -vc null $AUDIO $SRC &>mplayer-audio.log &
  89 mplayer -vo yuv4mpeg -ao null -nosound $VIDEO $SRC &>mplayer-video.log &
  90 theora_encoder_example $ARGS stream.wav stream.yuv
  91 rm -rf $DIR
  92 EOF
  93 chmod +x $DIR/run.sh
  94 exec $DIR/run.sh

MEncoder

MEncoder does not support the Ogg as a container to which you can encode.

However, if you use a different container, recent versions of mencoder (need to find the minimum SVN revision/version) should work with libtheora (given support is compiled in). Something along the lines of should work:

mencoder -ovc lavc -oac lavc -of lavf -lavfopts format=matroska -lavcopts acodec=vorbis:vcodec=libtheora input.avi -o output.mkv

However, this does not appear to work on Debian 6.0 (Squeeze).

ffmpeg2theora

ffmpeg2theora, obviously based on ffmpeg, is another Theora popular encoder.

VLC

VLC can either be used as a GUI encoder, or via the command-line:

   1 vlc foo.avi --sout-theora-quality=5 --sout-vorbis-quality=1 \
   2 --sout="#transcode{vcodec=theo,vb=800,scale=1,deinterlace=0,\
   3 acodec=vorb,ab=128,channels=2,samplerate=44100}:standard{access=file,\
   4 mux=ogg,dst='foo.ogv'}"

Source: How to get your clips on the web

GStreamer

   1 gst-launch-0.10 filesrc location=/path/to/video/file.ext ! decodebin name=dbin dbin. ! queue ! ffmpegcolorspace ! theoraenc quality=32 ! queue ! mux. dbin. ! queue ! audioconvert ! vorbisenc quality=0.2 ! queue ! mux. oggmux name=mux ! progressreport ! filesink location=/output/path.ogv

Source: How to get your clips on the web

Other information

More useful information on these pages:

All-in-one GUI programs:

  • OggConvert: GNOME-based utility that uses GStreamer and enables easy conversion to Theora, Dirac, VP8/WebM, and Vorbis

SamatsWiki: Theora (last edited 2011-01-05 22:57:51 by SamatJain)