Penguin
Annotated edit history of FFmpeg version 18, including all changes. View license author blame.
Rev Author # Line
6 LawrenceDoliveiro 1 FFmpeg is a multi-purpose multimedia tool which can convert between an amazing variety of different file formats and audio and video [CoDec]s. Its development is done in common with that of [MPlayer].
2
3 FFmpeg is undergoing continual development. Hence, any copy included with your [distro|Distro] is guaranteed to be out of date. Instead, always get the latest version via SubVersion from the repository linked from the FFmpeg home page (below).
4
5 Basic usage:
6
7 ffmpeg ''input-spec'' ''~[input-spec ...]'' ''output-spec'' ''~[output-spec ...]'' ''~[mapping-options]''
8
9 where each ''input-spec'' consists of
10
11 -i ''input-filename''
12
8 LawrenceDoliveiro 13 possibly preceded by options that apply to that input file (e.g. overriding format, sample rate etc if FFmpeg guesses wrong), and each ''output-spec'' consists of
6 LawrenceDoliveiro 14
15 ''output-filename''
16
17 possibly preceded by options to be applied in generating that output file.
18
19 FFmpeg does not ''concatenate'' multiple input files, it ''multiplexes'' them. Thus, you can specify an input video-only file and an input audio-only file, and get a combined video-plus-audio output file. Or you can ''demultiplex'' the input into multiple output files, for example video-only into one output file, audio-only into another, or different encodings of the same video or audio input into different outputs.
20
21 The ''mapping-options'' allow the specification of which streams from whicn input file(s) are mapped onto which streams in the output file(s). These are only necessary if FFmpeg can't figure out the right thing to do.
22
12 JohnBillings 23 !!Tips
10 JohnBillings 24
14 JohnBillings 25 !Extract an audio file from a MP4 or other video file:
10 JohnBillings 26
11 JohnBillings 27 ffmpeg -i Videofile.mp4 -vn -acodec mp3 audiofile.mp3
28
10 JohnBillings 29 Result on Ubuntu 9.04:
30
31 Unknown encoder 'mp3'
32
33 Fail!
34
11 JohnBillings 35 You could follow the advice [in this bug report|https://bugs.launchpad.net/ubuntu/+source/ffmpeg/+bug/296922], but why bother. Just do this:
10 JohnBillings 36
11 JohnBillings 37 ffmpeg -i Videofile.mp4 -vn -acodec vorbis audiofile.ogg
38
12 JohnBillings 39 !Extract a single video frame into a JPEG file:
6 LawrenceDoliveiro 40
9 LawrenceDoliveiro 41 <pre>
42 ffmpeg -ss ''hh'':''mm'':''ss'':''cc'' -t 00:00:00.01 -i ''input-filename'' -f mjpeg ''output-name''.jpeg
43 </pre>
6 LawrenceDoliveiro 44
45 For example, extract the frame at time 3 minutes and 51.04 seconds into the input video file:
46
9 LawrenceDoliveiro 47 <pre>
48 ffmpeg -ss 00:03:51.04 -t 00:00:00.01 -i my-doggie.mpg -f mjpeg my-doggie-thumbnail.jpeg
49 </pre>
6 LawrenceDoliveiro 50
12 JohnBillings 51 !Generate a specified duration of silence:
6 LawrenceDoliveiro 52
53 <pre>
54 ~NrChannels~=2
55 ~SampleRate~=48000
56 ~NrSeconds~=1
57 # above parameters can be changed as appropriate
58 ffmpeg -ar $~SampleRate -acodec pcm_s16le -f s16le -ac $~NrChannels \
59 -i <(dd if=/dev/zero bs=$(($~SampleRate * $~NrChannels * 2)) count=$~NrSeconds) \
60 silence.wav
61 </pre>
62
12 JohnBillings 63 !Generate a static background suitable for a non-animated [DVD-Video|DVDVideo] menu.
64
65 This takes a single still frame (probably best to stick to [JPEG] format, certainly [PNG] didn't work) and turns it into an [MPEG]-2 output movie with a silent soundtrack. The movie is of one-second duration, which is sufficient because it can be set to loop during the DVD authoring process:
6 LawrenceDoliveiro 66
67 <pre>
68 ffmpeg -loop_input -t 1.0 -i ''stillframename'' \
16 LawrenceDoliveiro 69 -ar 48000 -f s16le -i <(dd if=/dev/zero bs=96000 count=1) \
6 LawrenceDoliveiro 70 -target pal-dvd ''outputmoviename''
9 LawrenceDoliveiro 71 </pre>
6 LawrenceDoliveiro 72
73 where <tt>pal-dvd</tt> can be replaced with <tt>ntsc-dvd</tt> if authoring an NTSC disc rather than PAL.
15 LawrenceDoliveiro 74
75 !Concatenate two movies
76
77 This technique takes apart the video frames from the input movies and reassembles them into the output movie without decompressing and recompressing them. It uses the <tt>image2pipe</tt> container format to stream the frames. Unfortunately there doesn’t seem to be an equivalent pipe container format for audio, so that ends up being reencoded into the specified output format (which can of course be changed as required).
78
79 <pre>
17 LawrenceDoliveiro 80 audioparms="-f s16le -ar 48000 -ac 2" # choose appropriate intermediate audio format
15 LawrenceDoliveiro 81 ffmpeg \
82 -i <(
83 ffmpeg -v 0 -i ''inputfile1'' -f image2pipe -vcodec copy -y /dev/stdout;
84 ffmpeg -v 0 -i ''inputfile2'' -f image2pipe -vcodec copy -y /dev/stdout
85 ) \
86 $audioparms -i <(
87 ffmpeg -v 0 -i ''inputfile1'' $audioparms -y /dev/stdout;
88 ffmpeg -v 0 -i ''inputfile2'' $audioparms -y /dev/stdout
89 ) \
90 -vcodec copy -acodec pcm_s16le ''outputfile''
91 </pre>
92
93 Extending the example to concatenate more than two files is left as an exercise for the reader. :)
9 LawrenceDoliveiro 94
12 JohnBillings 95 !Fix audio/video sync in a movie
96
97 In this example, 64 seconds (determined by trial and error while observing lip sync) was trimmed from the start of the audio track. The video track happens to come first in the list; the source movie is specified twice, once with the appropriate offset applied, and the <tt>-map</tt> option is used to select the appropriate audio and video streams to combine into the output movie: the first <tt>-map</tt> specification says that the first (video) output stream is to come from the first stream of the second input file (stream 1.0), while the second <tt>-map</tt> specification says that the second (audio) output stream is to come from the second stream of the first input file (stream 0.1). Note the use also of <tt>-vcodec copy</tt> and <tt>-acodec copy</tt> to ensure that no re-encoding of audio or video data takes place:
9 LawrenceDoliveiro 98
99 <pre>
100 ffmpeg \
101 -ss 00:01:04.00 -i ''srcmovie'' \
102 -i ''srcmovie'' \
103 -vcodec copy -acodec copy ''dstmovie'' \
104 -map 1.0 -map 0.1
18 LawrenceDoliveiro 105 </pre>
106
107 !Resize video for DVD
108 Supposing I have a film where the video frames are 608x224 pixels, that I want to put on a DVD. Allowable aspect ratios for DVD-Video are 4:3 or 16:9. Clearly I should use 16:9 as the closest fit to the original ratio, and add black bars at the top and bottom to pad out the video frame.
109
110 But there is also the complication that pixels in DVD-Video are non-square: even though I want the video displayed at a 16:9 ratio, the number of pixels I have to play with on a PAL DVD is 720x576, which doesn’t match a 16:9 ratio.
111
112 The trick is to do the calculation in two stages: first calculate the necessary resizing to fill as much as possible of a destination frame size of 720x405 pixels (which has a 16:9 ratio), then apply an additional vertical rescaling to stretch the height from 405 to 576 pixels.
113
114 So if the width of 608 pixels is rescaled to 720, then the height of 224 pixels must be correspondingly rescaled to (720 / 608) * 224 = 265 (to the nearest pixel), in order to avoid distorting the images. Then I apply another vertical scale factor of 576 / 405 for the non-uniform DVD-Video pixels, to come up with a height of 377 pixels—make it 378, because video encoding algorithms tend to prefer even dimensions.
115
116 This I then need to pad out to a final height of 576 pixels by adding black bars at the top and bottom. FFmpeg can do this with its “pad” filter, specified as <tt>-vf pad ''width'':''height'':''xoffset'':''yoffset''</tt>. To keep the video nicely centred on the screen, the bars should have equal heights of (576 - 378) / 2 = 99 pixels.
117
118 So the complete FFmpeg command looks something like this:
119
120 <pre>
121 ffmpeg -i in.mpg -target pal-dvd -s 720x378 -vf pad=720:576:0:99 -aspect 16:9 out.mpg
9 LawrenceDoliveiro 122 </pre>
6 LawrenceDoliveiro 123
13 JohnBillings 124 !!Links:
125
6 LawrenceDoliveiro 126 * [FFmpeg home|http://ffmpeg.mplayerhq.hu/]
127 * [libamr home page|http://www.penguin.cz/~utx/amr] -- needed for audio encoding if you're making 3GPP movies to play on cell phones. Recent versions of FFmpeg no longer expect the AMR source code to be inserted into the FFmpeg source tree.

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 4 times)