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