This document describes the bitstream filters provided by the libavcodec library.
A bitstream filter operates on the encoded stream data, and performs bitstream level modifications without performing decoding.
When you configure your FFmpeg build, all the supported bitstream
filters are enabled by default. You can list all available ones using
the configure option --list-bsfs.
You can disable all the bitstream filters using the configure option
--disable-bsfs, and selectively enable any bitstream filter using
the option --enable-bsf=BSF, or you can disable a particular
bitstream filter using the option --disable-bsf=BSF.
The option -bsfs of the ff* tools will display the list of
all the supported bitstream filters included in your build.
The ff* tools have a -bsf option applied per stream, taking a comma-separated list of filters, whose parameters follow the filter name after a ’=’.
ffmpeg -i INPUT -c:v copy -bsf:v filter1[=opt1=str1:opt2=str2][,filter2] OUTPUT
Below is a description of the currently available bitstream filters, with their parameters, if any.
Convert MPEG-2/4 AAC ADTS to an MPEG-4 Audio Specific Configuration bitstream.
This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4 ADTS header and removes the ADTS header.
This filter is required for example when copying an AAC stream from a raw ADTS AAC or an MPEG-TS container to MP4A-LATM, to an FLV file, or to MOV/MP4 files and related formats such as 3GP or M4A. Please note that it is auto-inserted for MP4A-LATM and MOV/MP4 and related formats.
Modify metadata embedded in an AV1 stream.
Insert or remove temporal delimiter OBUs in all temporal units of the stream.
Insert a TD at the beginning of every TU which does not already have one.
Remove the TD from the beginning of every TU which has one.
Set the color description fields in the stream (see AV1 section 6.4.2).
Set the color range in the stream (see AV1 section 6.4.2; note that this cannot be set for streams using BT.709 primaries, sRGB transfer characteristic and identity (RGB) matrix coefficients).
Limited range.
Full range.
Set the chroma sample location in the stream (see AV1 section 6.4.2). This can only be set for 4:2:0 streams.
Left position (matching the default in MPEG-2 and H.264).
Top-left position.
Set the tick rate (time_scale / num_units_in_display_tick) in the timing info in the sequence header.
Set the number of ticks in each picture, to indicate that the stream has a fixed framerate. Ignored if tick_rate is not also set.
Deletes Padding OBUs.
Remove zero padding at the end of a packet.
Extract the core from a DCA/DTS stream, dropping extensions such as DTS-HD.
Manipulate Dolby Vision metadata in a HEVC/AV1 bitstream, optionally enabling metadata compression.
If enabled, strip all Dolby Vision metadata (configuration record + RPU data blocks) from the stream.
Which compression level to enable.
No metadata compression.
Limited metadata compression scheme. Should be compatible with most devices. This is the default.
Extended metadata compression. Devices are not required to support this. Note that this level currently behaves the same as ‘limited’ in libavcodec.
Split a Dolby Vision Profile 7 multi-layer HEVC bitstream. Profile 7 carries the enhancement-layer HEVC bitstream interleaved inside the base-layer access units, wrapped in user-unspecified NAL units of type 63 (UNSPEC63), and the RPU metadata as a sibling user-unspecified NAL of type 62 (UNSPEC62).
Which Dolby Vision components to keep in the output bitstream.
Base layer only: drop every UNSPEC63 (EL) and every UNSPEC62 (RPU). The output is a plain HEVC stream with no Dolby Vision markers. This is the default.
Base layer with the RPU NAL kept.
Enhancement layer only: for every UNSPEC63 NAL, strip the two-byte outer NAL header and emit the inner payload. The result is a standalone HEVC bitstream. UNSPEC62 (RPU) is dropped.
Enhancement layer with the RPU NAL kept verbatim. Same as ‘el’, but the UNSPEC62 RPU NALs are also emitted alongside the unwrapped EL NALs.
Add extradata to the beginning of the filtered packets except when said packets already exactly begin with the extradata that is intended to be added.
The additional argument specifies which packets should be filtered. It accepts the values:
add extradata to all key packets
add extradata to all packets
If not specified it is assumed ‘k’.
For example the following ffmpeg command forces a global
header (thus disabling individual packet headers) in the H.264 packets
generated by the libx264 encoder, but corrects them by adding
the header stored in extradata to the key packets:
ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
Blocks in DV which are marked as damaged are replaced by blocks of the specified color.
The color to replace damaged blocks by
A 16 bit mask which specifies which of the 16 possible error status values are to be replaced by colored blocks. 0xFFFE is the default which replaces all non 0 error status values.
No error, no concealment
Error, No concealment
Reserved
Error or concealment
Not reserved
The specific error status code
see page 44-46 or section 5.5 of http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf
Extract the core from a E-AC-3 stream, dropping extra channels.
Convert from a EIA_608 stream to a SMPTE_436M_ANC data stream, wrapping the closed captions in CTA-708 CDP VANC packets.
Choose which line number the generated VANC packets should go on. You generally want either line 9 (the default) or 11.
Choose the SMPTE 436M wrapping type, defaults to ‘vanc_frame’. It accepts the values:
VANC frame (interlaced or segmented progressive frame)
Choose the SMPTE 436M sample coding, defaults to ‘8bit_luma’. It accepts the values:
8-bit component luma samples
8-bit component color difference samples
8-bit component luma and color difference samples
10-bit component luma samples
10-bit component color difference samples
10-bit component luma and color difference samples
8-bit component luma samples with parity error
8-bit component color difference samples with parity error
8-bit component luma and color difference samples with parity error
The initial value of the CDP’s 16-bit unsigned integer cdp_hdr_sequence_cntr and cdp_ftr_sequence_cntr fields. Defaults to 0.
Set the CDP’s cdp_frame_rate field. This doesn’t actually change the timing of the data stream, it just changes the values inserted in that field in the generated CDP packets. Defaults to ‘30000/1001’.
Extract the in-band extradata.
Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers, or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part of the bitstream containing the coded frames) or "out of band" (e.g. on the container level). This latter form is called "extradata" in FFmpeg terminology.
This bitstream filter detects the in-band headers and makes them available as extradata.
When this option is enabled, the long-term headers are removed from the bitstream after extraction.
Remove units with types in or not in a given set from the stream.
List of unit types or ranges of unit types to pass through while removing all others. This is specified as a ’|’-separated list of unit type values or ranges of values with ’-’.
Identical to pass_types, except the units in the given set removed and all others passed through.
The types used by pass_types and remove_types correspond to NAL unit types (nal_unit_type) in H.264, HEVC and H.266 (see Table 7-1 in the H.264 and HEVC specifications or Table 5 in the H.266 specification), to marker values for JPEG (without 0xFF prefix) and to start codes without start code prefix (i.e. the byte following the 0x000001) for MPEG-2. For VP8 and VP9, every unit has type zero.
Extradata is unchanged by this transformation, but note that if the stream contains inline parameter sets then the output may be unusable if they are removed.
For example, to remove all non-VCL NAL units from an H.264 stream:
ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=pass_types=1-5' OUTPUT
To remove all AUDs, SEI and filler from an H.265 stream:
ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=35|38-40' OUTPUT
To remove all user data from a MPEG-2 stream, including Closed Captions:
ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=178' OUTPUT
To remove all SEI from a H264 stream, including Closed Captions:
ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=6' OUTPUT
To remove all prefix and suffix SEI from a HEVC stream, including Closed Captions and dynamic HDR:
ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=39|40' OUTPUT
Extract Rgb or Alpha part of an HAPQA file, without recompression, in order to create an HAPQ or an HAPAlphaOnly file.
Specifies the texture to keep.
Convert HAPQA to HAPQ
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
Convert HAPQA to HAPAlphaOnly
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
Modify metadata embedded in an H.264 stream.
Insert or remove AUD NAL units in all access units of the stream.
Default is pass.
Set the sample aspect ratio of the stream in the VUI parameters. See H.264 table E-1.
Set whether the stream is suitable for display using overscan or not (see H.264 section E.2.1).
Set the video format in the stream (see H.264 section E.2.1 and table E-2).
Set the colour description in the stream (see H.264 section E.2.1 and tables E-3, E-4 and E-5).
Set the chroma sample location in the stream (see H.264 section E.2.1 and figure E-1).
Set the tick rate (time_scale / num_units_in_tick) in the VUI parameters. This is the smallest time unit representable in the stream, and in many cases represents the field rate of the stream (double the frame rate).
Set whether the stream has fixed framerate - typically this indicates that the framerate is exactly half the tick rate, but the exact meaning is dependent on interlacing and the picture structure (see H.264 section E.2.1 and table E-6).
Zero constraint_set4_flag and constraint_set5_flag in the SPS. These bits were reserved in a previous version of the H.264 spec, and thus some hardware decoders require these to be zero. The result of zeroing this is still a valid bitstream.
Set the frame cropping offsets in the SPS. These values will replace the current ones if the stream is already cropped.
These fields are set in pixels. Note that some sizes may not be representable if the chroma is subsampled or the stream is interlaced (see H.264 section 7.4.2.1.1).
Insert a string as SEI unregistered user data. The argument must be of the form UUID+string, where the UUID is as hex digits possibly separated by hyphens, and the string can be anything.
For example, ‘086f3693-b7b3-4f2c-9653-21492feee5b8+hello’ will insert the string “hello” associated with the given UUID.
Deletes both filler NAL units and filler SEI messages.
Insert, extract or remove Display orientation SEI messages. See H.264 section D.1.27 and D.2.27 for syntax and semantics.
Default is pass.
Insert mode works in conjunction with rotate and flip options.
Any pre-existing Display orientation messages will be removed in insert or remove mode.
Extract mode attaches the display matrix to the packet as side data.
Set rotation in display orientation SEI (anticlockwise angle in degrees). Range is -360 to +360. Default is NaN.
Set flip in display orientation SEI.
Default is unset.
Set the level in the SPS. Refer to H.264 section A.3 and tables A-1 to A-5.
The argument must be the name of a level (for example, ‘4.2’), a level_idc value (for example, ‘42’), or the special name ‘auto’ indicating that the filter should attempt to guess the level from the input stream properties.
Convert an H.264 bitstream from length prefixed mode to start code prefixed mode (as defined in the Annex B of the ITU-T H.264 specification).
This is required by some streaming formats, typically the MPEG-2
transport stream format (muxer mpegts).
For example to remux an MP4 file containing an H.264 stream to mpegts
format with ffmpeg, you can use the command:
ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
Please note that this filter is auto-inserted for MPEG-TS (muxer
mpegts) and raw H.264 (muxer h264) output formats.
This applies a specific fixup to some Blu-ray BDMV H264 streams which contain redundant PPSs. The PPSs modify irrelevant parameters of the stream, confusing other transformations which require the correct extradata.
The encoder used on these impacted streams adds extra PPSs throughout the stream, varying the initial QP and whether weighted prediction was enabled. This causes issues after copying the stream into a global header container, as the starting PPS is not suitable for the rest of the stream. One side effect, for example, is seeking will return garbled output until a new PPS appears.
This BSF removes the extra PPSs and rewrites the slice headers such that the stream uses a single leading PPS in the global header, which resolves the issue.
Modify metadata embedded in an HEVC stream.
Insert or remove AUD NAL units in all access units of the stream.
Set the sample aspect ratio in the stream in the VUI parameters.
Set the video format in the stream (see H.265 section E.3.1 and table E.2).
Set the colour description in the stream (see H.265 section E.3.1 and tables E.3, E.4 and E.5).
Set the chroma sample location in the stream (see H.265 section E.3.1 and figure E.1).
Set the tick rate in the VPS and VUI parameters (time_scale / num_units_in_tick). Combined with num_ticks_poc_diff_one, this can set a constant framerate in the stream. Note that it is likely to be overridden by container parameters when the stream is in a container.
Set poc_proportional_to_timing_flag in VPS and VUI and use this value to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and E.3.1). Ignored if tick_rate is not also set.
Set the conformance window cropping offsets in the SPS. These values will replace the current ones if the stream is already cropped.
These fields are set in pixels. Note that some sizes may not be representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
Set width and height after crop.
Set the level in the VPS and SPS. See H.265 section A.4 and tables A.6 and A.7.
The argument must be the name of a level (for example, ‘5.1’), a general_level_idc value (for example, ‘153’ for level 5.1), or the special name ‘auto’ indicating that the filter should attempt to guess the level from the input stream properties.
Convert an HEVC/H.265 bitstream from length prefixed mode to start code prefixed mode (as defined in the Annex B of the ITU-T H.265 specification).
This is required by some streaming formats, typically the MPEG-2
transport stream format (muxer mpegts).
For example to remux an MP4 file containing an HEVC stream to mpegts
format with ffmpeg, you can use the command:
ffmpeg -i INPUT.mp4 -codec copy -bsf:v hevc_mp4toannexb OUTPUT.ts
Please note that this filter is auto-inserted for MPEG-TS (muxer
mpegts) and raw HEVC/H.265 (muxer h265 or
hevc) output formats.
Modifies the bitstream to fit in MOV and to be usable by the Final Cut Pro decoder. This filter only applies to the mpeg2video codec, and is likely not needed for Final Cut Pro 7 and newer with the appropriate -tag:v.
For example, to remux 30 MB/sec NTSC IMX to MOV:
ffmpeg -i input.mxf -c copy -bsf:v imxdump -tag:v mx3n output.mov
Convert MJPEG/AVI1 packets to full JPEG/JFIF packets.
MJPEG is a video codec wherein each video frame is essentially a JPEG image. The individual frames can be extracted without loss, e.g. by
ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg
Unfortunately, these chunks are incomplete JPEG images, because they lack the DHT segment required for decoding. Quoting from http://www.digitalpreservation.gov/formats/fdd/fdd000063.shtml:
Avery Lee, writing in the rec.video.desktop newsgroup in 2001, commented that "MJPEG, or at least the MJPEG in AVIs having the MJPG fourcc, is restricted JPEG with a fixed – and *omitted* – Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2, and it must use basic Huffman encoding, not arithmetic or progressive. . . . You can indeed extract the MJPEG frames and decode them with a regular JPEG decoder, but you have to prepend the DHT segment to them, or else the decoder won’t have any idea how to decompress the data. The exact table necessary is given in the OpenDML spec."
This bitstream filter patches the header of frames extracted from an MJPEG stream (carrying the AVI1 header ID and lacking a DHT segment) to produce fully qualified JPEG images.
ffmpeg -i mjpeg-movie.avi -c:v copy -bsf:v mjpeg2jpeg frame_%d.jpg exiftran -i -9 frame*.jpg ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
Add an MJPEG A header to the bitstream, to enable decoding by Quicktime.
Extract a representable text file from MOV subtitles, stripping the metadata header from each subtitle packet.
See also the text2movsub filter.
Modify metadata embedded in an MPEG-2 stream.
Set the display aspect ratio in the stream.
The following fixed values are supported:
Any other value will result in square pixels being signalled instead (see H.262 section 6.3.3 and table 6-3).
Set the frame rate in the stream. This is constructed from a table of known values combined with a small multiplier and divisor - if the supplied value is not exactly representable, the nearest representable value will be used instead (see H.262 section 6.3.3 and table 6-4).
Set the video format in the stream (see H.262 section 6.3.6 and table 6-6).
Set the colour description in the stream (see H.262 section 6.3.6 and tables 6-7, 6-8 and 6-9).
Unpack DivX-style packed B-frames.
DivX-style packed B-frames are not valid MPEG-4 and were only a workaround for the broken Video for Windows subsystem. They use more space, can cause minor AV sync issues, require more CPU power to decode (unless the player has some decoded picture queue to compensate the 2,0,2,0 frame per packet style) and cause trouble if copied into a standard container like mp4 or mpeg-ps/ts, because MPEG-4 decoders may not be able to decode them, since they are not valid MPEG-4.
For example to fix an AVI file containing an MPEG-4 stream with
DivX-style packed B-frames using ffmpeg, you can use the command:
ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
Damages the contents of packets or simply drops them without damaging the container. Can be used for fuzzing or testing error resilience/concealment.
Parameters:
Accepts an expression whose evaluation per-packet determines how often bytes in that packet will be modified. A value below 0 will result in a variable frequency. Default is 0 which results in no modification. However, if neither amount nor drop is specified, amount will be set to -1. See below for accepted variables.
Accepts an expression evaluated per-packet whose value determines whether that packet is dropped. Evaluation to a positive value results in the packet being dropped. Evaluation to a negative value results in a variable chance of it being dropped, roughly inverse in proportion to the magnitude of the value. Default is 0 which results in no drops. See below for accepted variables.
Accepts a non-negative integer, which assigns a variable chance of it being dropped, roughly inverse
in proportion to the value. Default is 0 which results in no drops. This option is kept for backwards
compatibility and is equivalent to setting drop to a negative value with the same magnitude
i.e. dropamount=4 is the same as drop=-4. Ignored if drop is also specified.
Both amount and drop accept expressions containing the following variables:
The index of the packet, starting from zero.
The timebase for packet timestamps.
Packet presentation timestamp.
Packet decoding timestamp.
Constant representing AV_NOPTS_VALUE.
First non-AV_NOPTS_VALUE PTS seen in the stream.
First non-AV_NOPTS_VALUE DTS seen in the stream.
Packet duration, in timebase units.
Packet position in input; may be -1 when unknown or not set.
Packet size, in bytes.
Whether packet is marked as a keyframe.
A pseudo random integer, primarily derived from the content of packet payload.
Apply modification to every byte but don’t drop any packets.
ffmpeg -i INPUT -c copy -bsf noise=1 output.mkv
Drop every video packet not marked as a keyframe after timestamp 30s but do not modify any of the remaining packets.
ffmpeg -i INPUT -c copy -bsf:v noise=drop='gt(pts*tb\,30)*not(key)' output.mkv
Drop one second of audio every 10 seconds and add some random noise to the rest.
ffmpeg -i INPUT -c copy -bsf:a noise=amount=-1:drop='between(mod(pts*tb\,10)\,9\,10)' output.mkv
This bitstream filter passes the packets through unchanged.
Repacketize PCM audio to a fixed number of samples per packet or a fixed packet rate per second. This is similar to the asetnsamples audio filter but works on audio packets instead of audio frames.
Set the number of samples per each output audio packet. The number is intended as the number of samples per each channel. Default value is 1024.
If set to 1, the filter will pad the last audio packet with silence, so that it will contain the same number of samples (or roughly the same number of samples, see frame_rate) as the previous ones. Default value is 1.
This option makes the filter output a fixed number of packets per second instead of a fixed number of samples per packet. If the audio sample rate is not divisible by the frame rate then the number of samples will not be constant but will vary slightly so that each packet will start as close to the frame boundary as possible. Using this option has precedence over nb_out_samples.
You can generate the well known 1602-1601-1602-1601-1602 pattern of 48kHz audio for NTSC frame rate using the frame_rate option.
ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf pcm_rechunk=r=30000/1001 -f framecrc -
Merge a sequence of PGS Subtitle segments ending with an "end of display set" segment into a single packet.
This is required by some containers that support PGS subtitles
(muxer matroska).
Modify color property metadata embedded in prores stream.
Set the color primaries. Available values are:
Keep the same color primaries property (default).
BT601 625
BT601 525
DCI P3
P3 D65
Set the color transfer. Available values are:
Keep the same transfer characteristics property (default).
BT 601, BT 709, BT 2020
SMPTE ST 2084
ARIB STD-B67
Set the matrix coefficient. Available values are:
Keep the same colorspace property (default).
BT 601
Set Rec709 colorspace for each frame of the file
ffmpeg -i INPUT -c copy -bsf:v prores_metadata=color_primaries=bt709:color_trc=bt709:colorspace=bt709 output.mov
Set Hybrid Log-Gamma parameters for each frame of the file
ffmpeg -i INPUT -c copy -bsf:v prores_metadata=color_primaries=bt2020:color_trc=arib-std-b67:colorspace=bt2020nc output.mov
Remove extradata from packets.
It accepts the following parameter:
Set which frame types to remove extradata from.
Remove extradata from non-keyframes only.
Remove extradata from keyframes only.
Remove extradata from all frames.
Set PTS and DTS in packets.
It accepts the following parameters:
Set expressions for PTS, DTS or both.
Set expression for duration.
Set output time base.
Set whether to convert time fields to user-set output time base before evaluation of expressions. Defaults to 0.
The expressions are evaluated through the eval API and can contain the following constants:
The count of the input packet. Starting from 0.
The demux timestamp in input in case of ts or dts option or presentation
timestamp in case of pts option.
The original position in the file of the packet, or undefined if undefined for the current packet
The demux timestamp in input.
The presentation timestamp in input.
The duration in input.
The DTS of the first packet.
The PTS of the first packet.
The previous input DTS.
The previous input PTS.
The previous input duration.
The previous output DTS.
The previous output PTS.
The previous output duration.
The next input DTS.
The next input PTS.
The next input duration.
The timebase in which time fields are denominated. The user-set output timebase if prescale is enabled, else the input timebase.
The output timebase.
The sample rate of stream packet belongs.
The AV_NOPTS_VALUE constant.
For example, to set PTS equal to DTS (not recommended if B-frames are involved):
ffmpeg -i INPUT -c:a copy -bsf:a setts=pts=DTS out.mkv
Log basic packet information. Mainly useful for testing, debugging, and development.
Convert from a SMPTE_436M_ANC data stream to a EIA_608 stream,
extracting the closed captions from CTA-708 CDP VANC packets, and ignoring all other data.
Convert text subtitles to MOV subtitles (as used by the mov_text
codec) with metadata headers.
See also the mov2textsub filter.
Log trace output containing all syntax elements in the coded stream headers (everything above the level of individual coded blocks). This can be useful for debugging low-level stream issues.
Supports AV1, H.264, H.265, (M)JPEG, MPEG-2 and VP9, but depending on the build only a subset of these may be available.
Drop packets outside a given range, similar to the trim and atrim filters, but operating on packets instead of decoded frames.
The range is described by a start and an end bound. At least one of them must be set. Each bound is fully described by three independent choices:
dts start with a pts end.
The start_type and end_type options name a combination of the
three. The dur_ts and dur_t_msec end types are the always relative
forms of pts and msec_pt. A zero duration therefore produces an
empty stream.
Every packet is judged on its own discriminant, and on nothing else. A packet not carrying the discriminant its bound uses cannot be placed, and is dropped.
start_rel makes start an offset from a reference packet instead of an absolute value. The reference is the first packet carrying the discriminant that bound uses. Its value is added to the offset once, and the bound stays there for the rest of the stream.
end_rel anchors on the first exported packet instead, at the position start trimmed it to. The two bounds therefore move together.
Only a discriminant that cannot come back into the range ends the stream, namely the packet index or the decoding timestamp. End of stream is signaled once one of those passes the end bound. A presentation timestamp past the end only drops its packet, so that later packets still inside the range are not lost.
A bound given in a time unit can fall inside a packet rather than between two. Such a packet is trimmed. Set trim_packets to false to keep every packet exactly as it came in: exported whole if its own value is inside the range, dropped otherwise.
Audio is trimmed in sample space, through skip samples side data. The timestamps and duration are left untouched, and a decoder discards the signaled samples on output. This needs a sample rate and a time base. Audio missing either is rejected rather than trimmed on the timeline. Every other media type is trimmed by shifting the packet timestamps and shortening its duration.
Trimming inside an audio packet needs the number of samples it decodes to. Where the codec does not give that number, the packet is handled as though trim_packets were false.
A skip larger than the packet carrying it continues into the packets after it. Dropping such a packet carries the remainder over to the next one. A skip that packet already carries replaces the remainder, as a decoder would, and the larger of it and this filter’s own trim wins.
By default a packet outside the range is dropped, whether or not later packets depend on it. Streams of independent frames, such as ADTS or intra only video, can be cut anywhere. Cutting an inter coded stream inside a group of pictures leaves the first packets in range undecodable.
Set preroll to export the packets those first packets depend on as well. They are flagged for a decoder to decode and then drop, so the frames it outputs still begin at the start bound. Only a decoder acts on that flag. Use preroll where the stream is decoded. A muxer writes the extra packets like any other. A remux then covers more than the requested range.
preroll covers the start of the range only. On a stream with B-frames an end bound on the presentation timestamp can drop a packet the last frames in the range need. Those frames then decode incorrectly.
It accepts the following parameters:
Time or index marking the start of the accepted range. Packets before it are dropped. A packet straddling it is trimmed at its start, or dropped when trim_packets is false.
How to interpret start:
Presentation timestamp, in stream time base (default).
Decoding timestamp, in stream time base.
Packet index, counting from zero.
Milliseconds, matched against the presentation timestamp.
Milliseconds, matched against the decoding timestamp.
Count start from the reference packet rather than from zero. Has no effect on ‘pkt_index’, whose first packet is already zero. Default false.
Time or index marking the end of the accepted range. Signals end of stream when reached. A packet straddling it is trimmed at its end, or exported untouched when trim_packets is false.
How to interpret end. Same values as start_type, plus:
Duration in stream time base. Same as ‘pts’ with end_rel set.
Duration in milliseconds. Same as ‘msec_pt’ with end_rel set.
Count end from the first exported packet rather than from zero. The reference is that packet’s value on the discriminant end_type names. On a timestamp it is taken at the position the packet is trimmed to. For audio that is the time of its first retained sample. The skip that packet carries can push it past the packet itself. With ‘pkt_index’ it exports a fixed number of packets, which can be combined with a timestamp-based start. Always set for the duration types. Default false.
Trim packets straddling a boundary. When false, packets are exported exactly as they came in, with no timestamp adjustment and no skip samples side data. A packet is then exported untouched if its value falls inside the range, and dropped otherwise. Default true.
Export the packets a decoder needs to decode the first packet in range, rather
than dropping them for falling before the start bound. The filter holds
every packet from the last keyframe on. It exports them ahead of the first
packet in range, carrying AV_PKT_FLAG_DISCARD.
Video only. Default false.
Maximum number of packets held for preroll. A group of pictures longer than this is dropped whole, with a warning naming the count to raise it past. Default 300, which covers the keyframe intervals encoders commonly default to.
For example, to keep only the 10 first packets of an ADTS stream:
ffmpeg -i INPUT.aac -c copy -bsf:a trim=end=10:end_type=pkt_index OUTPUT.aac
To keep 5 seconds starting 1.5 seconds into the stream:
ffmpeg -i INPUT.aac -c copy -bsf:a trim=start=1500:start_type=msec_pt:end=5000:end_type=dur_t_msec OUTPUT.aac
The same, expressed relative to the first packet so it works regardless of the stream’s starting timestamp:
ffmpeg -i INPUT.aac -c copy -bsf:a trim=start=1500:start_type=msec_pt:start_rel=1:end=5000:end_type=dur_t_msec OUTPUT.aac
To start on a keyframeless point of an inter coded video stream, re-encoding it so that the preroll is decoded rather than written out. The filter must run before the decoder, so it is given before the input:
ffmpeg -bsf:v trim=start=17000:start_type=msec_pt:end=30000:end_type=dur_t_msec:preroll=1 -i INPUT.mp4 OUTPUT.mp4
Extract the core from a TrueHD stream, dropping ATMOS data.
Modify metadata embedded in a VP9 stream.
Set the color space value in the frame header. Note that any frame set to RGB will be implicitly set to PC range and that RGB is incompatible with profiles 0 and 2.
Set the color range value in the frame header. Note that any value imposed by the color space will take precedence over this value.
Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This fixes merging of split/segmented VP9 streams where the alt-ref frame was split from its visible counterpart.
Split VP9 superframes into single frames.
Given a VP9 stream with correct timestamps but possibly out of order, insert additional show-existing-frame packets to correct the ordering.
ffmpeg, ffplay, ffprobe, libavcodec
The FFmpeg developers.
For details about the authorship, see the Git history of the project
(https://git.ffmpeg.org/ffmpeg), e.g. by typing the command
git log in the FFmpeg source directory, or browsing the
online repository at https://git.ffmpeg.org/ffmpeg.
Maintainers for the specific components are listed in the file MAINTAINERS in the source code tree.
This document was generated using makeinfo.