]> git.sesse.net Git - ffmpeg/blob - doc/muxers.texi
avi: Use the correct data type
[ffmpeg] / doc / muxers.texi
1 @chapter Muxers
2 @c man begin MUXERS
3
4 Muxers are configured elements in Libav which allow writing
5 multimedia streams to a particular type of file.
6
7 When you configure your Libav build, all the supported muxers
8 are enabled by default. You can list all available muxers using the
9 configure option @code{--list-muxers}.
10
11 You can disable all the muxers with the configure option
12 @code{--disable-muxers} and selectively enable / disable single muxers
13 with the options @code{--enable-muxer=@var{MUXER}} /
14 @code{--disable-muxer=@var{MUXER}}.
15
16 The option @code{-formats} of the av* tools will display the list of
17 enabled muxers.
18
19 A description of some of the currently available muxers follows.
20
21 @anchor{crc}
22 @section crc
23
24 CRC (Cyclic Redundancy Check) testing format.
25
26 This muxer computes and prints the Adler-32 CRC of all the input audio
27 and video frames. By default audio frames are converted to signed
28 16-bit raw audio and video frames to raw video before computing the
29 CRC.
30
31 The output of the muxer consists of a single line of the form:
32 CRC=0x@var{CRC}, where @var{CRC} is a hexadecimal number 0-padded to
33 8 digits containing the CRC for all the decoded input frames.
34
35 For example to compute the CRC of the input, and store it in the file
36 @file{out.crc}:
37 @example
38 avconv -i INPUT -f crc out.crc
39 @end example
40
41 You can print the CRC to stdout with the command:
42 @example
43 avconv -i INPUT -f crc -
44 @end example
45
46 You can select the output format of each frame with @command{avconv} by
47 specifying the audio and video codec and format. For example to
48 compute the CRC of the input audio converted to PCM unsigned 8-bit
49 and the input video converted to MPEG-2 video, use the command:
50 @example
51 avconv -i INPUT -c:a pcm_u8 -c:v mpeg2video -f crc -
52 @end example
53
54 See also the @ref{framecrc} muxer.
55
56 @anchor{framecrc}
57 @section framecrc
58
59 Per-frame CRC (Cyclic Redundancy Check) testing format.
60
61 This muxer computes and prints the Adler-32 CRC for each decoded audio
62 and video frame. By default audio frames are converted to signed
63 16-bit raw audio and video frames to raw video before computing the
64 CRC.
65
66 The output of the muxer consists of a line for each audio and video
67 frame of the form: @var{stream_index}, @var{frame_dts},
68 @var{frame_size}, 0x@var{CRC}, where @var{CRC} is a hexadecimal
69 number 0-padded to 8 digits containing the CRC of the decoded frame.
70
71 For example to compute the CRC of each decoded frame in the input, and
72 store it in the file @file{out.crc}:
73 @example
74 avconv -i INPUT -f framecrc out.crc
75 @end example
76
77 You can print the CRC of each decoded frame to stdout with the command:
78 @example
79 avconv -i INPUT -f framecrc -
80 @end example
81
82 You can select the output format of each frame with @command{avconv} by
83 specifying the audio and video codec and format. For example, to
84 compute the CRC of each decoded input audio frame converted to PCM
85 unsigned 8-bit and of each decoded input video frame converted to
86 MPEG-2 video, use the command:
87 @example
88 avconv -i INPUT -c:a pcm_u8 -c:v mpeg2video -f framecrc -
89 @end example
90
91 See also the @ref{crc} muxer.
92
93 @anchor{hls}
94 @section hls
95
96 Apple HTTP Live Streaming muxer that segments MPEG-TS according to
97 the HTTP Live Streaming specification.
98
99 It creates a playlist file and numbered segment files. The output
100 filename specifies the playlist filename; the segment filenames
101 receive the same basename as the playlist, a sequential number and
102 a .ts extension.
103
104 @example
105 avconv -i in.nut out.m3u8
106 @end example
107
108 @table @option
109 @item -hls_time @var{seconds}
110 Set the segment length in seconds.
111 @item -hls_list_size @var{size}
112 Set the maximum number of playlist entries.
113 @item -hls_wrap @var{wrap}
114 Set the number after which index wraps.
115 @item -start_number @var{number}
116 Start the sequence from @var{number}.
117 @item -hls_base_url @var{baseurl}
118 Append @var{baseurl} to every entry in the playlist.
119 Useful to generate playlists with absolute paths.
120 @item -hls_allow_cache @var{allowcache}
121 Explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments
122 @item -hls_version @var{version}
123 Set the protocol version. Enables or disables version-specific features
124 such as the integer (version 2) or decimal EXTINF values (version 3).
125 @end table
126
127 @anchor{image2}
128 @section image2
129
130 Image file muxer.
131
132 The image file muxer writes video frames to image files.
133
134 The output filenames are specified by a pattern, which can be used to
135 produce sequentially numbered series of files.
136 The pattern may contain the string "%d" or "%0@var{N}d", this string
137 specifies the position of the characters representing a numbering in
138 the filenames. If the form "%0@var{N}d" is used, the string
139 representing the number in each filename is 0-padded to @var{N}
140 digits. The literal character '%' can be specified in the pattern with
141 the string "%%".
142
143 If the pattern contains "%d" or "%0@var{N}d", the first filename of
144 the file list specified will contain the number 1, all the following
145 numbers will be sequential.
146
147 The pattern may contain a suffix which is used to automatically
148 determine the format of the image files to write.
149
150 For example the pattern "img-%03d.bmp" will specify a sequence of
151 filenames of the form @file{img-001.bmp}, @file{img-002.bmp}, ...,
152 @file{img-010.bmp}, etc.
153 The pattern "img%%-%d.jpg" will specify a sequence of filenames of the
154 form @file{img%-1.jpg}, @file{img%-2.jpg}, ..., @file{img%-10.jpg},
155 etc.
156
157 The following example shows how to use @command{avconv} for creating a
158 sequence of files @file{img-001.jpeg}, @file{img-002.jpeg}, ...,
159 taking one image every second from the input video:
160 @example
161 avconv -i in.avi -vsync 1 -r 1 -f image2 'img-%03d.jpeg'
162 @end example
163
164 Note that with @command{avconv}, if the format is not specified with the
165 @code{-f} option and the output filename specifies an image file
166 format, the image2 muxer is automatically selected, so the previous
167 command can be written as:
168 @example
169 avconv -i in.avi -vsync 1 -r 1 'img-%03d.jpeg'
170 @end example
171
172 Note also that the pattern must not necessarily contain "%d" or
173 "%0@var{N}d", for example to create a single image file
174 @file{img.jpeg} from the input video you can employ the command:
175 @example
176 avconv -i in.avi -f image2 -frames:v 1 img.jpeg
177 @end example
178
179 @table @option
180 @item -start_number @var{number}
181 Start the sequence from @var{number}.
182
183 @item -update @var{number}
184 If @var{number} is nonzero, the filename will always be interpreted as just a
185 filename, not a pattern, and this file will be continuously overwritten with new
186 images.
187
188 @end table
189
190 @section matroska
191
192 Matroska container muxer.
193
194 This muxer implements the matroska and webm container specs.
195
196 The recognized metadata settings in this muxer are:
197
198 @table @option
199
200 @item title=@var{title name}
201 Name provided to a single track
202 @end table
203
204 @table @option
205
206 @item language=@var{language name}
207 Specifies the language of the track in the Matroska languages form
208 @end table
209
210 @table @option
211
212 @item STEREO_MODE=@var{mode}
213 Stereo 3D video layout of two views in a single video track
214 @table @option
215 @item mono
216 video is not stereo
217 @item left_right
218 Both views are arranged side by side, Left-eye view is on the left
219 @item bottom_top
220 Both views are arranged in top-bottom orientation, Left-eye view is at bottom
221 @item top_bottom
222 Both views are arranged in top-bottom orientation, Left-eye view is on top
223 @item checkerboard_rl
224 Each view is arranged in a checkerboard interleaved pattern, Left-eye view being first
225 @item checkerboard_lr
226 Each view is arranged in a checkerboard interleaved pattern, Right-eye view being first
227 @item row_interleaved_rl
228 Each view is constituted by a row based interleaving, Right-eye view is first row
229 @item row_interleaved_lr
230 Each view is constituted by a row based interleaving, Left-eye view is first row
231 @item col_interleaved_rl
232 Both views are arranged in a column based interleaving manner, Right-eye view is first column
233 @item col_interleaved_lr
234 Both views are arranged in a column based interleaving manner, Left-eye view is first column
235 @item anaglyph_cyan_red
236 All frames are in anaglyph format viewable through red-cyan filters
237 @item right_left
238 Both views are arranged side by side, Right-eye view is on the left
239 @item anaglyph_green_magenta
240 All frames are in anaglyph format viewable through green-magenta filters
241 @item block_lr
242 Both eyes laced in one Block, Left-eye view is first
243 @item block_rl
244 Both eyes laced in one Block, Right-eye view is first
245 @end table
246 @end table
247
248 For example a 3D WebM clip can be created using the following command line:
249 @example
250 avconv -i sample_left_right_clip.mpg -an -c:v libvpx -metadata STEREO_MODE=left_right -y stereo_clip.webm
251 @end example
252
253 This muxer supports the following options:
254
255 @table @option
256
257 @item reserve_index_space
258 By default, this muxer writes the index for seeking (called cues in Matroska
259 terms) at the end of the file, because it cannot know in advance how much space
260 to leave for the index at the beginning of the file. However for some use cases
261 -- e.g.  streaming where seeking is possible but slow -- it is useful to put the
262 index at the beginning of the file.
263
264 If this option is set to a non-zero value, the muxer will reserve a given amount
265 of space in the file header and then try to write the cues there when the muxing
266 finishes. If the available space does not suffice, muxing will fail. A safe size
267 for most use cases should be about 50kB per hour of video.
268
269 Note that cues are only written if the output is seekable and this option will
270 have no effect if it is not.
271
272 @end table
273
274 @section mov, mp4, ismv
275
276 The mov/mp4/ismv muxer supports fragmentation. Normally, a MOV/MP4
277 file has all the metadata about all packets stored in one location
278 (written at the end of the file, it can be moved to the start for
279 better playback using the @command{qt-faststart} tool). A fragmented
280 file consists of a number of fragments, where packets and metadata
281 about these packets are stored together. Writing a fragmented
282 file has the advantage that the file is decodable even if the
283 writing is interrupted (while a normal MOV/MP4 is undecodable if
284 it is not properly finished), and it requires less memory when writing
285 very long files (since writing normal MOV/MP4 files stores info about
286 every single packet in memory until the file is closed). The downside
287 is that it is less compatible with other applications.
288
289 Fragmentation is enabled by setting one of the AVOptions that define
290 how to cut the file into fragments:
291
292 @table @option
293 @item -movflags frag_keyframe
294 Start a new fragment at each video keyframe.
295 @item -frag_duration @var{duration}
296 Create fragments that are @var{duration} microseconds long.
297 @item -frag_size @var{size}
298 Create fragments that contain up to @var{size} bytes of payload data.
299 @item -movflags frag_custom
300 Allow the caller to manually choose when to cut fragments, by
301 calling @code{av_write_frame(ctx, NULL)} to write a fragment with
302 the packets written so far. (This is only useful with other
303 applications integrating libavformat, not from @command{avconv}.)
304 @item -min_frag_duration @var{duration}
305 Don't create fragments that are shorter than @var{duration} microseconds long.
306 @end table
307
308 If more than one condition is specified, fragments are cut when
309 one of the specified conditions is fulfilled. The exception to this is
310 @code{-min_frag_duration}, which has to be fulfilled for any of the other
311 conditions to apply.
312
313 Additionally, the way the output file is written can be adjusted
314 through a few other options:
315
316 @table @option
317 @item -movflags empty_moov
318 Write an initial moov atom directly at the start of the file, without
319 describing any samples in it. Generally, an mdat/moov pair is written
320 at the start of the file, as a normal MOV/MP4 file, containing only
321 a short portion of the file. With this option set, there is no initial
322 mdat atom, and the moov atom only describes the tracks but has
323 a zero duration.
324
325 This option is implicitly set when writing ismv (Smooth Streaming) files.
326 @item -movflags separate_moof
327 Write a separate moof (movie fragment) atom for each track. Normally,
328 packets for all tracks are written in a moof atom (which is slightly
329 more efficient), but with this option set, the muxer writes one moof/mdat
330 pair for each track, making it easier to separate tracks.
331
332 This option is implicitly set when writing ismv (Smooth Streaming) files.
333 @item -movflags faststart
334 Run a second pass moving the index (moov atom) to the beginning of the file.
335 This operation can take a while, and will not work in various situations such
336 as fragmented output, thus it is not enabled by default.
337 @item -movflags disable_chpl
338 Disable Nero chapter markers (chpl atom).  Normally, both Nero chapters
339 and a QuickTime chapter track are written to the file. With this option
340 set, only the QuickTime chapter track will be written. Nero chapters can
341 cause failures when the file is reprocessed with certain tagging programs.
342 @item -movflags omit_tfhd_offset
343 Do not write any absolute base_data_offset in tfhd atoms. This avoids
344 tying fragments to absolute byte positions in the file/streams.
345 @item -movflags default_base_moof
346 Similarly to the omit_tfhd_offset, this flag avoids writing the
347 absolute base_data_offset field in tfhd atoms, but does so by using
348 the new default-base-is-moof flag instead. This flag is new from
349 14496-12:2012. This may make the fragments easier to parse in certain
350 circumstances (avoiding basing track fragment location calculations
351 on the implicit end of the previous track fragment).
352 @end table
353
354 Smooth Streaming content can be pushed in real time to a publishing
355 point on IIS with this muxer. Example:
356 @example
357 avconv -re @var{<normal input/transcoding options>} -movflags isml+frag_keyframe -f ismv http://server/publishingpoint.isml/Streams(Encoder1)
358 @end example
359
360 @section mp3
361
362 The MP3 muxer writes a raw MP3 stream with the following optional features:
363 @itemize @bullet
364 @item
365 An ID3v2 metadata header at the beginning (enabled by default). Versions 2.3 and
366 2.4 are supported, the @code{id3v2_version} private option controls which one is
367 used (3 or 4). Setting @code{id3v2_version} to 0 disables the ID3v2 header
368 completely.
369
370 The muxer supports writing attached pictures (APIC frames) to the ID3v2 header.
371 The pictures are supplied to the muxer in form of a video stream with a single
372 packet. There can be any number of those streams, each will correspond to a
373 single APIC frame.  The stream metadata tags @var{title} and @var{comment} map
374 to APIC @var{description} and @var{picture type} respectively. See
375 @url{http://id3.org/id3v2.4.0-frames} for allowed picture types.
376
377 Note that the APIC frames must be written at the beginning, so the muxer will
378 buffer the audio frames until it gets all the pictures. It is therefore advised
379 to provide the pictures as soon as possible to avoid excessive buffering.
380
381 @item
382 A Xing/LAME frame right after the ID3v2 header (if present). It is enabled by
383 default, but will be written only if the output is seekable. The
384 @code{write_xing} private option can be used to disable it.  The frame contains
385 various information that may be useful to the decoder, like the audio duration
386 or encoder delay.
387
388 @item
389 A legacy ID3v1 tag at the end of the file (disabled by default). It may be
390 enabled with the @code{write_id3v1} private option, but as its capabilities are
391 very limited, its usage is not recommended.
392 @end itemize
393
394 Examples:
395
396 Write an mp3 with an ID3v2.3 header and an ID3v1 footer:
397 @example
398 avconv -i INPUT -id3v2_version 3 -write_id3v1 1 out.mp3
399 @end example
400
401 Attach a picture to an mp3:
402 @example
403 avconv -i input.mp3 -i cover.png -c copy -metadata:s:v title="Album cover"
404 -metadata:s:v comment="Cover (Front)" out.mp3
405 @end example
406
407 Write a "clean" MP3 without any extra features:
408 @example
409 avconv -i input.wav -write_xing 0 -id3v2_version 0 out.mp3
410 @end example
411
412 @section mpegts
413
414 MPEG transport stream muxer.
415
416 This muxer implements ISO 13818-1 and part of ETSI EN 300 468.
417
418 The muxer options are:
419
420 @table @option
421 @item -mpegts_original_network_id @var{number}
422 Set the original_network_id (default 0x0001). This is unique identifier
423 of a network in DVB. Its main use is in the unique identification of a
424 service through the path Original_Network_ID, Transport_Stream_ID.
425 @item -mpegts_transport_stream_id @var{number}
426 Set the transport_stream_id (default 0x0001). This identifies a
427 transponder in DVB.
428 @item -mpegts_service_id @var{number}
429 Set the service_id (default 0x0001) also known as program in DVB.
430 @item -mpegts_pmt_start_pid @var{number}
431 Set the first PID for PMT (default 0x1000, max 0x1f00).
432 @item -mpegts_start_pid @var{number}
433 Set the first PID for data packets (default 0x0100, max 0x0f00).
434 @item -muxrate @var{number}
435 Set a constant muxrate (default VBR).
436 @item -pcr_period @var{numer}
437 Override the default PCR retransmission time (default 20ms), ignored
438 if variable muxrate is selected.
439 @end table
440
441 The recognized metadata settings in mpegts muxer are @code{service_provider}
442 and @code{service_name}. If they are not set the default for
443 @code{service_provider} is "Libav" and the default for
444 @code{service_name} is "Service01".
445
446 @example
447 avconv -i file.mpg -c copy \
448      -mpegts_original_network_id 0x1122 \
449      -mpegts_transport_stream_id 0x3344 \
450      -mpegts_service_id 0x5566 \
451      -mpegts_pmt_start_pid 0x1500 \
452      -mpegts_start_pid 0x150 \
453      -metadata service_provider="Some provider" \
454      -metadata service_name="Some Channel" \
455      -y out.ts
456 @end example
457
458 @section null
459
460 Null muxer.
461
462 This muxer does not generate any output file, it is mainly useful for
463 testing or benchmarking purposes.
464
465 For example to benchmark decoding with @command{avconv} you can use the
466 command:
467 @example
468 avconv -benchmark -i INPUT -f null out.null
469 @end example
470
471 Note that the above command does not read or write the @file{out.null}
472 file, but specifying the output file is required by the @command{avconv}
473 syntax.
474
475 Alternatively you can write the command as:
476 @example
477 avconv -benchmark -i INPUT -f null -
478 @end example
479
480 @section nut
481
482 @table @option
483 @item -syncpoints @var{flags}
484 Change the syncpoint usage in nut:
485 @table @option
486 @item @var{default} use the normal low-overhead seeking aids.
487 @item @var{none} do not use the syncpoints at all, reducing the overhead but making the stream non-seekable;
488 @item @var{timestamped} extend the syncpoint with a wallclock field.
489 @end table
490 The @var{none} and @var{timestamped} flags are experimental.
491 @end table
492
493 @example
494 avconv -i INPUT -f_strict experimental -syncpoints none - | processor
495 @end example
496
497 @section ogg
498
499 Ogg container muxer.
500
501 @table @option
502 @item -page_duration @var{duration}
503 Preferred page duration, in microseconds. The muxer will attempt to create
504 pages that are approximately @var{duration} microseconds long. This allows the
505 user to compromise between seek granularity and container overhead. The default
506 is 1 second. A value of 0 will fill all segments, making pages as large as
507 possible. A value of 1 will effectively use 1 packet-per-page in most
508 situations, giving a small seek granularity at the cost of additional container
509 overhead.
510 @item -serial_offset @var{value}
511 Serial value from which to set the streams serial number.
512 Setting it to different and sufficiently large values ensures that the produced
513 ogg files can be safely chained.
514
515 @end table
516
517 @section segment
518
519 Basic stream segmenter.
520
521 The segmenter muxer outputs streams to a number of separate files of nearly
522 fixed duration. Output filename pattern can be set in a fashion similar to
523 @ref{image2}.
524
525 Every segment starts with a video keyframe, if a video stream is present.
526 The segment muxer works best with a single constant frame rate video.
527
528 Optionally it can generate a flat list of the created segments, one segment
529 per line.
530
531 @table @option
532 @item segment_format @var{format}
533 Override the inner container format, by default it is guessed by the filename
534 extension.
535 @item segment_time @var{t}
536 Set segment duration to @var{t} seconds.
537 @item segment_list @var{name}
538 Generate also a listfile named @var{name}.
539 @item segment_list_type @var{type}
540 Select the listing format.
541 @table @option
542 @item @var{flat} use a simple flat list of entries.
543 @item @var{hls} use a m3u8-like structure.
544 @end table
545 @item segment_list_size @var{size}
546 Overwrite the listfile once it reaches @var{size} entries.
547 @item segment_list_entry_prefix @var{prefix}
548 Prepend @var{prefix} to each entry. Useful to generate absolute paths.
549 @item segment_wrap @var{limit}
550 Wrap around segment index once it reaches @var{limit}.
551 @end table
552
553 @example
554 avconv -i in.mkv -c copy -map 0 -f segment -list out.list out%03d.nut
555 @end example
556
557 @c man end MUXERS