]> git.sesse.net Git - ffmpeg/blob - doc/bitstream_filters.texi
doc/filters: update URL for sr filter script repository
[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 av1_metadata
41
42 Modify metadata embedded in an AV1 stream.
43
44 @table @option
45 @item td
46 Insert or remove temporal delimiter OBUs in all temporal units of the
47 stream.
48
49 @table @samp
50 @item insert
51 Insert a TD at the beginning of every TU which does not already have one.
52 @item remove
53 Remove the TD from the beginning of every TU which has one.
54 @end table
55
56 @item color_primaries
57 @item transfer_characteristics
58 @item matrix_coefficients
59 Set the color description fields in the stream (see AV1 section 6.4.2).
60
61 @item color_range
62 Set the color range in the stream (see AV1 section 6.4.2; note that
63 this cannot be set for streams using BT.709 primaries, sRGB transfer
64 characteristic and identity (RGB) matrix coefficients).
65 @table @samp
66 @item tv
67 Limited range.
68 @item pc
69 Full range.
70 @end table
71
72 @item chroma_sample_position
73 Set the chroma sample location in the stream (see AV1 section 6.4.2).
74 This can only be set for 4:2:0 streams.
75
76 @table @samp
77 @item vertical
78 Left position (matching the default in MPEG-2 and H.264).
79 @item colocated
80 Top-left position.
81 @end table
82
83 @item tick_rate
84 Set the tick rate (@emph{num_units_in_display_tick / time_scale}) in
85 the timing info in the sequence header.
86 @item num_ticks_per_picture
87 Set the number of ticks in each picture, to indicate that the stream
88 has a fixed framerate.  Ignored if @option{tick_rate} is not also set.
89
90 @item delete_padding
91 Deletes Padding OBUs.
92
93 @end table
94
95 @section chomp
96
97 Remove zero padding at the end of a packet.
98
99 @section dca_core
100
101 Extract the core from a DCA/DTS stream, dropping extensions such as
102 DTS-HD.
103
104 @section dump_extra
105
106 Add extradata to the beginning of the filtered packets.
107
108 @table @option
109 @item freq
110 The additional argument specifies which packets should be filtered.
111 It accepts the values:
112 @table @samp
113 @item k
114 @item keyframe
115 add extradata to all key packets
116
117 @item e
118 @item all
119 add extradata to all packets
120 @end table
121 @end table
122
123 If not specified it is assumed @samp{e}.
124
125 For example the following @command{ffmpeg} command forces a global
126 header (thus disabling individual packet headers) in the H.264 packets
127 generated by the @code{libx264} encoder, but corrects them by adding
128 the header stored in extradata to the key packets:
129 @example
130 ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
131 @end example
132
133 @section eac3_core
134
135 Extract the core from a E-AC-3 stream, dropping extra channels.
136
137 @section extract_extradata
138
139 Extract the in-band extradata.
140
141 Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers,
142 or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part
143 of the bitstream containing the coded frames) or "out of band" (e.g. on the
144 container level). This latter form is called "extradata" in FFmpeg terminology.
145
146 This bitstream filter detects the in-band headers and makes them available as
147 extradata.
148
149 @table @option
150 @item remove
151 When this option is enabled, the long-term headers are removed from the
152 bitstream after extraction.
153 @end table
154
155 @section filter_units
156
157 Remove units with types in or not in a given set from the stream.
158
159 @table @option
160 @item pass_types
161 List of unit types or ranges of unit types to pass through while removing
162 all others.  This is specified as a '|'-separated list of unit type values
163 or ranges of values with '-'.
164
165 @item remove_types
166 Identical to @option{pass_types}, except the units in the given set
167 removed and all others passed through.
168 @end table
169
170 Extradata is unchanged by this transformation, but note that if the stream
171 contains inline parameter sets then the output may be unusable if they are
172 removed.
173
174 For example, to remove all non-VCL NAL units from an H.264 stream:
175 @example
176 ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=pass_types=1-5' OUTPUT
177 @end example
178
179 To remove all AUDs, SEI and filler from an H.265 stream:
180 @example
181 ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=35|38-40' OUTPUT
182 @end example
183
184 @section hapqa_extract
185
186 Extract Rgb or Alpha part of an HAPQA file, without recompression, in order to create an HAPQ or an HAPAlphaOnly file.
187
188 @table @option
189 @item texture
190 Specifies the texture to keep.
191
192 @table @option
193 @item color
194 @item alpha
195 @end table
196
197 @end table
198
199 Convert HAPQA to HAPQ
200 @example
201 ffmpeg -i hapqa_inputfile.mov -c copy -bsf:v hapqa_extract=texture=color -tag:v HapY -metadata:s:v:0 encoder="HAPQ" hapq_file.mov
202 @end example
203
204 Convert HAPQA to HAPAlphaOnly
205 @example
206 ffmpeg -i hapqa_inputfile.mov -c copy -bsf:v hapqa_extract=texture=alpha -tag:v HapA -metadata:s:v:0 encoder="HAPAlpha Only" hapalphaonly_file.mov
207 @end example
208
209 @section h264_metadata
210
211 Modify metadata embedded in an H.264 stream.
212
213 @table @option
214 @item aud
215 Insert or remove AUD NAL units in all access units of the stream.
216
217 @table @samp
218 @item insert
219 @item remove
220 @end table
221
222 @item sample_aspect_ratio
223 Set the sample aspect ratio of the stream in the VUI parameters.
224
225 @item video_format
226 @item video_full_range_flag
227 Set the video format in the stream (see H.264 section E.2.1 and
228 table E-2).
229
230 @item colour_primaries
231 @item transfer_characteristics
232 @item matrix_coefficients
233 Set the colour description in the stream (see H.264 section E.2.1
234 and tables E-3, E-4 and E-5).
235
236 @item chroma_sample_loc_type
237 Set the chroma sample location in the stream (see H.264 section
238 E.2.1 and figure E-1).
239
240 @item tick_rate
241 Set the tick rate (num_units_in_tick / time_scale) in the VUI
242 parameters.  This is the smallest time unit representable in the
243 stream, and in many cases represents the field rate of the stream
244 (double the frame rate).
245 @item fixed_frame_rate_flag
246 Set whether the stream has fixed framerate - typically this indicates
247 that the framerate is exactly half the tick rate, but the exact
248 meaning is dependent on interlacing and the picture structure (see
249 H.264 section E.2.1 and table E-6).
250
251 @item crop_left
252 @item crop_right
253 @item crop_top
254 @item crop_bottom
255 Set the frame cropping offsets in the SPS.  These values will replace
256 the current ones if the stream is already cropped.
257
258 These fields are set in pixels.  Note that some sizes may not be
259 representable if the chroma is subsampled or the stream is interlaced
260 (see H.264 section 7.4.2.1.1).
261
262 @item sei_user_data
263 Insert a string as SEI unregistered user data.  The argument must
264 be of the form @emph{UUID+string}, where the UUID is as hex digits
265 possibly separated by hyphens, and the string can be anything.
266
267 For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
268 insert the string ``hello'' associated with the given UUID.
269
270 @item delete_filler
271 Deletes both filler NAL units and filler SEI messages.
272
273 @item level
274 Set the level in the SPS.  Refer to H.264 section A.3 and tables A-1
275 to A-5.
276
277 The argument must be the name of a level (for example, @samp{4.2}), a
278 level_idc value (for example, @samp{42}), or the special name @samp{auto}
279 indicating that the filter should attempt to guess the level from the
280 input stream properties.
281
282 @end table
283
284 @section h264_mp4toannexb
285
286 Convert an H.264 bitstream from length prefixed mode to start code
287 prefixed mode (as defined in the Annex B of the ITU-T H.264
288 specification).
289
290 This is required by some streaming formats, typically the MPEG-2
291 transport stream format (muxer @code{mpegts}).
292
293 For example to remux an MP4 file containing an H.264 stream to mpegts
294 format with @command{ffmpeg}, you can use the command:
295
296 @example
297 ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
298 @end example
299
300 Please note that this filter is auto-inserted for MPEG-TS (muxer
301 @code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
302
303 @section h264_redundant_pps
304
305 This applies a specific fixup to some Blu-ray streams which contain
306 redundant PPSs modifying irrelevant parameters of the stream which
307 confuse other transformations which require correct extradata.
308
309 A new single global PPS is created, and all of the redundant PPSs
310 within the stream are removed.
311
312 @section hevc_metadata
313
314 Modify metadata embedded in an HEVC stream.
315
316 @table @option
317 @item aud
318 Insert or remove AUD NAL units in all access units of the stream.
319
320 @table @samp
321 @item insert
322 @item remove
323 @end table
324
325 @item sample_aspect_ratio
326 Set the sample aspect ratio in the stream in the VUI parameters.
327
328 @item video_format
329 @item video_full_range_flag
330 Set the video format in the stream (see H.265 section E.3.1 and
331 table E.2).
332
333 @item colour_primaries
334 @item transfer_characteristics
335 @item matrix_coefficients
336 Set the colour description in the stream (see H.265 section E.3.1
337 and tables E.3, E.4 and E.5).
338
339 @item chroma_sample_loc_type
340 Set the chroma sample location in the stream (see H.265 section
341 E.3.1 and figure E.1).
342
343 @item tick_rate
344 Set the tick rate in the VPS and VUI parameters (num_units_in_tick /
345 time_scale).  Combined with @option{num_ticks_poc_diff_one}, this can
346 set a constant framerate in the stream.  Note that it is likely to be
347 overridden by container parameters when the stream is in a container.
348
349 @item num_ticks_poc_diff_one
350 Set poc_proportional_to_timing_flag in VPS and VUI and use this value
351 to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
352 E.3.1).  Ignored if @option{tick_rate} is not also set.
353
354 @item crop_left
355 @item crop_right
356 @item crop_top
357 @item crop_bottom
358 Set the conformance window cropping offsets in the SPS.  These values
359 will replace the current ones if the stream is already cropped.
360
361 These fields are set in pixels.  Note that some sizes may not be
362 representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
363
364 @end table
365
366 @section hevc_mp4toannexb
367
368 Convert an HEVC/H.265 bitstream from length prefixed mode to start code
369 prefixed mode (as defined in the Annex B of the ITU-T H.265
370 specification).
371
372 This is required by some streaming formats, typically the MPEG-2
373 transport stream format (muxer @code{mpegts}).
374
375 For example to remux an MP4 file containing an HEVC stream to mpegts
376 format with @command{ffmpeg}, you can use the command:
377
378 @example
379 ffmpeg -i INPUT.mp4 -codec copy -bsf:v hevc_mp4toannexb OUTPUT.ts
380 @end example
381
382 Please note that this filter is auto-inserted for MPEG-TS (muxer
383 @code{mpegts}) and raw HEVC/H.265 (muxer @code{h265} or
384 @code{hevc}) output formats.
385
386 @section imxdump
387
388 Modifies the bitstream to fit in MOV and to be usable by the Final Cut
389 Pro decoder. This filter only applies to the mpeg2video codec, and is
390 likely not needed for Final Cut Pro 7 and newer with the appropriate
391 @option{-tag:v}.
392
393 For example, to remux 30 MB/sec NTSC IMX to MOV:
394
395 @example
396 ffmpeg -i input.mxf -c copy -bsf:v imxdump -tag:v mx3n output.mov
397 @end example
398
399 @section mjpeg2jpeg
400
401 Convert MJPEG/AVI1 packets to full JPEG/JFIF packets.
402
403 MJPEG is a video codec wherein each video frame is essentially a
404 JPEG image. The individual frames can be extracted without loss,
405 e.g. by
406
407 @example
408 ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg
409 @end example
410
411 Unfortunately, these chunks are incomplete JPEG images, because
412 they lack the DHT segment required for decoding. Quoting from
413 @url{http://www.digitalpreservation.gov/formats/fdd/fdd000063.shtml}:
414
415 Avery Lee, writing in the rec.video.desktop newsgroup in 2001,
416 commented that "MJPEG, or at least the MJPEG in AVIs having the
417 MJPG fourcc, is restricted JPEG with a fixed -- and *omitted* --
418 Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2,
419 and it must use basic Huffman encoding, not arithmetic or
420 progressive. . . . You can indeed extract the MJPEG frames and
421 decode them with a regular JPEG decoder, but you have to prepend
422 the DHT segment to them, or else the decoder won't have any idea
423 how to decompress the data. The exact table necessary is given in
424 the OpenDML spec."
425
426 This bitstream filter patches the header of frames extracted from an MJPEG
427 stream (carrying the AVI1 header ID and lacking a DHT segment) to
428 produce fully qualified JPEG images.
429
430 @example
431 ffmpeg -i mjpeg-movie.avi -c:v copy -bsf:v mjpeg2jpeg frame_%d.jpg
432 exiftran -i -9 frame*.jpg
433 ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
434 @end example
435
436 @section mjpegadump
437
438 Add an MJPEG A header to the bitstream, to enable decoding by
439 Quicktime.
440
441 @anchor{mov2textsub}
442 @section mov2textsub
443
444 Extract a representable text file from MOV subtitles, stripping the
445 metadata header from each subtitle packet.
446
447 See also the @ref{text2movsub} filter.
448
449 @section mp3decomp
450
451 Decompress non-standard compressed MP3 audio headers.
452
453 @section mpeg2_metadata
454
455 Modify metadata embedded in an MPEG-2 stream.
456
457 @table @option
458 @item display_aspect_ratio
459 Set the display aspect ratio in the stream.
460
461 The following fixed values are supported:
462 @table @option
463 @item 4/3
464 @item 16/9
465 @item 221/100
466 @end table
467 Any other value will result in square pixels being signalled instead
468 (see H.262 section 6.3.3 and table 6-3).
469
470 @item frame_rate
471 Set the frame rate in the stream.  This is constructed from a table
472 of known values combined with a small multiplier and divisor - if
473 the supplied value is not exactly representable, the nearest
474 representable value will be used instead (see H.262 section 6.3.3
475 and table 6-4).
476
477 @item video_format
478 Set the video format in the stream (see H.262 section 6.3.6 and
479 table 6-6).
480
481 @item colour_primaries
482 @item transfer_characteristics
483 @item matrix_coefficients
484 Set the colour description in the stream (see H.262 section 6.3.6
485 and tables 6-7, 6-8 and 6-9).
486
487 @end table
488
489 @section mpeg4_unpack_bframes
490
491 Unpack DivX-style packed B-frames.
492
493 DivX-style packed B-frames are not valid MPEG-4 and were only a
494 workaround for the broken Video for Windows subsystem.
495 They use more space, can cause minor AV sync issues, require more
496 CPU power to decode (unless the player has some decoded picture queue
497 to compensate the 2,0,2,0 frame per packet style) and cause
498 trouble if copied into a standard container like mp4 or mpeg-ps/ts,
499 because MPEG-4 decoders may not be able to decode them, since they are
500 not valid MPEG-4.
501
502 For example to fix an AVI file containing an MPEG-4 stream with
503 DivX-style packed B-frames using @command{ffmpeg}, you can use the command:
504
505 @example
506 ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
507 @end example
508
509 @section noise
510
511 Damages the contents of packets or simply drops them without damaging the
512 container. Can be used for fuzzing or testing error resilience/concealment.
513
514 Parameters:
515 @table @option
516 @item amount
517 A numeral string, whose value is related to how often output bytes will
518 be modified. Therefore, values below or equal to 0 are forbidden, and
519 the lower the more frequent bytes will be modified, with 1 meaning
520 every byte is modified.
521 @item dropamount
522 A numeral string, whose value is related to how often packets will be dropped.
523 Therefore, values below or equal to 0 are forbidden, and the lower the more
524 frequent packets will be dropped, with 1 meaning every packet is dropped.
525 @end table
526
527 The following example applies the modification to every byte but does not drop
528 any packets.
529 @example
530 ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
531 @end example
532
533 @section null
534 This bitstream filter passes the packets through unchanged.
535
536 @section prores_metadata
537
538 Modify color property metadata embedded in prores stream.
539
540 @table @option
541 @item color_primaries
542 Set the color primaries.
543 Available values are:
544
545 @table @samp
546 @item auto
547 Keep the same color primaries property (default).
548
549 @item unknown
550 @item bt709
551 @item bt470bg
552 BT601 625
553
554 @item smpte170m
555 BT601 525
556
557 @item bt2020
558 @item smpte431
559 DCI P3
560
561 @item smpte432
562 P3 D65
563
564 @end table
565
566 @item transfer_characteristics
567 Set the color transfer.
568 Available values are:
569
570 @table @samp
571 @item auto
572 Keep the same transfer characteristics property (default).
573
574 @item unknown
575 @item bt709
576 BT 601, BT 709, BT 2020
577 @end table
578
579
580 @item matrix_coefficients
581 Set the matrix coefficient.
582 Available values are:
583
584 @table @samp
585 @item auto
586 Keep the same transfer characteristics property (default).
587
588 @item unknown
589 @item bt709
590 @item smpte170m
591 BT 601
592
593 @item bt2020nc
594 @end table
595 @end table
596
597 Set Rec709 colorspace for each frame of the file
598 @example
599 ffmpeg -i INPUT -c copy -bsf:v prores_metadata=color_primaries=bt709:color_trc=bt709:colorspace=bt709 output.mov
600 @end example
601
602 @section remove_extra
603
604 Remove extradata from packets.
605
606 It accepts the following parameter:
607 @table @option
608 @item freq
609 Set which frame types to remove extradata from.
610
611 @table @samp
612 @item k
613 Remove extradata from non-keyframes only.
614
615 @item keyframe
616 Remove extradata from keyframes only.
617
618 @item e, all
619 Remove extradata from all frames.
620
621 @end table
622 @end table
623
624 @anchor{text2movsub}
625 @section text2movsub
626
627 Convert text subtitles to MOV subtitles (as used by the @code{mov_text}
628 codec) with metadata headers.
629
630 See also the @ref{mov2textsub} filter.
631
632 @section trace_headers
633
634 Log trace output containing all syntax elements in the coded stream
635 headers (everything above the level of individual coded blocks).
636 This can be useful for debugging low-level stream issues.
637
638 Supports AV1, H.264, H.265, (M)JPEG, MPEG-2 and VP9, but depending
639 on the build only a subset of these may be available.
640
641 @section truehd_core
642
643 Extract the core from a TrueHD stream, dropping ATMOS data.
644
645 @section vp9_metadata
646
647 Modify metadata embedded in a VP9 stream.
648
649 @table @option
650 @item color_space
651 Set the color space value in the frame header.
652 @table @samp
653 @item unknown
654 @item bt601
655 @item bt709
656 @item smpte170
657 @item smpte240
658 @item bt2020
659 @item rgb
660 @end table
661
662 @item color_range
663 Set the color range value in the frame header.  Note that this cannot
664 be set in RGB streams.
665 @table @samp
666 @item tv
667 @item pc
668 @end table
669 @end table
670
671 @section vp9_superframe
672
673 Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
674 fixes merging of split/segmented VP9 streams where the alt-ref frame
675 was split from its visible counterpart.
676
677 @section vp9_superframe_split
678
679 Split VP9 superframes into single frames.
680
681 @section vp9_raw_reorder
682
683 Given a VP9 stream with correct timestamps but possibly out of order,
684 insert additional show-existing-frame packets to correct the ordering.
685
686 @c man end BITSTREAM FILTERS