1 \input texinfo @c -*- texinfo -*-
3 @settitle FFmpeg Documentation
6 @center @titlefont{FFmpeg Documentation}
13 FFmpeg is a very fast video and audio converter. It can also grab from
14 a live audio/video source.
16 The command line interface is designed to be intuitive, in the sense
17 that FFmpeg tries to figure out all parameters that can possibly be
18 derived automatically. You usually only have to specify the target
21 FFmpeg can also convert from any sample rate to any other, and resize
22 video on the fly with a high quality polyphase filter.
27 @section Video and Audio grabbing
29 FFmpeg can use a video4linux compatible video source and any Open Sound
36 Note that you must activate the right video source and channel before
37 launching FFmpeg with any TV viewer such as xawtv
38 (@url{http://bytesex.org/xawtv/}) by Gerd Knorr. You also
39 have to set the audio recording levels correctly with a
42 @section Video and Audio file format conversion
44 * FFmpeg can use any supported file format and protocol as input:
48 * You can use YUV files as input:
51 ffmpeg -i /tmp/test%d.Y /tmp/out.mpg
54 It will use the files:
56 /tmp/test0.Y, /tmp/test0.U, /tmp/test0.V,
57 /tmp/test1.Y, /tmp/test1.U, /tmp/test1.V, etc...
60 The Y files use twice the resolution of the U and V files. They are
61 raw files, without header. They can be generated by all decent video
62 decoders. You must specify the size of the image with the @option{-s} option
63 if FFmpeg cannot guess it.
65 * You can input from a raw YUV420P file:
68 ffmpeg -i /tmp/test.yuv /tmp/out.avi
71 test.yuv is a file containing raw YUV planar data. Each frame is composed
72 of the Y plane followed by the U and V planes at half vertical and
73 horizontal resolution.
75 * You can output to a raw YUV420P file:
78 ffmpeg -i mydivx.avi hugefile.yuv
81 * You can set several input files and output files:
84 ffmpeg -i /tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg
87 Converts the audio file a.wav and the raw YUV video file a.yuv
90 * You can also do audio and video conversions at the same time:
93 ffmpeg -i /tmp/a.wav -ar 22050 /tmp/a.mp2
96 Converts a.wav to MPEG audio at 22050Hz sample rate.
98 * You can encode to several formats at the same time and define a
99 mapping from input stream to output streams:
102 ffmpeg -i /tmp/a.wav -ab 64 /tmp/a.mp2 -ab 128 /tmp/b.mp2 -map 0:0 -map 0:0
105 Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map
106 file:index' specifies which input stream is used for each output
107 stream, in the order of the definition of output streams.
109 * You can transcode decrypted VOBs
112 ffmpeg -i snatch_1.vob -f avi -vcodec mpeg4 -b 800 -g 300 -bf 2 -acodec mp3 -ab 128 snatch.avi
115 This is a typical DVD ripping example; the input is a VOB file, the
116 output an AVI file with MPEG-4 video and MP3 audio. Note that in this
117 command we use B-frames so the MPEG-4 stream is DivX5 compatible, and
118 GOP size is 300 which means one intra frame every 10 seconds for 29.97fps
119 input video. Furthermore, the audio stream is MP3-encoded so you need
120 to enable LAME support by passing @code{--enable-mp3lame} to configure.
121 The mapping is particularly useful for DVD transcoding
122 to get the desired audio language.
124 NOTE: To see the supported input formats, use @code{ffmpeg -formats}.
131 The generic syntax is:
134 @c man begin SYNOPSIS
135 ffmpeg [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}...
138 @c man begin DESCRIPTION
139 If no input file is given, audio/video grabbing is done.
141 As a general rule, options are applied to the next specified
142 file. For example, if you give the @option{-b 64} option, it sets the video
143 bitrate of the next file. The format option may be needed for raw input
146 By default, FFmpeg tries to convert as losslessly as possible: It
147 uses the same audio and video parameters for the outputs as the one
148 specified for the inputs.
152 @section Main options
162 Show available formats, codecs, protocols, ...
171 Overwrite output files.
174 Set the recording time in seconds.
175 @code{hh:mm:ss[.xxx]} syntax is also supported.
178 Seek to given time position in seconds.
179 @code{hh:mm:ss[.xxx]} syntax is also supported.
187 @item -copyright string
190 @item -comment string
194 Specify target file type ("vcd", "svcd", "dvd", "dv", "pal-vcd",
195 "ntsc-svcd", ... ). All the format options (bitrate, codecs,
196 buffer sizes) are then set automatically. You can just type:
199 ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
202 Nevertheless you can specify additional options as long as you know
203 they do not conflict with the standard, as in:
206 ffmpeg -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg
210 Activate high quality settings.
212 @item -itsoffset offset
213 Set the input time offset in seconds.
214 @code{[-]hh:mm:ss[.xxx]} syntax is also supported.
215 This option affects all the input files that follow it.
216 The offset is added to the timestamps of the input files.
217 Specifying a positive offset means that the corresponding
218 streams are delayed by 'offset' seconds.
222 @section Video Options
226 Set the video bitrate in kbit/s (default = 200 kb/s).
228 Set frame rate (default = 25).
230 Set frame size. The format is @samp{wxh} (default = 160x128).
231 The following abbreviations are recognized:
244 Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777).
246 Set top crop band size (in pixels).
247 @item -cropbottom size
248 Set bottom crop band size (in pixels).
250 Set left crop band size (in pixels).
251 @item -cropright size
252 Set right crop band size (in pixels).
254 Set top pad band size (in pixels).
255 @item -padbottom size
256 Set bottom pad band size (in pixels).
258 Set left pad band size (in pixels).
260 Set right pad band size (in pixels).
261 @item -padcolor (hex color)
262 Set color of padded bands. The value for padcolor is expressed
263 as a six digit hexadecimal number where the first two digits
264 represent red, the middle two digits green and last two digits
265 blue (default = 000000 (black)).
267 Disable video recording.
269 Set video bitrate tolerance (in kbit/s).
270 @item -maxrate bitrate
271 Set max video bitrate tolerance (in kbit/s).
272 @item -minrate bitrate
273 Set min video bitrate tolerance (in kbit/s).
275 Set rate control buffer size (in kbit).
277 Force video codec to @var{codec}. Use the @code{copy} special value to
278 tell that the raw codec data must be copied as is.
280 Use same video quality as source (implies VBR).
283 Select the pass number (1 or 2). It is useful to do two pass
284 encoding. The statistics of the video are recorded in the first
285 pass and the video is generated at the exact requested bitrate
288 @item -passlogfile file
289 Set two pass logfile name to @var{file}.
293 @section Advanced Video Options
297 Set the group of pictures size.
299 Use only intra frames.
301 Use fixed video quantiser scale (VBR).
303 minimum video quantiser scale (VBR)
305 maximum video quantiser scale (VBR)
307 maximum difference between the quantiser scales (VBR)
309 video quantiser scale blur (VBR)
310 @item -qcomp compression
311 video quantiser scale compression (VBR)
313 @item -rc_init_cplx complexity
314 initial complexity for single pass encoding
315 @item -b_qfactor factor
316 qp factor between P- and B-frames
317 @item -i_qfactor factor
318 qp factor between P- and I-frames
319 @item -b_qoffset offset
320 qp offset between P- and B-frames
321 @item -i_qoffset offset
322 qp offset between P- and I-frames
323 @item -rc_eq equation
324 Set rate control equation (@pxref{FFmpeg formula
325 evaluator}) (default = @code{tex^qComp}).
326 @item -rc_override override
327 rate control override for specific intervals
329 Set motion estimation method to @var{method}.
330 Available methods are (from lowest to best quality):
333 Try just the (0, 0) vector.
340 exhaustive search (slow and marginally better than epzs)
344 Set DCT algorithm to @var{algo}. Available values are:
347 FF_DCT_AUTO (default)
360 @item -idct_algo algo
361 Set IDCT algorithm to @var{algo}. Available values are:
364 FF_IDCT_AUTO (default)
388 Set error resilience to @var{n}.
391 FF_ER_CAREFUL (default)
397 FF_ER_VERY_AGGRESSIVE
401 Set error concealment to @var{bit_mask}. @var{bit_mask} is a bit mask of
402 the following values:
405 FF_EC_GUESS_MVS (default = enabled)
407 FF_EC_DEBLOCK (default = enabled)
411 Use 'frames' B-frames (supported for MPEG-1, MPEG-2 and MPEG-4).
416 FF_MB_DECISION_SIMPLE: Use mb_cmp (cannot change it yet in FFmpeg).
418 FF_MB_DECISION_BITS: Choose the one which needs the fewest bits.
420 FF_MB_DECISION_RD: rate distortion
424 Use four motion vector by macroblock (MPEG-4 only).
426 Use data partitioning (MPEG-4 only).
428 Work around encoder bugs that are not auto-detected.
429 @item -strict strictness
430 How strictly to follow the standards.
432 Enable Advanced intra coding (h263+).
434 Enable Unlimited Motion Vector (h263+)
437 Deinterlace pictures.
439 Force interlacing support in encoder (MPEG-2 and MPEG-4 only).
440 Use this option if your input file is interlaced and you want
441 to keep the interlaced format for minimum losses.
442 The alternative is to deinterlace the input stream with
443 @option{-deinterlace}, but deinterlacing introduces losses.
445 Calculate PSNR of compressed frames.
447 Dump video coding statistics to @file{vstats_HHMMSS.log}.
449 Insert video processing @var{module}. @var{module} contains the module
450 name and its parameters separated by spaces.
453 @section Audio Options
457 Set the audio sampling frequency (default = 44100 Hz).
459 Set the audio bitrate in kbit/s (default = 64).
461 Set the number of audio channels (default = 1).
463 Disable audio recording.
465 Force audio codec to @var{codec}. Use the @code{copy} special value to
466 specify that the raw codec data must be copied as is.
469 @section Audio/Video grab options
473 sEt video grab device (e.g. @file{/dev/video0}).
475 Set video grab channel (DV1394 only).
476 @item -tvstd standard
477 Set television standard (NTSC, PAL (SECAM)).
481 Set audio device (e.g. @file{/dev/dsp}).
484 @section Advanced options
487 @item -map file:stream
488 Set input stream mapping.
490 Print specific debug info.
492 Add timings for benchmarking.
494 Dump each input packet.
496 Only use bit exact algorithms (for codec testing).
498 Set packet size in bits.
500 Read input at native frame rate. Mainly used to simulate a grab device.
502 Loop over the input stream. Currently it works only for image
503 streams. This option is used for automatic FFserver testing.
504 @item -loop_output number_of_times
505 Repeatedly loop output for formats that support looping such as animated GIF
506 (0 will loop the output infinitely).
509 @node FFmpeg formula evaluator
510 @section FFmpeg formula evaluator
512 When evaluating a rate control string, FFmpeg uses an internal formula
515 The following binary operators are available: @code{+}, @code{-},
516 @code{*}, @code{/}, @code{^}.
518 The following unary operators are available: @code{+}, @code{-},
521 The following functions are available:
543 The following constants are available:
572 @settitle FFmpeg video converter
575 ffserver(1), ffplay(1) and the HTML documentation of @file{ffmpeg}.
586 The filename can be @file{-} to read from standard input or to write
589 FFmpeg also handles many protocols specified with an URL syntax.
591 Use 'ffmpeg -formats' to see a list of the supported protocols.
593 The protocol @code{http:} is currently used only to communicate with
594 FFserver (see the FFserver documentation). When FFmpeg will be a
595 video player it will also be used for streaming :-)
600 @item For streaming at very low bitrate application, use a low frame rate
601 and a small GOP size. This is especially true for RealVideo where
602 the Linux player does not seem to be very fast, so it can miss
603 frames. An example is:
606 ffmpeg -g 3 -r 3 -t 10 -b 50 -s qcif -f rv10 /tmp/b.rm
609 @item The parameter 'q' which is displayed while encoding is the current
610 quantizer. The value 1 indicates that a very good quality could
611 be achieved. The value 31 indicates the worst quality. If q=31 appears
612 too often, it means that the encoder cannot compress enough to meet
613 your bitrate. You must either increase the bitrate, decrease the
614 frame rate or decrease the frame size.
616 @item If your computer is not fast enough, you can speed up the
617 compression at the expense of the compression ratio. You can use
618 '-me zero' to speed up motion estimation, and '-intra' to disable
619 motion estimation completely (you have only I-frames, which means it
620 is about as good as JPEG compression).
622 @item To have very low audio bitrates, reduce the sampling frequency
623 (down to 22050 kHz for MPEG audio, 22050 or 11025 for AC3).
625 @item To have a constant quality (but a variable bitrate), use the option
626 '-qscale n' when 'n' is between 1 (excellent quality) and 31 (worst
629 @item When converting video files, you can use the '-sameq' option which
630 uses the same quality factor in the encoder as in the decoder.
631 It allows almost lossless encoding.
635 @chapter Supported File Formats and Codecs
637 You can use the @code{-formats} option to have an exhaustive list.
639 @section File Formats
641 FFmpeg supports the following file formats through the @code{libavformat}
644 @multitable @columnfractions .4 .1 .1 .4
645 @item Supported File Format @tab Encoding @tab Decoding @tab Comments
646 @item MPEG audio @tab X @tab X
647 @item MPEG-1 systems @tab X @tab X
648 @tab muxed audio and video
649 @item MPEG-2 PS @tab X @tab X
650 @tab also known as @code{VOB} file
651 @item MPEG-2 TS @tab @tab X
652 @tab also known as DVB Transport Stream
653 @item ASF@tab X @tab X
654 @item AVI@tab X @tab X
655 @item WAV@tab X @tab X
656 @item Macromedia Flash@tab X @tab X
657 @tab Only embedded audio is decoded.
658 @item FLV @tab X @tab X
659 @tab Macromedia Flash video files
660 @item Real Audio and Video @tab X @tab X
661 @item Raw AC3 @tab X @tab X
662 @item Raw MJPEG @tab X @tab X
663 @item Raw MPEG video @tab X @tab X
664 @item Raw PCM8/16 bits, mulaw/Alaw@tab X @tab X
665 @item Raw CRI ADX audio @tab X @tab X
666 @item Raw Shorten audio @tab @tab X
667 @item SUN AU format @tab X @tab X
668 @item NUT @tab X @tab X @tab NUT Open Container Format
669 @item QuickTime @tab X @tab X
670 @item MPEG-4 @tab X @tab X
671 @tab MPEG-4 is a variant of QuickTime.
672 @item Raw MPEG4 video @tab X @tab X
673 @item DV @tab X @tab X
674 @item 4xm @tab @tab X
675 @tab 4X Technologies format, used in some games.
676 @item Playstation STR @tab @tab X
677 @item Id RoQ @tab @tab X
678 @tab Used in Quake III, Jedi Knight 2, other computer games.
679 @item Interplay MVE @tab @tab X
680 @tab Format used in various Interplay computer games.
681 @item WC3 Movie @tab @tab X
682 @tab Multimedia format used in Origin's Wing Commander III computer game.
683 @item Sega FILM/CPK @tab @tab X
684 @tab Used in many Sega Saturn console games.
685 @item Westwood Studios VQA/AUD @tab @tab X
686 @tab Multimedia formats used in Westwood Studios games.
687 @item Id Cinematic (.cin) @tab @tab X
688 @tab Used in Quake II.
689 @item FLIC format @tab @tab X
691 @item Sierra VMD @tab @tab X
692 @tab Used in Sierra CD-ROM games.
693 @item Sierra Online @tab @tab X
694 @tab .sol files used in Sierra Online games.
695 @item Matroska @tab @tab X
696 @item Electronic Arts Multimedia @tab @tab X
697 @tab Used in various EA games; files have extensions like WVE and UV2.
698 @item Nullsoft Video (NSV) format @tab @tab X
701 @code{X} means that encoding (resp. decoding) is supported.
703 @section Image Formats
705 FFmpeg can read and write images for each frame of a video sequence. The
706 following image formats are supported:
708 @multitable @columnfractions .4 .1 .1 .4
709 @item Supported Image Format @tab Encoding @tab Decoding @tab Comments
710 @item PGM, PPM @tab X @tab X
711 @item PAM @tab X @tab X @tab PAM is a PNM extension with alpha support.
712 @item PGMYUV @tab X @tab X @tab PGM with U and V components in YUV 4:2:0
713 @item JPEG @tab X @tab X @tab Progressive JPEG is not supported.
714 @item .Y.U.V @tab X @tab X @tab one raw file per component
715 @item animated GIF @tab X @tab X @tab Only uncompressed GIFs are generated.
716 @item PNG @tab X @tab X @tab 2 bit and 4 bit/pixel not supported yet.
717 @item SGI @tab X @tab X @tab SGI RGB image format
720 @code{X} means that encoding (resp. decoding) is supported.
722 @section Video Codecs
724 @multitable @columnfractions .4 .1 .1 .4
725 @item Supported Codec @tab Encoding @tab Decoding @tab Comments
726 @item MPEG-1 video @tab X @tab X
727 @item MPEG-2 video @tab X @tab X
728 @item MPEG-4 @tab X @tab X @tab also known as DivX4/5
729 @item MSMPEG4 V1 @tab X @tab X
730 @item MSMPEG4 V2 @tab X @tab X
731 @item MSMPEG4 V3 @tab X @tab X @tab also known as DivX3
732 @item WMV7 @tab X @tab X
733 @item WMV8 @tab X @tab X @tab not completely working
734 @item H.261 @tab X @tab X
735 @item H.263(+) @tab X @tab X @tab also known as RealVideo 1.0
736 @item H.264 @tab @tab X
737 @item MJPEG @tab X @tab X
738 @item lossless MJPEG @tab X @tab X
739 @item Apple MJPEG-B @tab @tab X
740 @item Sunplus MJPEG @tab @tab X @tab fourcc: SP5X
741 @item DV @tab X @tab X
742 @item HuffYUV @tab X @tab X
743 @item FFmpeg Video 1 @tab X @tab X @tab experimental lossless codec (fourcc: FFV1)
744 @item FFmpeg Snow @tab X @tab X @tab experimental wavelet codec (fourcc: SNOW)
745 @item Asus v1 @tab X @tab X @tab fourcc: ASV1
746 @item Asus v2 @tab X @tab X @tab fourcc: ASV2
747 @item Creative YUV @tab @tab X @tab fourcc: CYUV
748 @item Sorenson Video 1 @tab X @tab X @tab fourcc: SVQ1
749 @item Sorenson Video 3 @tab @tab X @tab fourcc: SVQ3
750 @item On2 VP3 @tab @tab X @tab still experimental
751 @item Theora @tab @tab X @tab still experimental
752 @item Intel Indeo 3 @tab @tab X
753 @item FLV @tab X @tab X @tab Sorenson H.263 used in Flash
754 @item ATI VCR1 @tab @tab X @tab fourcc: VCR1
755 @item ATI VCR2 @tab @tab X @tab fourcc: VCR2
756 @item Cirrus Logic AccuPak @tab @tab X @tab fourcc: CLJR
757 @item 4X Video @tab @tab X @tab Used in certain computer games.
758 @item Sony Playstation MDEC @tab @tab X
759 @item Id RoQ @tab @tab X @tab Used in Quake III, Jedi Knight 2, other computer games.
760 @item Xan/WC3 @tab @tab X @tab Used in Wing Commander III .MVE files.
761 @item Interplay Video @tab @tab X @tab Used in Interplay .MVE files.
762 @item Apple Animation @tab @tab X @tab fourcc: 'rle '
763 @item Apple Graphics @tab @tab X @tab fourcc: 'smc '
764 @item Apple Video @tab @tab X @tab fourcc: rpza
765 @item Apple QuickDraw @tab @tab X @tab fourcc: qdrw
766 @item Cinepak @tab @tab X
767 @item Microsoft RLE @tab @tab X
768 @item Microsoft Video-1 @tab @tab X
769 @item Westwood VQA @tab @tab X
770 @item Id Cinematic Video @tab @tab X @tab Used in Quake II.
771 @item Planar RGB @tab @tab X @tab fourcc: 8BPS
772 @item FLIC video @tab @tab X
773 @item Duck TrueMotion v1 @tab @tab X @tab fourcc: DUCK
774 @item VMD Video @tab @tab X @tab Used in Sierra VMD files.
775 @item MSZH @tab @tab X @tab Part of LCL
776 @item ZLIB @tab X @tab X @tab Part of LCL, encoder experimental
777 @item TechSmith Camtasia @tab @tab X @tab fourcc: TSCC
778 @item IBM Ultimotion @tab @tab X @tab fourcc: ULTI
779 @item Miro VideoXL @tab @tab X @tab fourcc: VIXL
780 @item QPEG @tab @tab X @tab fourccs: QPEG, Q1.0, Q1.1
781 @item LOCO @tab @tab X @tab
782 @item Winnov WNV1 @tab @tab X @tab
783 @item Autodesk Animator Studio Codec @tab @tab X @tab fourcc: AASC
784 @item Fraps FPS1 @tab @tab X @tab
787 @code{X} means that encoding (resp. decoding) is supported.
789 See @url{http://www.mplayerhq.hu/~michael/codec-features.html} to
790 get a precise comparison of the FFmpeg MPEG-4 codec compared to
791 other implementations.
793 @section Audio Codecs
795 @multitable @columnfractions .4 .1 .1 .1 .7
796 @item Supported Codec @tab Encoding @tab Decoding @tab Comments
797 @item MPEG audio layer 2 @tab IX @tab IX
798 @item MPEG audio layer 1/3 @tab IX @tab IX
799 @tab MP3 encoding is supported through the external library LAME.
800 @item AC3 @tab IX @tab IX
801 @tab liba52 is used internally for decoding.
802 @item Vorbis @tab X @tab X
803 @tab Supported through the external library libvorbis.
804 @item WMA V1/V2 @tab @tab X
805 @item AAC @tab X @tab X
806 @tab Supported through the external library libfaac/libfaad.
807 @item Microsoft ADPCM @tab X @tab X
808 @item MS IMA ADPCM @tab X @tab X
809 @item QT IMA ADPCM @tab @tab X
810 @item 4X IMA ADPCM @tab @tab X
811 @item G.726 ADPCM @tab X @tab X
812 @item Duck DK3 IMA ADPCM @tab @tab X
813 @tab Used in some Sega Saturn console games.
814 @item Duck DK4 IMA ADPCM @tab @tab X
815 @tab Used in some Sega Saturn console games.
816 @item Westwood Studios IMA ADPCM @tab @tab X
817 @tab Used in Westwood Studios games like Command and Conquer.
818 @item SMJPEG IMA ADPCM @tab @tab X
819 @tab Used in certain Loki game ports.
820 @item CD-ROM XA ADPCM @tab @tab X
821 @item CRI ADX ADPCM @tab X @tab X
822 @tab Used in Sega Dreamcast games.
823 @item Electronic Arts ADPCM @tab @tab X
824 @tab Used in various EA titles.
825 @item Creative ADPCM @tab @tab X
826 @item RA144 @tab @tab X
827 @tab Real 14400 bit/s codec
828 @item RA288 @tab @tab X
829 @tab Real 28800 bit/s codec
830 @item RADnet @tab X @tab IX
831 @tab Real low bitrate AC3 codec, liba52 is used for decoding.
832 @item AMR-NB @tab X @tab X
833 @tab Supported through an external library.
834 @item AMR-WB @tab X @tab X
835 @tab Supported through an external library.
836 @item DV audio @tab @tab X
837 @item Id RoQ DPCM @tab @tab X
838 @tab Used in Quake III, Jedi Knight 2, other computer games.
839 @item Interplay MVE DPCM @tab @tab X
840 @tab Used in various Interplay computer games.
841 @item Xan DPCM @tab @tab X
842 @tab Used in Origin's Wing Commander IV AVI files.
843 @item Sierra Online DPCM @tab @tab X
844 @tab Used in Sierra Online game audio files.
845 @item Apple MACE 3 @tab @tab X
846 @item Apple MACE 6 @tab @tab X
847 @item FLAC lossless audio @tab @tab X
848 @item Shorten lossless audio @tab @tab X
849 @item Apple lossless audio @tab @tab X
850 @tab QuickTime fourcc 'alac'
851 @item FFmpeg Sonic @tab X @tab X
852 @tab experimental lossy/lossless codec
855 @code{X} means that encoding (resp. decoding) is supported.
857 @code{I} means that an integer-only version is available, too (ensures high
858 performance on systems without hardware floating point support).
860 @chapter Platform Specific information
864 FFmpeg should be compiled with at least GCC 2.95.3. GCC 3.2 is the
865 preferred compiler now for FFmpeg. All future optimizations will depend on
866 features only found in GCC 3.2.
872 @subsection Native Windows compilation
875 @item Install the current versions of MSYS and MinGW from
876 @url{http://www.mingw.org/}. You can find detailed installation
877 instructions in the download section and the FAQ.
879 @item If you want to test the FFplay, also download
880 the MinGW development library of SDL 1.2.x
881 (@file{SDL-devel-1.2.x-mingw32.tar.gz}) from
882 @url{http://www.libsdl.org}. Unpack it in a temporary directory, and
883 unpack the archive @file{i386-mingw32msvc.tar.gz} in the MinGW tool
884 directory. Edit the @file{sdl-config} script so that it gives the
885 correct SDL directory when invoked.
887 @item Extract the current version of FFmpeg.
889 @item Start the MSYS shell (file @file{msys.bat}).
891 @item Change to the FFmpeg directory and follow
892 the instructions of how to compile FFmpeg (file
893 @file{INSTALL}). Usually, launching @file{./configure} and @file{make}
894 suffices. If you have problems using SDL, verify that
895 @file{sdl-config} can be launched from the MSYS command line.
897 @item You can install FFmpeg in @file{Program Files/FFmpeg} by typing
898 @file{make install}. Don't forget to copy @file{SDL.dll} to the place
899 you launch @file{ffplay} from.
906 @item The target @file{make wininstaller} can be used to create a
907 Nullsoft based Windows installer for FFmpeg and FFplay. @file{SDL.dll}
908 must be copied to the FFmpeg directory in order to build the
911 @item By using @code{./configure --enable-shared} when configuring FFmpeg,
912 you can build @file{avcodec.dll} and @file{avformat.dll}. With
913 @code{make install} you install the FFmpeg DLLs and the associated
914 headers in @file{Program Files/FFmpeg}.
916 @item Visual C++ compatibility: If you used @code{./configure --enable-shared}
917 when configuring FFmpeg, FFmpeg tries to use the Microsoft Visual
918 C++ @code{lib} tool to build @code{avcodec.lib} and
919 @code{avformat.lib}. With these libraries you can link your Visual C++
920 code directly with the FFmpeg DLLs (see below).
924 @subsection Visual C++ compatibility
926 FFmpeg will not compile under Visual C++ -- and it has too many
927 dependencies on the GCC compiler to make a port viable. However,
928 if you want to use the FFmpeg libraries in your own applications,
929 you can still compile those applications using Visual C++. An
930 important restriction to this is that you have to use the
931 dynamically linked versions of the FFmpeg libraries (i.e. the
932 DLLs), and you have to make sure that Visual-C++-compatible
933 import libraries are created during the FFmpeg build process.
935 This description of how to use the FFmpeg libraries with Visual C++ is
936 based on Visual C++ 2005 Express Edition Beta 2. If you have a different
937 version, you might have to modify the procedures slightly.
939 Here are the step-by-step instructions for building the FFmpeg libraries
940 so they can be used with Visual C++:
944 @item Install Visual C++ (if you haven't done so already).
946 @item Install MinGW and MSYS as described above.
948 @item Add a call to @file{vcvars32.bat} (which sets up the environment
949 variables for the Visual C++ tools) as the first line of
950 @file{msys.bat}. The standard location for @file{vcvars32.bat} is
951 @file{C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat},
952 and the standard location for @file{msys.bat} is
953 @file{C:\msys\1.0\msys.bat}. If this corresponds to your setup, add the
954 following line as the first line of @file{msys.bat}:
956 @code{call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"}
958 @item Start the MSYS shell (file @file{msys.bat}) and type @code{link.exe}.
959 If you get a help message with the command line options of @code{link.exe},
960 this means your environment variables are set up correctly, the
961 Microsoft linker is on the path and will be used by FFmpeg to
962 create Visual-C++-compatible import libraries.
964 @item Extract the current version of FFmpeg and change to the FFmpeg directory.
966 @item Type the command
967 @code{./configure --enable-shared --enable-memalign-hack} to configure and,
968 if that didn't produce any errors, type @code{make} to build FFmpeg.
970 @item The subdirectories @file{libavformat}, @file{libavcodec}, and
971 @file{libavutil} should now contain the files @file{avformat.dll},
972 @file{avformat.lib}, @file{avcodec.dll}, @file{avcodec.lib},
973 @file{avutil.dll}, and @file{avutil.lib}, respectively. Copy the three
974 DLLs to your System32 directory (typically @file{C:\Windows\System32}).
978 And here is how to use these libraries with Visual C++:
982 @item Create a new console application ("File / New / Project") and then
983 select "Win32 Console Application". On the appropriate page of the
984 Application Wizard, uncheck the "Precompiled headers" option.
986 @item Write the source code for your application, or, for testing, just
987 copy the code from an existing sample application into the source file
988 that Visual C++ has already created for you. (Note that your source
989 filehas to have a @code{.cpp} extension; otherwise, Visual C++ won't
990 compile the FFmpeg headers correctly because in C mode, it doesn't
991 recognize the @code{inline} keyword.) For example, you can copy
992 @file{output_example.c} from the FFmpeg distribution (but you will
993 have to make minor modifications so the code will compile under
996 @item Open the "Project / Properties" dialog box. In the "Configuration"
997 combo box, select "All Configurations" so that the changes you make will
998 affect both debug and release builds. In the tree view on the left hand
999 side, select "C/C++ / General", then edit the "Additional Include
1000 Directories" setting to contain the complete paths to the
1001 @file{libavformat}, @file{libavcodec}, and @file{libavutil}
1002 subdirectories of your FFmpeg directory. Note that the directories have
1003 to be separated using semicolons. Now select "Linker / General" from the
1004 tree view and edit the "Additional Library Directories" setting to
1005 contain the same three directories.
1007 @item Still in the "Project / Properties" dialog box, select "Linker / Input"
1008 from the tree view, then add the files @file{avformat.lib},
1009 @file{avcodec.lib}, and @file{avutil.lib} to the end of the "Additional
1010 Dependencies". Note that the names of the libraries have to be separated
1013 @item Now, select "C/C++ / Preprocessor" from the tree view. Select "Debug"
1014 in the "Configuration" combo box. Add @code{EMULATE_INTTYPES} to the
1015 "Preprocessor Definitions". (Note that the various preprocessor
1016 definitions have to be separated using semicolons.) Select "Release" in
1017 the "Configuration" combo box and, again, add @code{EMULATE_INTTYPES} to
1018 the "Preprocessor Definitions". (This has to be done separately because
1019 debug and release builds have different preprocessor definitions.)
1020 Finally, select "C/C++ / Code Generation" from the tree view. Select
1021 "Debug" in the "Configuration" combo box. Make sure that "Runtime
1022 Library" is set to "Multi-threaded Debug DLL". Then, select "Release" in
1023 the "Configuration" combo box and make sure that "Runtime Library" is
1024 set to "Multi-threaded DLL".
1026 @item Click "OK" to close the "Project / Properties" dialog box and build
1027 the application. Hopefully, it should compile and run cleanly. If you
1028 used @file{output_example.c} as your sample application, you will get a
1029 few compiler errors, but they are easy to fix. The first type of error
1030 occurs because Visual C++ doesn't allow an @code{int} to be converted to
1031 an @code{enum} without a cast. To solve the problem, insert the required
1032 casts (this error occurs once for a @code{CodecID} and once for a
1033 @code{CodecType}). The second type of error occurs because C++ requires
1034 the return value of @code{malloc} to be cast to the exact type of the
1035 pointer it is being assigned to. Visual C++ will complain that, for
1036 example, @code{(void *)} is being assigned to @code{(uint8_t *)} without
1037 an explicit cast. So insert an explicit cast in these places to silence
1038 the compiler. The third type of error occurs because the @code{snprintf}
1039 library function is called @code{_snprintf} under Visual C++. So just
1040 add an underscore to fix the problem. With these changes,
1041 @file{output_example.c} should compile under Visual C++, and the
1042 resulting executable should produce valid video files.
1046 @subsection Cross compilation for Windows with Linux
1048 You must use the MinGW cross compilation tools available at
1049 @url{http://www.mingw.org/}.
1051 Then configure FFmpeg with the following options:
1053 ./configure --enable-mingw32 --cross-prefix=i386-mingw32msvc-
1055 (you can change the cross-prefix according to the prefix chosen for the
1058 Then you can easily test FFmpeg with Wine
1059 (@url{http://www.winehq.com/}).
1065 The configure script should guess the configuration itself.
1066 Networking support is currently not finished.
1067 errno issues fixed by Andrew Bachmann.
1071 François Revol - revol at free dot fr - April 2002
1073 The configure script should guess the configuration itself,
1074 however I still didn't test building on the net_server version of BeOS.
1076 FFserver is broken (needs poll() implementation).
1078 There are still issues with errno codes, which are negative in BeOS, and
1079 that FFmpeg negates when returning. This ends up turning errors into
1080 valid results, then crashes.
1083 @chapter Developers Guide
1087 @item libavcodec is the library containing the codecs (both encoding and
1088 decoding). Look at @file{libavcodec/apiexample.c} to see how to use it.
1090 @item libavformat is the library containing the file format handling (mux and
1091 demux code for several formats). Look at @file{ffplay.c} to use it in a
1092 player. See @file{output_example.c} to use it to generate audio or video
1097 @section Integrating libavcodec or libavformat in your program
1099 You can integrate all the source code of the libraries to link them
1100 statically to avoid any version problem. All you need is to provide a
1101 'config.mak' and a 'config.h' in the parent directory. See the defines
1102 generated by ./configure to understand what is needed.
1104 You can use libavcodec or libavformat in your commercial program, but
1105 @emph{any patch you make must be published}. The best way to proceed is
1106 to send your patches to the FFmpeg mailing list.
1109 @section Coding Rules
1111 FFmpeg is programmed in the ISO C90 language with a few additional
1112 features from ISO C99, namely:
1115 the @samp{inline} keyword;
1119 designated struct initializers (@samp{struct s x = @{ .i = 17 @};})
1121 compound literals (@samp{x = (struct s) @{ 17, 23 @};})
1124 These features are supported by all compilers we care about, so we won't
1125 accept patches to remove their use unless they absolutely don't impair
1126 clarity and performance.
1128 All code must compile with GCC 2.95 and GCC 3.3. Currently, FFmpeg also
1129 compiles with several other compilers, such as the Compaq ccc compiler
1130 or Sun Studio 9, and we would like to keep it that way unless it would
1131 be exceedingly involved. To ensure compatibility, please don't use any
1132 additional C99 features or GCC extensions. Especially watch out for:
1135 mixing statements and declarations;
1137 @samp{long long} (use @samp{int64_t} instead);
1139 @samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar;
1141 GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}).
1144 Indent size is 4. The TAB character should not be used.
1145 The presentation is the one specified by 'indent -i4 -kr'.
1147 Main priority in FFmpeg is simplicity and small code size (=less
1150 Comments: Use the JavaDoc/Doxygen
1151 format (see examples below) so that code documentation
1152 can be generated automatically. All nontrivial functions should have a comment
1153 above them explaining what the function does, even if it's just one sentence.
1154 All structures and their member variables should be documented, too.
1167 typedef struct Foobar@{
1168 int var1; /**< var1 description */
1169 int var2; ///< var2 description
1170 /** var3 description */
1178 * @@param my_parameter description of my_parameter
1179 * @@return return value description
1181 int myfunc(int my_parameter)
1185 fprintf and printf are forbidden in libavformat and libavcodec,
1186 please use av_log() instead.
1193 You must not commit code which breaks FFmpeg! (Meaning unfinished but
1194 enabled code which breaks compilation or compiles but does not work or
1195 breaks the regression tests)
1196 You can commit unfinished stuff (for testing etc), but it must be disabled
1197 (#ifdef etc) by default so it does not interfere with other developers'
1200 You don't have to over-test things. If it works for you, and you think it
1201 should work for others, then commit. If your code has problems
1202 (portability, triggers compiler bugs, unusual environment etc) they will be
1203 reported and eventually fixed.
1205 Do not commit unrelated changes together, split them into self-contained
1208 Do not change behavior of the program (renaming options etc) without
1209 first discussing it on the ffmpeg-devel mailing list. Do not remove
1210 functionality from the code. Just improve!
1212 Note: Redundant code can be removed.
1214 Do not commit changes to the build system (Makefiles, configure script)
1215 which change behavior, defaults etc, without asking first. The same
1216 applies to compiler warning fixes, trivial looking fixes and to code
1217 maintained by other developers. We usually have a reason for doing things
1218 the way we do. Send your changes as patches to the ffmpeg-devel mailing
1219 list, and if the code maintainers say OK, you may commit. This does not
1220 apply to files you wrote and/or maintain.
1222 We refuse source indentation and other cosmetic changes if they are mixed
1223 with functional changes, such commits will be rejected and removed. Every
1224 developer has his own indentation style, you should not change it. Of course
1225 if you (re)write something, you can use your own style, even though we would
1226 prefer if the indentation throughout FFmpeg was consistent (Many projects
1227 force a given indentation style - we don't.). If you really need to make
1228 indentation changes (try to avoid this), separate them strictly from real
1231 NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code,
1232 then either do NOT change the indentation of the inner part within (don't
1233 move it to the right)! or do so in a separate commit
1235 Always fill out the commit log message. Describe in a few lines what you
1236 changed and why. You can refer to mailing list postings if you fix a
1237 particular bug. Comments such as "fixed!" or "Changed it." are unacceptable.
1239 If you apply a patch by someone else, include the name and email address in
1240 the CVS log message. Since the ffmpeg-cvslog mailing list is publicly
1241 archived you should add some SPAM protection to the email address. Send an
1242 answer to ffmpeg-devel (or wherever you got the patch from) saying that
1243 you applied the patch.
1245 Do NOT commit to code actively maintained by others without permission. Send
1246 a patch to ffmpeg-devel instead.
1248 Subscribe to the ffmpeg-cvslog mailing list. The diffs of all CVS commits
1249 are sent there and reviewed by all the other developers. Bugs and possible
1250 improvements or general questions regarding commits are discussed there. We
1251 expect you to react if problems with your code are uncovered.
1253 Update the documentation if you change behavior or add features. If you are
1254 unsure how best to do this, send a patch to ffmpeg-devel, the documentation
1255 maintainer(s) will review and commit your stuff.
1257 Revert a commit ONLY in case of a big blunder like committing something not
1258 intended to be committed or committing a wrong file, the wrong version of a
1259 patch, CVS policy violation or broken code and you are going to recommit the
1260 right thing immediately.
1262 Never revert changes made a long time ago or buggy code. Fix it in the
1265 Never write to unallocated memory, never write over the end of arrays,
1266 always check values read from some untrusted source before using them
1267 as array index or other risky things.
1270 We think our rules are not too hard. If you have comments, contact us.
1272 Note, these rules are mostly borrowed from the MPlayer project.
1274 @subsection Renaming/moving files or content of files
1275 You CANNOT do that. Post a request for such a change to the mailing list
1276 Do NOT remove & readd a file - it will kill the changelog!!!!
1278 @section Submitting patches
1280 First, (@pxref{Coding Rules}) above if you didn't yet.
1282 When you submit your patch, try to send a unified diff (diff '-up'
1283 option). I cannot read other diffs :-)
1285 Also please do not submit patches which contain several unrelated changes.
1286 Split them into individual self-contained patches; this makes reviewing
1289 Run the regression tests before submitting a patch so that you can
1290 verify that there are no big problems.
1292 Patches should be posted as base64 encoded attachments (or any other
1293 encoding which ensures that the patch won't be trashed during
1294 transmission) to the ffmpeg-devel mailing list, see
1295 @url{http://www1.mplayerhq.hu/mailman/listinfo/ffmpeg-devel}
1297 It also helps quite a bit if you tell us what the patch does (for example
1298 'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant
1299 and has no lrint()')
1301 We reply to all submitted patches and either apply or reject with some
1302 explanation why, but sometimes we are quite busy so it can take a week or two.
1304 @section Regression tests
1306 Before submitting a patch (or committing to CVS), you should at least
1307 test that you did not break anything.
1309 The regression tests build a synthetic video stream and a synthetic
1310 audio stream. These are then encoded and decoded with all codecs or
1311 formats. The CRC (or MD5) of each generated file is recorded in a
1312 result file. A 'diff' is launched to compare the reference results and
1315 The regression tests then go on to test the FFserver code with a
1316 limited set of streams. It is important that this step runs correctly
1319 Run 'make test' to test all the codecs and formats.
1321 Run 'make fulltest' to test all the codecs, formats and FFserver.
1323 [Of course, some patches may change the results of the regression tests. In
1324 this case, the reference results of the regression tests shall be modified