Ogg/Theora vs x264 for HTML5 <VIDEO> tag
- April 26th, 2010
- Write comment
Greg Maxwell at Xiph.org has a great article where he compares Ogg/Theora to x264 video at YouTube video sizes and bit rates. My goal here is to provide a step by step guide to reproduce Greg Maxwell’s results so you can prove it for yourself. Greg outlined the following steps which we will reproduce using a fresh installation of Ubuntu Karmic 9.10 i386.
- Obtain the lossless 640×360 Big Buck Bunny source PNGs and FLACs from media.xiph.org.
- Resample the images to 480×270 using ImageMagick’s convert utility.
- Use gstreamer’s jpegenc, produce a quality=100 mjpeg + PCM audio stream. The result is around 1.5Gbytes with a bitrate of around 20Mbit/sec.
- Truncate the file to fit under the YouTube 1Gbyte limit, resulting in input_mjpeg.avi (706MiB).
- Upload the file to YouTube and wait for it to transcode.
- Download the FLV and H.264 files produced by YouTube using one of the many web downloading services. (I used KeepVid)
- Using libtheora 1.1a2 and Vorbis aoTuv 5.7 produce a file of comparable bitrate to the youtube 499kbit/sec from the same file uploaded to YouTube (input_mjpeg.avi).
- Resample the file uploaded to YouTube to 400×226.
- Using libtheora 1.1a2 and Vorbis aoTuv 5.7 produce a file of comparable bitrate to the youtube 327kbit/sec from the 400×226 downsampled copy of input_mjpeg.avi
Step 1 – Prepare the Environment:
- Install Ubuntu 9.10 Karmic and install all available updates.
- Download BBB-360-png.tar and BigBuckBunny-stereo.flac from one of the following locations and save to your Desktop:
http://media.xiph.org/BBB/BigBuckBunny-stereo.flac
http://gregfaust.net/files/BigBuckBunny-stereo.flac
http://media.xiph.org/BBB/BBB-360-png.tar
http://gregfaust.net/files/BBB-360-png.tar - Install the packages we will need: sudo apt get install vorbis-tools imagemagick gstreamer-tools mplayer-nogui automake libtool
- Extract and prepare the files for encoding:
cd Desktoptar -xvf BBB-360-png.tarmkdir BBB-270-png
mkdir BBB-226-png
cd BBB-360-png
ls *.png | xargs -I FILE convert FILE -resize 480×270\! ../BBB-270-png/FILE
ls *.png | xargs -I FILE convert FILE -resize 400×226\! ../BBB-226-png/FILE
cd ../BBB-270-png
gst-launch multifilesrc location=big_buck_bunny_%05d.png index=1 caps=”image/png,framerate=24/1″ ! pngdec ! ffmpegcolorspace ! jpegenc quality=100 ! queue ! mux. filesrc location=../BigBuckBunny-stereo.flac ! flacdec ! audioconvert ! audioresample ! queue ! mux. avimux name=mux ! filesink location=input270_mjpeg.avi
cd ../BBB-226-png
gst-launch multifilesrc location=big_buck_bunny_%05d.png index=1 caps=”image/png,framerate=24/1″ ! pngdec ! ffmpegcolorspace ! jpegenc quality=100 ! queue ! mux. filesrc location=../BigBuckBunny-stereo.flac ! flacdec ! audioconvert ! audioresample ! queue ! mux. avimux name=mux ! filesink location=input226_mjpeg.avi
cd ..
mplayer input1_mjpeg.avi -ao pcm -vo yuv4mpeg
mv stream.yuv stream1.yuv
mplayer input2_mjpeg.avi -ao pcm -vo yuv4mpeg
mv stream.yuv stream2.yuv
- The libtheora reference encoder accepts (lossless) yuv4mpeg video and PCM audio. The yuv4mpeg video we are supplying was created from a lossy .avi source (mjpeg quality=100) because YouTube does not accept lossless input and this is as close as we can get to lossless. To be fair we are starting with the same lossy input for libtheora, but if we were doing this for real, we would want to go convert directly from png to yuv4mpeg and skip the step where we convert to mjpeg. Note that we are using the reference Vorbis encoder for simplicity and not the tuned AoTuV Vorbis encoder (which in my opinion is better), maybe I’ll do another blog post on AoTuV in the future. cd libtheora/examples
./encoder_example –output ../../output1_theora.ogv -A64 -V345 –two-pass –keyframe-freq 250 ../../stream1.yuv ../../audiodump.wav ./encoder_example –output ../../output2_theora.ogv -A64 -V261 –two-pass –keyframe-freq 250 ../../stream2.yuv ../../audiodump.wav - Now you have a file named output1_theora.ogv which contains 480×270 video at approx 499kbit/sec and audio at 64kbit/sec. You will also have a file named output2_theora.ogv which contains 400×226 video at approx 325kbit/sec and audio at 64kbit/sec. In my opinion, this renders better video and audio quality than YouTube. To compare you YouTuve, you will need to have a YouTube account and upload the files input1_mjpeg.avi and intput2_mjpeg.avi.UPDATE: It looks like Google may open source the On2 VP8 codec it acquired along with On2 in February. An open source VP8 could eliminate concerns about H.264 licensing and Theora quality.









