1 README for the Dirac video codec
2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 by the BBC R&D Dirac team (diracinfo@rd.bbc.co.uk)
10 Dirac is an open source video codec. It uses a traditional hybrid video codec
11 architecture, but with the wavelet transform instead of the usual block
12 transforms. Motion compensation uses overlapped blocks to reduce block
13 artefacts that would upset the transform coding stage.
15 Dirac can code just about any size of video, from streaming up to HD and
16 beyond, although certain presets are defined for different applications and
17 standards. These cover the parameters that need to be set for the encoder to
18 work, such as block sizes and temporal prediction structures, which must
19 otherwise be set by hand.
21 Dirac is intended to develop into real coding and decoding software, capable
22 of plugging into video processing applications and media players that need
23 compression. It is intended to develop into a simple set of reliable but
24 effective coding tools that work over a wide variety of content and formats,
25 using well-understood compression techniques, in a clear and accessible
26 software structure. It is not intended as a demonstration or reference coder.
32 Documentation can be found at
33 http://diracvideo.org/wiki/index.php/Main_Page#Documentation
35 3. Building and installing
36 ~~~~~~~~~~~~~~~~~~~~~~~~~~
38 GNU/Linux, Unix, MacOS X, Cygwin, Mingw
39 ---------------------------------------
40 ./configure --enable-debug
41 (to enable extra debug compile options)
43 ./configure --enable-profile
44 (to enable the g++ profiling flag -pg)
46 ./configure --disable-mmx
47 (to disable MMX optimisation which is enabled by default)
49 ./configure --enable-debug --enable-profile
50 (to enable extra debug compile options and profiling options)
54 By default, both shared and static libraries are built. To build all-static
56 ./configure --disable-shared
58 To build shared libraries only use
59 ./configure --disable-static
64 The INSTALL file documents arguments to ./configure such as
65 --prefix=/usr/local (specify the installation location prefix).
68 MSYS and Microsoft Visual C++
69 -----------------------------
70 Download and install the no-cost Microsoft Visual C++ 2008 Express
72 http://msdn.microsoft.com/vstudio/express/visualc/
74 Download and install MSYS (the MinGW Minimal SYStem), MSYS-1.0.10.exe,
75 from http://www.mingw.org/download.shtml. An MSYS icon will be available
78 Click on the MSYS icon on the desktop to open a MSYS shell window.
80 Create a .profile file to set up the environment variables required.
83 Include the following four lines in the .profile file.
85 PATH=/c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/Common7/IDE:/c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/VC/BIN:/c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/Common7/Tools:/c/WINDOWS/Microsoft.NET/Framework/v3.5:/c/WINDOWS/Microsoft.NET/Framework/v2.0.50727:/c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/VC/VCPackages:$PATH
87 INCLUDE=/c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/VC/INCLUDE:$INCLUDE
88 LIB=/c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/VC/LIB:$LIB
90 LIBPATH=/c/WINDOWS/Microsoft.NET/Framework/v3.5:/c/WINDOWS/Microsoft.NET/Framework/v2.0.50727:/c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/VC/LIB:$LIBPATH
92 (Replace /c/Program\ Files/Microsoft\ Visual\ Studio\ 9/ with
93 the location where VC++ 2008 is installed if necessary)
95 Exit from the MSYS shell and click on the MSYS icon on the desktop to open
96 a new MSYS shell window for the .profile to take effect.
98 Change directory to the directory where Dirac was unpacked. By default
99 only the dynamic libraries are built.
101 ./configure CXX=cl LD=cl --enable-debug
102 (to enable extra debug compile options)
104 ./configure CXX=cl LD=cl --disable-shared
105 (to build static libraries)
107 ./configure CXX=cl LD=cl
111 The INSTALL file documents arguments to ./configure such as
112 --prefix=/usr/local (specify the installation location prefix).
114 Microsoft Visual C++ .NET 2008
115 ------------------------------
116 Download and install the no-cost Microsoft Visual C++ 2008 Express
118 http://www.microsoft.com/express/download/
120 The MS VC++ 2008 solution and project files are in win32/VisualStudio
121 directory. Double-click on the solution file, dirac.sln, in the
122 win32/VisualStudio directory. The target 'Everything' builds the codec
123 libraries and utilities. Four build-types are supported
125 Debug - builds unoptimised encoder and decoder dlls with debug symbols
126 Release - builds optimised encoder and decoder dlls
127 Debug-mmx - builds unoptimised encoder and decoder dlls with debug symbols
128 and mmx optimisations enabled.
129 Release-mmx - builds optimised encoder and decoder dlls with mmx
130 optimisations enabled.
131 Static-Debug - builds unoptimised encoder and decoder static libraries
133 Static-Release - builds optimised encoder and decoder static libraries
134 Static-Debug-mmx - builds unoptimised encoder and decoder static libraries
135 with debug symbols and mmx optmisations enabled.
136 Static-Release-mmx - builds optimised encoder and decoder static libraries
137 with mmx optmisations enabled.
139 Static libraries are created in the win32/VisualStudio/build/lib/<build-type> directory.
141 Encoder and Decoder dlls and import libraries, encoder and decoder apps are
142 created in the win32/VisualStudio/build/bin/<build-type> directory. The "C"
143 public API is exported using the _declspec(dllexport) mechanism.
145 Conversion utilites are created in the
146 win32/VisualStudio/build/utils/conversion/<build-type> directory. Only static
148 Instrumentation utility is created in the
149 win32/VisualStudio/build/utils/instrumentation/<build-type> directory. Only
150 static versions are built.
153 Older editions of Microsoft Visual C++ (e.g. 2003 and 2005)
154 -----------------------------------------------------------
156 NOTE: Since Visual C++ 2008 Express edition is freely available to
157 download, older versions of the Visual C++ editions are no longer
158 supported. So it is suggested that the users upgrade their VC++ environment
161 4. Running the example programs
162 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164 4.1 Command-line parameters
166 At the moment there is a simple command-line parser class which is
167 used in all the executables. The general procedure for running a program
170 prog_name -<flag_name> flag_val ... param1 param2 ...
172 In other words, options are prefixed by a dash; some options take values,
173 while others are boolean options that enable specific features. For example:
174 When running the encoder, the -qf options requires a numeric argument
175 specifying the "quality factor" for encoding. The -verbose option enables
176 detailed output and does not require an argument.
178 Running any program without arguments will display a list of parameters and
183 The example coder and decoder use raw 8-bit planar YUV data. This means that
184 data is stored bytewise, with a frame of Y followed by a frame of U followed
185 by a frame of V, all scanned in the usual raster order. The video dimensions
186 , frame rate and chroma are passed to the encoder via command line arguments.
188 Other file formats are supported by means of conversion utilities that
189 may be found in the subdirectory util/conversion. These will convert to
190 and from raw RGB format, and support all the standard raw YUV formats as
191 well as bitmaps. Raw RGB can be obtained as an output from standard conversion
192 utilities such as ImageMagick.
195 Compress an image sequence of 100 frames of 352x288 video in tiff format.
199 Use your favourite conversion routine to produce a single raw RGB file of
200 all the data. If your routine converts frame-by-frame then you will
201 need to concatenate the output.
205 Convert from RGB to the YUV format of your choice. For example, to do
208 RGBtoYUV420 <file.rgb >file.yuv 352 288 100
210 Note that this uses stdin and stdout to read and write the data.
212 We have provided a script create_test_data.pl to help convert rgb format
213 files into all the input formats supported by Dirac. The command line
214 arguments it supports can be listed using
216 create_test_data.pl -use
220 create_test_data.pl -width=352 -height=288 -num_frames=100 file.rgb
222 (This assumes that the RGBtoYUV utilities are in a directory specified in
223 PATH variable. If not in the path, then use options -convutildir and to set
224 the directories where the script can find the conversion utilities.)
226 The scripts then outputs files in all chroma formats (420, 422,
227 444) supported by Dirac to the current directory.
232 Run the encoder. This will produce a locally decoded output in the
233 same format if the locally decoded output is enabled using the -local flag.
239 YUV420toRGB <file.yuv >file.rgb 352 288 100
243 Use your favourite conversion utility to convert to the format of your
246 You can also use the transcode utility to convert data to and from Dirac's
247 native formats (see http://zebra.fh-weingarten.de/~transcode/):
249 This example uses a 720x576x50 DV source, and transcodes to 720x576 YUV in
250 4:2:0 chroma format. Cascading codecs (DV + Dirac) is generally a bad idea
251 - use this only if you don't have any other source of uncompressed video.
253 transcode -i source.dv -x auto,null --dv_yuy2_mode -k -V -y raw,null -o file.avi
254 tcextract -i test.avi -x rgb > file.yuv
256 Viewing and playback utilities for uncompressed video include MPlayer and
257 ImageMagick's display command.
259 Continuing the 352x288 4:2:0 example above, to display a single frame
260 of raw YUV with ImageMagick use the following (use <spacebar> to see
263 display -size 352x288 test.yuv
265 Raw YUV 420 data can also be played back in MPlayer - use the following
268 mplayer -fps 15 -rawvideo on:size=152064:w=352:h=288 test.yuv
270 (at the time of writing MPlayer could not playback 4:2:2 or 4:4:4 YUV data)
275 The basic encoding syntax is to type
277 dirac_encoder [options] file_in file_out
279 This will compress file_in and produce an output file_out of compressed data.
281 A locally decoded output file_out.local-dec.yuv and instrumentation data
282 file_out.imt (for debugging the encoder and of interest to developers only)
283 are also produced if the -local flag is enabled on the command line.
285 There are a large number of optional parameters that can be used to run the
286 encoder, all of which are listed below. To encode video you need three types of
287 parameter need to be set:
289 a) quality factor or target bit rate
290 b) source parameters (width, height, frame rate, chroma format)
291 c) encoding parameters (motion compensation block sizes, preferred viewing
294 In practice you don't have to set all these directly because presets can be used
295 to use appropriate default values.
297 a) The most important parameters are the quality factor or target bit rate.
299 The quality factor is specified by using the option
301 qf : Overall quality factor (>0)
303 This value is greater than 0, the higher the number, the better
304 the quality. Typical high quality is 8-10, but it will vary from sequence to
305 sequence, sometimes higher and sometimes lower.
307 The target bit rate is set using the option
309 targetrate : Target bit rate in Kb/s
311 This will attempt to maintain constant bit rate over the sequence. It works
312 reasonably well, but actual bit rate, especially over short sequences, may be
313 slightly different from the target.
315 Setting -targetrate overrides -qf, in that CBR will still be applied, although
316 the initial quality will be set by the given qf value. This might help the CBR
317 algorithm to adapt faster.
319 Setting -lossless overrides both -qf and -targetrate, and enforces lossless
322 b) Source parameters need to be set as the imput is just a raw YUV file and
323 the encoder doesn't have any information about it.
325 The best way to set source parameters is to use a preset for
326 different video formats.
328 The available preset options are:
329 QSIF525 : width=176; height=120; 4:2:0 format; 14.98 frames/sec
330 QCIF : width=176; height=144; 4:2:0 format; 12.5 frames/sec
331 SIF525 : width=352; height=240; 4:2:0 format; 14.98 frames/sec
332 CIF : width=352; height=288; 4:2:0 format; 12.5 frames/sec
333 4SIF525 : width=704; height=480; 4:2:0 format; 14.98 frames/sec
334 4CIF : width=704; height=576; 4:2:0 format; 12.5 frames/sec
335 SD480I60 : width=720; height=480; 4:2:2 format; 29.97 frames/sec
336 SD576I50 : width=720; height=576; 4:2:2 format; 25 frames/sec
337 HD720P60 : width=1280; height=720; 4:2:2 format; 60 frames/sec
338 HD720P50 : width=1280; height=720; 4:2:2 format; 50 frames/sec
339 HD1080I60 : width=1920; height=1080; 4:2:2 format; 29,97 frames/sec
340 HD1080I50 : width=1920; height=1080; 4:2:2 format; 25 frames/sec
341 HD1080P60 : width=1920; height=1080; 4:2:2 format; 59.94 frames/sec
342 HD1080P50 : width=1920; height=1080; 4:2:2 format; 50 frames/sec
343 DC2K24 : width=2048; height=1080; 4:2:2 format; 24 frames/sec
344 DC4K24 : width=4096; height=2160; 4:2:2 format; 24 frames/sec
345 UHDTV4K60 : width=3840; height=2160; 4:2:2 format; 59.94 frames/sec
346 UHDTV4K50 : width=3840; height=2160; 4:2:2 format; 50 frames/sec
347 UHDTV8K60 : width=7680; height=4320; 4:2:2 format; 59.94 frames/sec
348 UHDTV8K50 : width=7680; height=4320; 4:2:2 format; 50 frames/sec
350 The default format used is CUSTOM format which has the following preset values
351 width=640; height=480; 4:2:0 format; 23.97 frames/sec.
353 If your video is not one of these formats, you should pick the nearest preset
354 and override the parameters that are different.
356 Example 1 Simple coding example. Code a 720x576 sequence in Planar 420 format to
361 dirac_encoder -cformat YUV420P -SD576I50 -qf 9 test.yuv test_out.drc
363 Example 2. Code a 720x486 sequence at 29.97 frames/sec in 422 format to
368 dirac_encoder -SD576I50 -width 720 -height 486 -fr 29.97 -cformat YUV422P -qf 5.5 test.yuv test_out.drc
370 Source parameters that affect coding are:
372 width : Width of video frame
373 height : Height of video frame
374 cformat : Chroma Sampling format. Acceptable values are
375 YUV444P, YUV422P and YUV420P.
376 fr : Frame rate. Can be a decimal number or a fraction. Examples
377 of acceptable values are 25, 29.97, 12.5, 30000/1001.
378 source_sampling : Source material type - 0 - progressive or 1 - interlaced
380 For a complete list of source parameters, refer to Annex C of the Dirac
383 WARNING!! If you use a preset but don't override source parameters that
384 are different, then Dirac will still compress, but the bit rate will be
385 much, much higher and there may well be serious artefacts. The encoder prints
386 out the parameters it's actually using before starting encoding (in verbose
387 mode only), so that you can abort at this point.
389 c) The presets ALSO set encoding parameters. That's why it's a very good idea
390 to use presets, as the encoding parameters are a bit obscure. They're still
391 supported for those who want to experiment, but use with care.
393 Encoding parameters are:
395 L1_sep : the separation between L1 frames (frames that are predicted but
396 also used as reference frames, like P frames in MPEG-2)
397 num_L1 : the number of L1 frames before the next intra frame
398 xblen : the width of blocks used for motion compensation
399 yblen : the height of blocks used for motion compensation
400 xbsep : the horizontal separation between blocks. Always <xblen
401 ybsep : the vertical separation between blocks. Always <yblen
402 cpd : normalised viewing distance parameter, in cycles per degree.
403 iwlt_filter : transform filter to use when encoding INTRA frames, Valid
404 values are DD9_7, LEGALL5_3, DD13_7, HAAR0, HAAR1, FIDELITY,
405 DAUB97. Default value is DD9_5.
406 rwlt_filter : transform filter to use when encoding INTER frames, Valid
407 values are DD9_7, LEGALL5_3, DD13_7, HAAR0, HAAR1, FIDELITY,
408 DAUB97. Default value is LEGALL5_3.
409 wlt_depth : transform depth, i.e number of times the component is split
410 while applying the wavelet transform
411 no_spartition : Do not split a subband into coefficient blocks before
413 multi_quants : If subbands are split into multiple coefficient blocks before
414 entropy coding, assign different quantisers to each block
416 prefilter : Prefilter to apply to input video before encoding. The name of
417 the filter to be used and the filter strength have to be
418 supplied. Valid filter names are NO_PF, CWM, RECTLP and
419 DIAGLP. Filter strenth range should be in the range 0-10.
420 (note PSNR statistics will be computed relative to the filtered
421 video if -local is enabled)
422 lossless : Lossless coding.(overrides -qf and -targetrate)
423 mv_prec : Motion vector precision. Valid values are 1 (Pixel precision),
424 1/2 (half-pixel precision), 1/4 (quarter pixel precision which
425 is the default), 1/8 ( Eighth pixel precision).
426 full_search : Use full search motion estimation
427 field_coding : Code the input video as fields instead of frames.
428 Default coding is frames.
429 use_vlc : Use VLC for entropy coding of coefficients instead of arithmetic
431 Modifying L1_sep and num_L1 allows for new GOP structures to be used, and
432 should be entirely safe. There are two non-GOP modes that can also be used for
433 encoding: setting num_L1=0 gives I-frame only coding, and setting L1_sep to
434 1 will do IP-only coding (no B-pictures). P-only coding isn't possible, but
435 num_L1=very large and L1_sep=1 will approximate it.
437 Modifying the block parameters is strongly deprecated: it's likely to break
438 the encoder as there are many constraints. Modifying cpd will not break
439 anything, but will change the way noise is distributed which may be more (or
440 less) suitable for your application. Setting cpd equal zero turns off
441 perceptual weighting altogether.
443 For more information, see the algorithm documentation on the website:
444 http://diracvideo.org/wiki/index.php/Dirac_Algorithm
446 Other options. The encoder also supports some other options, which are
448 verbose : turn on verbosity (if you don't, you won't see the final bitrate!)
449 start : code from this frame number
450 stop : code up until this frame number
451 local : Generate diagnostics and locally decoded output (to avoid running a
452 decoder to see your video)
454 Using -start and -stop allows a small section to be coded, rather than the
457 If the -local flag is present in the command line, the encoder produces
458 diagnostic information about motion vectors that can be used to debug the
459 encoder algorithm. It also produces a locally decoded picture so that you
460 don't have to run the decoder to see what the pictures are like.
464 Decoding is much simpler. Just point the decoder input at the bitstream and the
467 dirac_decoder -verbose test_enc test_dec
469 will decode test_enc into test_dec with running commentary.