]> git.sesse.net Git - ffmpeg/blob - doc/bitstream_filters.texi
Merge commit '4cf84e254ae75b524e1cacae499a97d7cc9e5906'
[ffmpeg] / doc / bitstream_filters.texi
1 @chapter Bitstream Filters
2 @c man begin BITSTREAM FILTERS
3
4 When you configure your FFmpeg build, all the supported bitstream
5 filters are enabled by default. You can list all available ones using
6 the configure option @code{--list-bsfs}.
7
8 You can disable all the bitstream filters using the configure option
9 @code{--disable-bsfs}, and selectively enable any bitstream filter using
10 the option @code{--enable-bsf=BSF}, or you can disable a particular
11 bitstream filter using the option @code{--disable-bsf=BSF}.
12
13 The option @code{-bsfs} of the ff* tools will display the list of
14 all the supported bitstream filters included in your build.
15
16 The ff* tools have a -bsf option applied per stream, taking a
17 comma-separated list of filters, whose parameters follow the filter
18 name after a '='.
19
20 @example
21 ffmpeg -i INPUT -c:v copy -bsf:v filter1[=opt1=str1:opt2=str2][,filter2] OUTPUT
22 @end example
23
24 Below is a description of the currently available bitstream filters,
25 with their parameters, if any.
26
27 @section aac_adtstoasc
28
29 Convert MPEG-2/4 AAC ADTS to an MPEG-4 Audio Specific Configuration
30 bitstream.
31
32 This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
33 ADTS header and removes the ADTS header.
34
35 This filter is required for example when copying an AAC stream from a
36 raw ADTS AAC or an MPEG-TS container to MP4A-LATM, to an FLV file, or
37 to MOV/MP4 files and related formats such as 3GP or M4A. Please note
38 that it is auto-inserted for MP4A-LATM and MOV/MP4 and related formats.
39
40 @section chomp
41
42 Remove zero padding at the end of a packet.
43
44 @section dca_core
45
46 Extract the core from a DCA/DTS stream, dropping extensions such as
47 DTS-HD.
48
49 @section dump_extra
50
51 Add extradata to the beginning of the filtered packets.
52
53 The additional argument specifies which packets should be filtered.
54 It accepts the values:
55 @table @samp
56 @item a
57 add extradata to all key packets, but only if @var{local_header} is
58 set in the @option{flags2} codec context field
59
60 @item k
61 add extradata to all key packets
62
63 @item e
64 add extradata to all packets
65 @end table
66
67 If not specified it is assumed @samp{k}.
68
69 For example the following @command{ffmpeg} command forces a global
70 header (thus disabling individual packet headers) in the H.264 packets
71 generated by the @code{libx264} encoder, but corrects them by adding
72 the header stored in extradata to the key packets:
73 @example
74 ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
75 @end example
76
77 @section extract_extradata
78
79 Extract the in-band extradata.
80
81 Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers,
82 or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part
83 of the bitstream containing the coded frames) or "out of band" (e.g. on the
84 container level). This latter form is called "extradata" in FFmpeg terminology.
85
86 This bitstream filter detects the in-band headers and makes them available as
87 extradata.
88
89 @table @option
90 @item remove
91 When this option is enabled, the long-term headers are removed from the
92 bitstream after extraction.
93 @end table
94
95 @section h264_metadata
96
97 Modify metadata embedded in an H.264 stream.
98
99 @table @option
100 @item aud
101 Insert or remove AUD NAL units in all access units of the stream.
102
103 @table @samp
104 @item insert
105 @item remove
106 @end table
107
108 @item sample_aspect_ratio
109 Set the sample aspect ratio of the stream in the VUI parameters.
110
111 @item video_format
112 @item video_full_range_flag
113 Set the video format in the stream (see H.264 section E.2.1 and
114 table E-2).
115
116 @item colour_primaries
117 @item transfer_characteristics
118 @item matrix_coefficients
119 Set the colour description in the stream (see H.264 section E.2.1
120 and tables E-3, E-4 and E-5).
121
122 @item chroma_sample_loc_type
123 Set the chroma sample location in the stream (see H.264 section
124 E.2.1 and figure E-1).
125
126 @item tick_rate
127 Set the tick rate (num_units_in_tick / time_scale) in the VUI
128 parameters.  This is the smallest time unit representable in the
129 stream, and in many cases represents the field rate of the stream
130 (double the frame rate).
131 @item fixed_frame_rate_flag
132 Set whether the stream has fixed framerate - typically this indicates
133 that the framerate is exactly half the tick rate, but the exact
134 meaning is dependent on interlacing and the picture structure (see
135 H.264 section E.2.1 and table E-6).
136
137 @item crop_left
138 @item crop_right
139 @item crop_top
140 @item crop_bottom
141 Set the frame cropping offsets in the SPS.  These values will replace
142 the current ones if the stream is already cropped.
143
144 These fields are set in pixels.  Note that some sizes may not be
145 representable if the chroma is subsampled or the stream is interlaced
146 (see H.264 section 7.4.2.1.1).
147
148 @item sei_user_data
149 Insert a string as SEI unregistered user data.  The argument must
150 be of the form @emph{UUID+string}, where the UUID is as hex digits
151 possibly separated by hyphens, and the string can be anything.
152
153 For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
154 insert the string ``hello'' associated with the given UUID.
155
156 @end table
157
158 @section h264_mp4toannexb
159
160 Convert an H.264 bitstream from length prefixed mode to start code
161 prefixed mode (as defined in the Annex B of the ITU-T H.264
162 specification).
163
164 This is required by some streaming formats, typically the MPEG-2
165 transport stream format (muxer @code{mpegts}).
166
167 For example to remux an MP4 file containing an H.264 stream to mpegts
168 format with @command{ffmpeg}, you can use the command:
169
170 @example
171 ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
172 @end example
173
174 Please note that this filter is auto-inserted for MPEG-TS (muxer
175 @code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
176
177 @section h264_redundant_pps
178
179 This applies a specific fixup to some Blu-ray streams which contain
180 redundant PPSs modifying irrelevant parameters of the stream which
181 confuse other transformations which require correct extradata.
182
183 A new single global PPS is created, and all of the redundant PPSs
184 within the stream are removed.
185
186 @section hevc_metadata
187
188 Modify metadata embedded in an HEVC stream.
189
190 @table @option
191 @item aud
192 Insert or remove AUD NAL units in all access units of the stream.
193
194 @table @samp
195 @item insert
196 @item remove
197 @end table
198
199 @item sample_aspect_ratio
200 Set the sample aspect ratio in the stream in the VUI parameters.
201
202 @item video_format
203 @item video_full_range_flag
204 Set the video format in the stream (see H.265 section E.3.1 and
205 table E.2).
206
207 @item colour_primaries
208 @item transfer_characteristics
209 @item matrix_coefficients
210 Set the colour description in the stream (see H.265 section E.3.1
211 and tables E.3, E.4 and E.5).
212
213 @item chroma_sample_loc_type
214 Set the chroma sample location in the stream (see H.265 section
215 E.3.1 and figure E.1).
216
217 @item tick_rate
218 Set the tick rate in the VPS and VUI parameters (num_units_in_tick /
219 time_scale).  Combined with @option{num_ticks_poc_diff_one}, this can
220 set a constant framerate in the stream.  Note that it is likely to be
221 overridden by container parameters when the stream is in a container.
222
223 @item num_ticks_poc_diff_one
224 Set poc_proportional_to_timing_flag in VPS and VUI and use this value
225 to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
226 E.3.1).  Ignored if @option{tick_rate} is not also set.
227
228 @item crop_left
229 @item crop_right
230 @item crop_top
231 @item crop_bottom
232 Set the conformance window cropping offsets in the SPS.  These values
233 will replace the current ones if the stream is already cropped.
234
235 These fields are set in pixels.  Note that some sizes may not be
236 representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
237
238 @end table
239
240 @section hevc_mp4toannexb
241
242 Convert an HEVC/H.265 bitstream from length prefixed mode to start code
243 prefixed mode (as defined in the Annex B of the ITU-T H.265
244 specification).
245
246 This is required by some streaming formats, typically the MPEG-2
247 transport stream format (muxer @code{mpegts}).
248
249 For example to remux an MP4 file containing an HEVC stream to mpegts
250 format with @command{ffmpeg}, you can use the command:
251
252 @example
253 ffmpeg -i INPUT.mp4 -codec copy -bsf:v hevc_mp4toannexb OUTPUT.ts
254 @end example
255
256 Please note that this filter is auto-inserted for MPEG-TS (muxer
257 @code{mpegts}) and raw HEVC/H.265 (muxer @code{h265} or
258 @code{hevc}) output formats.
259
260 @section imxdump
261
262 Modifies the bitstream to fit in MOV and to be usable by the Final Cut
263 Pro decoder. This filter only applies to the mpeg2video codec, and is
264 likely not needed for Final Cut Pro 7 and newer with the appropriate
265 @option{-tag:v}.
266
267 For example, to remux 30 MB/sec NTSC IMX to MOV:
268
269 @example
270 ffmpeg -i input.mxf -c copy -bsf:v imxdump -tag:v mx3n output.mov
271 @end example
272
273 @section mjpeg2jpeg
274
275 Convert MJPEG/AVI1 packets to full JPEG/JFIF packets.
276
277 MJPEG is a video codec wherein each video frame is essentially a
278 JPEG image. The individual frames can be extracted without loss,
279 e.g. by
280
281 @example
282 ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg
283 @end example
284
285 Unfortunately, these chunks are incomplete JPEG images, because
286 they lack the DHT segment required for decoding. Quoting from
287 @url{http://www.digitalpreservation.gov/formats/fdd/fdd000063.shtml}:
288
289 Avery Lee, writing in the rec.video.desktop newsgroup in 2001,
290 commented that "MJPEG, or at least the MJPEG in AVIs having the
291 MJPG fourcc, is restricted JPEG with a fixed -- and *omitted* --
292 Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2,
293 and it must use basic Huffman encoding, not arithmetic or
294 progressive. . . . You can indeed extract the MJPEG frames and
295 decode them with a regular JPEG decoder, but you have to prepend
296 the DHT segment to them, or else the decoder won't have any idea
297 how to decompress the data. The exact table necessary is given in
298 the OpenDML spec."
299
300 This bitstream filter patches the header of frames extracted from an MJPEG
301 stream (carrying the AVI1 header ID and lacking a DHT segment) to
302 produce fully qualified JPEG images.
303
304 @example
305 ffmpeg -i mjpeg-movie.avi -c:v copy -bsf:v mjpeg2jpeg frame_%d.jpg
306 exiftran -i -9 frame*.jpg
307 ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
308 @end example
309
310 @section mjpegadump
311
312 Add an MJPEG A header to the bitstream, to enable decoding by
313 Quicktime.
314
315 @anchor{mov2textsub}
316 @section mov2textsub
317
318 Extract a representable text file from MOV subtitles, stripping the
319 metadata header from each subtitle packet.
320
321 See also the @ref{text2movsub} filter.
322
323 @section mp3decomp
324
325 Decompress non-standard compressed MP3 audio headers.
326
327 @section mpeg2_metadata
328
329 Modify metadata embedded in an MPEG-2 stream.
330
331 @table @option
332 @item display_aspect_ratio
333 Set the display aspect ratio in the stream.
334
335 The following fixed values are supported:
336 @table @option
337 @item 4/3
338 @item 16/9
339 @item 221/100
340 @end table
341 Any other value will result in square pixels being signalled instead
342 (see H.262 section 6.3.3 and table 6-3).
343
344 @item frame_rate
345 Set the frame rate in the stream.  This is constructed from a table
346 of known values combined with a small multiplier and divisor - if
347 the supplied value is not exactly representable, the nearest
348 representable value will be used instead (see H.262 section 6.3.3
349 and table 6-4).
350
351 @item video_format
352 Set the video format in the stream (see H.262 section 6.3.6 and
353 table 6-6).
354
355 @item colour_primaries
356 @item transfer_characteristics
357 @item matrix_coefficients
358 Set the colour description in the stream (see H.262 section 6.3.6
359 and tables 6-7, 6-8 and 6-9).
360
361 @end table
362
363 @section mpeg4_unpack_bframes
364
365 Unpack DivX-style packed B-frames.
366
367 DivX-style packed B-frames are not valid MPEG-4 and were only a
368 workaround for the broken Video for Windows subsystem.
369 They use more space, can cause minor AV sync issues, require more
370 CPU power to decode (unless the player has some decoded picture queue
371 to compensate the 2,0,2,0 frame per packet style) and cause
372 trouble if copied into a standard container like mp4 or mpeg-ps/ts,
373 because MPEG-4 decoders may not be able to decode them, since they are
374 not valid MPEG-4.
375
376 For example to fix an AVI file containing an MPEG-4 stream with
377 DivX-style packed B-frames using @command{ffmpeg}, you can use the command:
378
379 @example
380 ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
381 @end example
382
383 @section noise
384
385 Damages the contents of packets or simply drops them without damaging the
386 container. Can be used for fuzzing or testing error resilience/concealment.
387
388 Parameters:
389 @table @option
390 @item amount
391 A numeral string, whose value is related to how often output bytes will
392 be modified. Therefore, values below or equal to 0 are forbidden, and
393 the lower the more frequent bytes will be modified, with 1 meaning
394 every byte is modified.
395 @item dropamount
396 A numeral string, whose value is related to how often packets will be dropped.
397 Therefore, values below or equal to 0 are forbidden, and the lower the more
398 frequent packets will be dropped, with 1 meaning every packet is dropped.
399 @end table
400
401 The following example applies the modification to every byte but does not drop
402 any packets.
403 @example
404 ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
405 @end example
406
407 @section null
408 This bitstream filter passes the packets through unchanged.
409
410 @section remove_extra
411
412 Remove extradata from packets.
413
414 It accepts the following parameter:
415 @table @option
416 @item freq
417 Set which frame types to remove extradata from.
418
419 @table @samp
420 @item k
421 Remove extradata from non-keyframes only.
422
423 @item keyframe
424 Remove extradata from keyframes only.
425
426 @item e, all
427 Remove extradata from all frames.
428
429 @end table
430 @end table
431
432 @anchor{text2movsub}
433 @section text2movsub
434
435 Convert text subtitles to MOV subtitles (as used by the @code{mov_text}
436 codec) with metadata headers.
437
438 See also the @ref{mov2textsub} filter.
439
440 @section trace_headers
441
442 Log trace output containing all syntax elements in the coded stream
443 headers (everything above the level of individual coded blocks).
444 This can be useful for debugging low-level stream issues.
445
446 Supports H.264, H.265 and MPEG-2.
447
448 @section vp9_superframe
449
450 Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
451 fixes merging of split/segmented VP9 streams where the alt-ref frame
452 was split from its visible counterpart.
453
454 @section vp9_superframe_split
455
456 Split VP9 superframes into single frames.
457
458 @section vp9_raw_reorder
459
460 Given a VP9 stream with correct timestamps but possibly out of order,
461 insert additional show-existing-frame packets to correct the ordering.
462
463 @c man end BITSTREAM FILTERS