1 @chapter Bitstream Filters
2 @c man begin BITSTREAM FILTERS
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}.
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}.
13 The option @code{-bsfs} of the ff* tools will display the list of
14 all the supported bitstream filters included in your build.
16 The ff* tools have a -bsf option applied per stream, taking a
17 comma-separated list of filters, whose parameters follow the filter
21 ffmpeg -i INPUT -c:v copy -bsf:v filter1[=opt1=str1:opt2=str2][,filter2] OUTPUT
24 Below is a description of the currently available bitstream filters,
25 with their parameters, if any.
27 @section aac_adtstoasc
29 Convert MPEG-2/4 AAC ADTS to an MPEG-4 Audio Specific Configuration
32 This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
33 ADTS header and removes the ADTS header.
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.
42 Modify metadata embedded in an AV1 stream.
46 Insert or remove temporal delimiter OBUs in all temporal units of the
51 Insert a TD at the beginning of every TU which does not already have one.
53 Remove the TD from the beginning of every TU which has one.
57 @item transfer_characteristics
58 @item matrix_coefficients
59 Set the color description fields in the stream (see AV1 section 6.4.2).
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).
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.
78 Left position (matching the default in MPEG-2 and H.264).
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.
97 Remove zero padding at the end of a packet.
101 Extract the core from a DCA/DTS stream, dropping extensions such as
106 Add extradata to the beginning of the filtered packets except when
107 said packets already exactly begin with the extradata that is intended
112 The additional argument specifies which packets should be filtered.
113 It accepts the values:
117 add extradata to all key packets
121 add extradata to all packets
125 If not specified it is assumed @samp{k}.
127 For example the following @command{ffmpeg} command forces a global
128 header (thus disabling individual packet headers) in the H.264 packets
129 generated by the @code{libx264} encoder, but corrects them by adding
130 the header stored in extradata to the key packets:
132 ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
137 Extract the core from a E-AC-3 stream, dropping extra channels.
139 @section extract_extradata
141 Extract the in-band extradata.
143 Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers,
144 or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part
145 of the bitstream containing the coded frames) or "out of band" (e.g. on the
146 container level). This latter form is called "extradata" in FFmpeg terminology.
148 This bitstream filter detects the in-band headers and makes them available as
153 When this option is enabled, the long-term headers are removed from the
154 bitstream after extraction.
157 @section filter_units
159 Remove units with types in or not in a given set from the stream.
163 List of unit types or ranges of unit types to pass through while removing
164 all others. This is specified as a '|'-separated list of unit type values
165 or ranges of values with '-'.
168 Identical to @option{pass_types}, except the units in the given set
169 removed and all others passed through.
172 Extradata is unchanged by this transformation, but note that if the stream
173 contains inline parameter sets then the output may be unusable if they are
176 For example, to remove all non-VCL NAL units from an H.264 stream:
178 ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=pass_types=1-5' OUTPUT
181 To remove all AUDs, SEI and filler from an H.265 stream:
183 ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=35|38-40' OUTPUT
186 @section hapqa_extract
188 Extract Rgb or Alpha part of an HAPQA file, without recompression, in order to create an HAPQ or an HAPAlphaOnly file.
192 Specifies the texture to keep.
201 Convert HAPQA to HAPQ
203 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
206 Convert HAPQA to HAPAlphaOnly
208 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
211 @section h264_metadata
213 Modify metadata embedded in an H.264 stream.
217 Insert or remove AUD NAL units in all access units of the stream.
224 @item sample_aspect_ratio
225 Set the sample aspect ratio of the stream in the VUI parameters.
227 @item overscan_appropriate_flag
228 Set whether the stream is suitable for display using overscan
229 or not (see H.264 section E.2.1).
232 @item video_full_range_flag
233 Set the video format in the stream (see H.264 section E.2.1 and
236 @item colour_primaries
237 @item transfer_characteristics
238 @item matrix_coefficients
239 Set the colour description in the stream (see H.264 section E.2.1
240 and tables E-3, E-4 and E-5).
242 @item chroma_sample_loc_type
243 Set the chroma sample location in the stream (see H.264 section
244 E.2.1 and figure E-1).
247 Set the tick rate (num_units_in_tick / time_scale) in the VUI
248 parameters. This is the smallest time unit representable in the
249 stream, and in many cases represents the field rate of the stream
250 (double the frame rate).
251 @item fixed_frame_rate_flag
252 Set whether the stream has fixed framerate - typically this indicates
253 that the framerate is exactly half the tick rate, but the exact
254 meaning is dependent on interlacing and the picture structure (see
255 H.264 section E.2.1 and table E-6).
261 Set the frame cropping offsets in the SPS. These values will replace
262 the current ones if the stream is already cropped.
264 These fields are set in pixels. Note that some sizes may not be
265 representable if the chroma is subsampled or the stream is interlaced
266 (see H.264 section 7.4.2.1.1).
269 Insert a string as SEI unregistered user data. The argument must
270 be of the form @emph{UUID+string}, where the UUID is as hex digits
271 possibly separated by hyphens, and the string can be anything.
273 For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
274 insert the string ``hello'' associated with the given UUID.
277 Deletes both filler NAL units and filler SEI messages.
280 Set the level in the SPS. Refer to H.264 section A.3 and tables A-1
283 The argument must be the name of a level (for example, @samp{4.2}), a
284 level_idc value (for example, @samp{42}), or the special name @samp{auto}
285 indicating that the filter should attempt to guess the level from the
286 input stream properties.
290 @section h264_mp4toannexb
292 Convert an H.264 bitstream from length prefixed mode to start code
293 prefixed mode (as defined in the Annex B of the ITU-T H.264
296 This is required by some streaming formats, typically the MPEG-2
297 transport stream format (muxer @code{mpegts}).
299 For example to remux an MP4 file containing an H.264 stream to mpegts
300 format with @command{ffmpeg}, you can use the command:
303 ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
306 Please note that this filter is auto-inserted for MPEG-TS (muxer
307 @code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
309 @section h264_redundant_pps
311 This applies a specific fixup to some Blu-ray streams which contain
312 redundant PPSs modifying irrelevant parameters of the stream which
313 confuse other transformations which require correct extradata.
315 A new single global PPS is created, and all of the redundant PPSs
316 within the stream are removed.
318 @section hevc_metadata
320 Modify metadata embedded in an HEVC stream.
324 Insert or remove AUD NAL units in all access units of the stream.
331 @item sample_aspect_ratio
332 Set the sample aspect ratio in the stream in the VUI parameters.
335 @item video_full_range_flag
336 Set the video format in the stream (see H.265 section E.3.1 and
339 @item colour_primaries
340 @item transfer_characteristics
341 @item matrix_coefficients
342 Set the colour description in the stream (see H.265 section E.3.1
343 and tables E.3, E.4 and E.5).
345 @item chroma_sample_loc_type
346 Set the chroma sample location in the stream (see H.265 section
347 E.3.1 and figure E.1).
350 Set the tick rate in the VPS and VUI parameters (num_units_in_tick /
351 time_scale). Combined with @option{num_ticks_poc_diff_one}, this can
352 set a constant framerate in the stream. Note that it is likely to be
353 overridden by container parameters when the stream is in a container.
355 @item num_ticks_poc_diff_one
356 Set poc_proportional_to_timing_flag in VPS and VUI and use this value
357 to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
358 E.3.1). Ignored if @option{tick_rate} is not also set.
364 Set the conformance window cropping offsets in the SPS. These values
365 will replace the current ones if the stream is already cropped.
367 These fields are set in pixels. Note that some sizes may not be
368 representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
371 Set the level in the VPS and SPS. See H.265 section A.4 and tables
374 The argument must be the name of a level (for example, @samp{5.1}), a
375 @emph{general_level_idc} value (for example, @samp{153} for level 5.1),
376 or the special name @samp{auto} indicating that the filter should
377 attempt to guess the level from the input stream properties.
381 @section hevc_mp4toannexb
383 Convert an HEVC/H.265 bitstream from length prefixed mode to start code
384 prefixed mode (as defined in the Annex B of the ITU-T H.265
387 This is required by some streaming formats, typically the MPEG-2
388 transport stream format (muxer @code{mpegts}).
390 For example to remux an MP4 file containing an HEVC stream to mpegts
391 format with @command{ffmpeg}, you can use the command:
394 ffmpeg -i INPUT.mp4 -codec copy -bsf:v hevc_mp4toannexb OUTPUT.ts
397 Please note that this filter is auto-inserted for MPEG-TS (muxer
398 @code{mpegts}) and raw HEVC/H.265 (muxer @code{h265} or
399 @code{hevc}) output formats.
403 Modifies the bitstream to fit in MOV and to be usable by the Final Cut
404 Pro decoder. This filter only applies to the mpeg2video codec, and is
405 likely not needed for Final Cut Pro 7 and newer with the appropriate
408 For example, to remux 30 MB/sec NTSC IMX to MOV:
411 ffmpeg -i input.mxf -c copy -bsf:v imxdump -tag:v mx3n output.mov
416 Convert MJPEG/AVI1 packets to full JPEG/JFIF packets.
418 MJPEG is a video codec wherein each video frame is essentially a
419 JPEG image. The individual frames can be extracted without loss,
423 ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg
426 Unfortunately, these chunks are incomplete JPEG images, because
427 they lack the DHT segment required for decoding. Quoting from
428 @url{http://www.digitalpreservation.gov/formats/fdd/fdd000063.shtml}:
430 Avery Lee, writing in the rec.video.desktop newsgroup in 2001,
431 commented that "MJPEG, or at least the MJPEG in AVIs having the
432 MJPG fourcc, is restricted JPEG with a fixed -- and *omitted* --
433 Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2,
434 and it must use basic Huffman encoding, not arithmetic or
435 progressive. . . . You can indeed extract the MJPEG frames and
436 decode them with a regular JPEG decoder, but you have to prepend
437 the DHT segment to them, or else the decoder won't have any idea
438 how to decompress the data. The exact table necessary is given in
441 This bitstream filter patches the header of frames extracted from an MJPEG
442 stream (carrying the AVI1 header ID and lacking a DHT segment) to
443 produce fully qualified JPEG images.
446 ffmpeg -i mjpeg-movie.avi -c:v copy -bsf:v mjpeg2jpeg frame_%d.jpg
447 exiftran -i -9 frame*.jpg
448 ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
453 Add an MJPEG A header to the bitstream, to enable decoding by
459 Extract a representable text file from MOV subtitles, stripping the
460 metadata header from each subtitle packet.
462 See also the @ref{text2movsub} filter.
466 Decompress non-standard compressed MP3 audio headers.
468 @section mpeg2_metadata
470 Modify metadata embedded in an MPEG-2 stream.
473 @item display_aspect_ratio
474 Set the display aspect ratio in the stream.
476 The following fixed values are supported:
482 Any other value will result in square pixels being signalled instead
483 (see H.262 section 6.3.3 and table 6-3).
486 Set the frame rate in the stream. This is constructed from a table
487 of known values combined with a small multiplier and divisor - if
488 the supplied value is not exactly representable, the nearest
489 representable value will be used instead (see H.262 section 6.3.3
493 Set the video format in the stream (see H.262 section 6.3.6 and
496 @item colour_primaries
497 @item transfer_characteristics
498 @item matrix_coefficients
499 Set the colour description in the stream (see H.262 section 6.3.6
500 and tables 6-7, 6-8 and 6-9).
504 @section mpeg4_unpack_bframes
506 Unpack DivX-style packed B-frames.
508 DivX-style packed B-frames are not valid MPEG-4 and were only a
509 workaround for the broken Video for Windows subsystem.
510 They use more space, can cause minor AV sync issues, require more
511 CPU power to decode (unless the player has some decoded picture queue
512 to compensate the 2,0,2,0 frame per packet style) and cause
513 trouble if copied into a standard container like mp4 or mpeg-ps/ts,
514 because MPEG-4 decoders may not be able to decode them, since they are
517 For example to fix an AVI file containing an MPEG-4 stream with
518 DivX-style packed B-frames using @command{ffmpeg}, you can use the command:
521 ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
526 Damages the contents of packets or simply drops them without damaging the
527 container. Can be used for fuzzing or testing error resilience/concealment.
532 A numeral string, whose value is related to how often output bytes will
533 be modified. Therefore, values below or equal to 0 are forbidden, and
534 the lower the more frequent bytes will be modified, with 1 meaning
535 every byte is modified.
537 A numeral string, whose value is related to how often packets will be dropped.
538 Therefore, values below or equal to 0 are forbidden, and the lower the more
539 frequent packets will be dropped, with 1 meaning every packet is dropped.
542 The following example applies the modification to every byte but does not drop
545 ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
549 This bitstream filter passes the packets through unchanged.
553 Repacketize PCM audio to a fixed number of samples per packet or a fixed packet
554 rate per second. This is similar to the @ref{asetnsamples,,asetnsamples audio
555 filter,ffmpeg-filters} but works on audio packets instead of audio frames.
558 @item nb_out_samples, n
559 Set the number of samples per each output audio packet. The number is intended
560 as the number of samples @emph{per each channel}. Default value is 1024.
563 If set to 1, the filter will pad the last audio packet with silence, so that it
564 will contain the same number of samples (or roughly the same number of samples,
565 see @option{frame_rate}) as the previous ones. Default value is 1.
568 This option makes the filter output a fixed number of packets per second instead
569 of a fixed number of samples per packet. If the audio sample rate is not
570 divisible by the frame rate then the number of samples will not be constant but
571 will vary slightly so that each packet will start as close to the frame
572 boundary as possible. Using this option has precedence over @option{nb_out_samples}.
575 You can generate the well known 1602-1601-1602-1601-1602 pattern of 48kHz audio
576 for NTSC frame rate using the @option{frame_rate} option.
578 ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf pcm_rechunk=r=30000/1001 -f framecrc -
581 @section prores_metadata
583 Modify color property metadata embedded in prores stream.
586 @item color_primaries
587 Set the color primaries.
588 Available values are:
592 Keep the same color primaries property (default).
611 @item transfer_characteristics
612 Set the color transfer.
613 Available values are:
617 Keep the same transfer characteristics property (default).
621 BT 601, BT 709, BT 2020
629 @item matrix_coefficients
630 Set the matrix coefficient.
631 Available values are:
635 Keep the same colorspace property (default).
646 Set Rec709 colorspace for each frame of the file
648 ffmpeg -i INPUT -c copy -bsf:v prores_metadata=color_primaries=bt709:color_trc=bt709:colorspace=bt709 output.mov
651 Set Hybrid Log-Gamma parameters for each frame of the file
653 ffmpeg -i INPUT -c copy -bsf:v prores_metadata=color_primaries=bt2020:color_trc=arib-std-b67:colorspace=bt2020nc output.mov
656 @section remove_extra
658 Remove extradata from packets.
660 It accepts the following parameter:
663 Set which frame types to remove extradata from.
667 Remove extradata from non-keyframes only.
670 Remove extradata from keyframes only.
673 Remove extradata from all frames.
679 Set PTS and DTS in packets.
681 It accepts the following parameters:
686 Set expressions for PTS, DTS or both.
689 The expressions are evaluated through the eval API and can contain the following
694 The count of the input packet. Starting from 0.
697 The demux timestamp in input in case of @code{ts} or @code{dts} option or presentation
698 timestamp in case of @code{pts} option.
701 The original position in the file of the packet, or undefined if undefined
702 for the current packet
705 The demux timestamp in input.
708 The presentation timestamp in input.
711 The DTS of the first packet.
714 The PTS of the first packet.
717 The previous input DTS.
720 The previous input PTS.
723 The previous output DTS.
726 The previous output PTS.
729 The timebase of stream packet belongs.
732 The sample rate of stream packet belongs.
738 Convert text subtitles to MOV subtitles (as used by the @code{mov_text}
739 codec) with metadata headers.
741 See also the @ref{mov2textsub} filter.
743 @section trace_headers
745 Log trace output containing all syntax elements in the coded stream
746 headers (everything above the level of individual coded blocks).
747 This can be useful for debugging low-level stream issues.
749 Supports AV1, H.264, H.265, (M)JPEG, MPEG-2 and VP9, but depending
750 on the build only a subset of these may be available.
754 Extract the core from a TrueHD stream, dropping ATMOS data.
756 @section vp9_metadata
758 Modify metadata embedded in a VP9 stream.
762 Set the color space value in the frame header. Note that any frame
763 set to RGB will be implicitly set to PC range and that RGB is
764 incompatible with profiles 0 and 2.
776 Set the color range value in the frame header. Note that any value
777 imposed by the color space will take precedence over this value.
784 @section vp9_superframe
786 Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
787 fixes merging of split/segmented VP9 streams where the alt-ref frame
788 was split from its visible counterpart.
790 @section vp9_superframe_split
792 Split VP9 superframes into single frames.
794 @section vp9_raw_reorder
796 Given a VP9 stream with correct timestamps but possibly out of order,
797 insert additional show-existing-frame packets to correct the ordering.
799 @c man end BITSTREAM FILTERS