Encode Big Buck Bunny
From DiracWiki
Contents |
[edit] Introduction
This example shows a complete start-to-finish encoding setup for a real piece of source material. The uncompressed audio and video for Big Buck Bunny may be downloaded from http://media.xiph.org/BBB. Note that for the 640x360 resolution source video you need to download over 3Gbytes of data.
[edit] Source material
The source material for Big Buck Bunny is a sequence of PNG images, which for the purpose of Dirac encoding will be converted to 4:2:0 YUV video. Losslessly compressed audio files in FLAC format are also provided, and can be transcoded into a compressed format suitable for the various container formats.
[edit] Container formats
The encoded video will be wrapped both in OGG and MPEG transport stream containers for maximum compatibility with player applications.
[edit] Prerequisites
- The fluendo transport stream multiplexer GStreamer plugin
- A recent version of the Schroedinger GStreamer plugin, compiled from the GIT source
- The dirac command line encoder is required.
To play back,
- The fluendo transport stream demultiplexer GStreamer plugin
[edit] Makefiles
This is a makefile to encode and wrap the source media. A makefile is used because the video encoding can take a long time, but the wrapping is quick, so the encoding is only done once prior to multiple wrappings.
The makefile first generates the subsampled I420 video from the source PNGs, then uses both the dirac command line encoder and the schroenc gstreamer element to produce a coded bitstream from each encoder.
The wrapping stage incorporates transcoding the audio from FLAC to MPEG1-layer2 and Vorbis, depending uopon the container.
You will need to edit the makefile to specify the location of your source video and dirac encoder binary.
Usage:
make big_buck_bunny.dirac.ogg make big_buck_bunny.dirac.ts make big_buck_bunny.schro.ogg make big_buck_bunny.schro.ts make big_buck_bunny.lossless.drc
If you do not have the dirac encoder binary build, don't run the dirac.* commands. The coding via schroedinger will still work.
Makefile:
SHELL=/bin/bash
VINPUT=/video/originals/BBB/media.xiph.org/BBB/BBB-360-short-png/big_buck_bunny_%05d.png
WIDTH=640
HEIGHT=360
FRAMERATE=24/1
PAR=1/1
FIRSTINDEX=1
AINPUT=/video/originals/BBB/media.xiph.org/BBB/BigBuckBunny-stereo.flac
VIDEOPARSEOPTS=format=0 \
width=$(WIDTH) \
height=$(HEIGHT) \
framerate=$(FRAMERATE)
pixel-aspect-ratio=$(PAR)
DIRACENC=dirac_encoder
DIRACOPTS=-HD720P50 \
-fr $(FRAMERATE) \
-cformat YUV420P \
-width $(WIDTH) \
-height $(HEIGHT) \
-targetrate 1000 \
-mv_prec 1/4 \
-prefilter DIAGLP 3 \
-verbose \
-local
SCHROOPTS= rate-control=1 \
bitrate=1000000
.PRECIOUS: %.i420 %.drc %.schro.drc %.dirac.drc %.lossless.drc
.PHONY: all
all: big_buck_bunny.dirac.ogg \
big_buck_bunny.dirac.ts \
big_buck_bunny.dirac.avi \
big_buck_bunny.schro.ogg \
big_buck_bunny.schro.ts \
big_buck_bunny.schro.avi \
big_buck_bunny.lossless.drc \
include makerules.dirac
[edit] Makerules
The makefile includes the following rules file which contains the rules for format conversion, encoding and multiplexing.
#
# Make Rules for various dirac encoding and multiplexing operations
#
#generate single i420 file contining frames from the original PNGs
%.i420:
gst-launch multifilesrc location=$(VINPUT) index=$(FIRSTINDEX) \
caps="image/png,framerate=$(FRAMERATE)" ! \
pngdec ! \
ffmpegcolorspace ! \
video/x-raw-yuv,format=\(fourcc\)I420 ! \
filesink location=$@
#encode the i420 file to a .drc using the dirac encoder
%.dirac.drc: %.i420
$(DIRACENC) $(DIRACOPTS) $< $@ 1>$@.diracenc.log
#encode the i420 file to a .drc using the schro encoder:
%.schro.drc: %.i420
gst-launch filesrc location=$< ! \
videoparse $(VIDEOPARSEOPTS) ! \
schroenc $(SCHROOPTS) ! \
filesink location=$@
#encode the i420 file losslessly using the schro encoder
%.lossless.drc: %.i420
gst-launch filesrc location=$< ! \
videoparse $(VIDEOPARSEOPTS) ! \
schroenc rate-control=3 enable-noarith=true ! \
filesink location=$@
#encode the i420 file directly with schro and output to ogg avoiding schroparse
%.noparse.ogg: %.i420
gst-launch oggmux name=mux ! filesink location=$@ \
filesrc location=$< ! \
videoparse $(VIDEOPARSEOPTS) ! \
schroenc $(SCHROOPTS) ! \
queue ! \
mux.
#multiplex the .drc and audio into an OGG container
%.ogg: %.drc $(AINPUT)
gst-launch oggmux name=mux ! filesink location=$@ \
filesrc location=$< ! \
schroparse ! \
queue ! \
mux. \
filesrc location=$(AINPUT) ! \
flacdec ! \
audioconvert ! \
vorbisenc ! \
queue ! \
mux.
#multiplex the .drc and audio into a mpeg transport stream container
%.ts: %.drc $(AINPUT)
gst-launch flutsmux name=mux ! filesink location=$@ \
filesrc location=$< ! \
schroparse ! \
queue ! \
mux. \
filesrc location=$(AINPUT) ! \
flacdec ! \
audioconvert ! \
ffenc_mp2 ! \
queue ! \
mux.
#multiplex the .drc and audio into an AVI container
%.avi: %.drc $(AINPUT)
gst-launch avimux name=mux ! filesink location=$@ \
filesrc location=$< ! \
schroparse ! \
queue ! \
mux. \
filesrc location=$(AINPUT) ! \
flacdec ! \
audioconvert ! \
lame ! \
queue ! \
mux.
