summaryrefslogtreecommitdiff
path: root/doc/bitstream_filters.texi (plain)
blob: 947c31dae84e417dbfabb2a7666cc5529423a9b4
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 chomp
41
42Remove zero padding at the end of a packet.
43
44@section dca_core
45
46Extract the core from a DCA/DTS stream, dropping extensions such as
47DTS-HD.
48
49@section dump_extra
50
51Add extradata to the beginning of the filtered packets.
52
53The additional argument specifies which packets should be filtered.
54It accepts the values:
55@table @samp
56@item a
57add extradata to all key packets, but only if @var{local_header} is
58set in the @option{flags2} codec context field
59
60@item k
61add extradata to all key packets
62
63@item e
64add extradata to all packets
65@end table
66
67If not specified it is assumed @samp{k}.
68
69For example the following @command{ffmpeg} command forces a global
70header (thus disabling individual packet headers) in the H.264 packets
71generated by the @code{libx264} encoder, but corrects them by adding
72the header stored in extradata to the key packets:
73@example
74ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
75@end example
76
77@section extract_extradata
78
79Extract the in-band extradata.
80
81Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers,
82or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part
83of the bitstream containing the coded frames) or "out of band" (e.g. on the
84container level). This latter form is called "extradata" in FFmpeg terminology.
85
86This bitstream filter detects the in-band headers and makes them available as
87extradata.
88
89@table @option
90@item remove
91When this option is enabled, the long-term headers are removed from the
92bitstream after extraction.
93@end table
94
95@section h264_mp4toannexb
96
97Convert an H.264 bitstream from length prefixed mode to start code
98prefixed mode (as defined in the Annex B of the ITU-T H.264
99specification).
100
101This is required by some streaming formats, typically the MPEG-2
102transport stream format (muxer @code{mpegts}).
103
104For example to remux an MP4 file containing an H.264 stream to mpegts
105format with @command{ffmpeg}, you can use the command:
106
107@example
108ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
109@end example
110
111Please note that this filter is auto-inserted for MPEG-TS (muxer
112@code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
113
114@section hevc_mp4toannexb
115
116Convert an HEVC/H.265 bitstream from length prefixed mode to start code
117prefixed mode (as defined in the Annex B of the ITU-T H.265
118specification).
119
120This is required by some streaming formats, typically the MPEG-2
121transport stream format (muxer @code{mpegts}).
122
123For example to remux an MP4 file containing an HEVC stream to mpegts
124format with @command{ffmpeg}, you can use the command:
125
126@example
127ffmpeg -i INPUT.mp4 -codec copy -bsf:v hevc_mp4toannexb OUTPUT.ts
128@end example
129
130Please note that this filter is auto-inserted for MPEG-TS (muxer
131@code{mpegts}) and raw HEVC/H.265 (muxer @code{h265} or
132@code{hevc}) output formats.
133
134@section imxdump
135
136Modifies the bitstream to fit in MOV and to be usable by the Final Cut
137Pro decoder. This filter only applies to the mpeg2video codec, and is
138likely not needed for Final Cut Pro 7 and newer with the appropriate
139@option{-tag:v}.
140
141For example, to remux 30 MB/sec NTSC IMX to MOV:
142
143@example
144ffmpeg -i input.mxf -c copy -bsf:v imxdump -tag:v mx3n output.mov
145@end example
146
147@section mjpeg2jpeg
148
149Convert MJPEG/AVI1 packets to full JPEG/JFIF packets.
150
151MJPEG is a video codec wherein each video frame is essentially a
152JPEG image. The individual frames can be extracted without loss,
153e.g. by
154
155@example
156ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg
157@end example
158
159Unfortunately, these chunks are incomplete JPEG images, because
160they lack the DHT segment required for decoding. Quoting from
161@url{http://www.digitalpreservation.gov/formats/fdd/fdd000063.shtml}:
162
163Avery Lee, writing in the rec.video.desktop newsgroup in 2001,
164commented that "MJPEG, or at least the MJPEG in AVIs having the
165MJPG fourcc, is restricted JPEG with a fixed -- and *omitted* --
166Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2,
167and it must use basic Huffman encoding, not arithmetic or
168progressive. . . . You can indeed extract the MJPEG frames and
169decode them with a regular JPEG decoder, but you have to prepend
170the DHT segment to them, or else the decoder won't have any idea
171how to decompress the data. The exact table necessary is given in
172the OpenDML spec."
173
174This bitstream filter patches the header of frames extracted from an MJPEG
175stream (carrying the AVI1 header ID and lacking a DHT segment) to
176produce fully qualified JPEG images.
177
178@example
179ffmpeg -i mjpeg-movie.avi -c:v copy -bsf:v mjpeg2jpeg frame_%d.jpg
180exiftran -i -9 frame*.jpg
181ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
182@end example
183
184@section mjpegadump
185
186Add an MJPEG A header to the bitstream, to enable decoding by
187Quicktime.
188
189@anchor{mov2textsub}
190@section mov2textsub
191
192Extract a representable text file from MOV subtitles, stripping the
193metadata header from each subtitle packet.
194
195See also the @ref{text2movsub} filter.
196
197@section mp3decomp
198
199Decompress non-standard compressed MP3 audio headers.
200
201@section mpeg4_unpack_bframes
202
203Unpack DivX-style packed B-frames.
204
205DivX-style packed B-frames are not valid MPEG-4 and were only a
206workaround for the broken Video for Windows subsystem.
207They use more space, can cause minor AV sync issues, require more
208CPU power to decode (unless the player has some decoded picture queue
209to compensate the 2,0,2,0 frame per packet style) and cause
210trouble if copied into a standard container like mp4 or mpeg-ps/ts,
211because MPEG-4 decoders may not be able to decode them, since they are
212not valid MPEG-4.
213
214For example to fix an AVI file containing an MPEG-4 stream with
215DivX-style packed B-frames using @command{ffmpeg}, you can use the command:
216
217@example
218ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
219@end example
220
221@section noise
222
223Damages the contents of packets without damaging the container. Can be
224used for fuzzing or testing error resilience/concealment.
225
226Parameters:
227A numeral string, whose value is related to how often output bytes will
228be modified. Therefore, values below or equal to 0 are forbidden, and
229the lower the more frequent bytes will be modified, with 1 meaning
230every byte is modified.
231
232@example
233ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
234@end example
235applies the modification to every byte.
236
237@section remove_extra
238
239Remove extradata from packets.
240
241It accepts the following parameter:
242@table @option
243@item freq
244Set which frame types to remove extradata from.
245
246@table @samp
247@item k
248Remove extradata from non-keyframes only.
249
250@item keyframe
251Remove extradata from keyframes only.
252
253@item e, all
254Remove extradata from all frames.
255
256@end table
257@end table
258
259@anchor{text2movsub}
260@section text2movsub
261
262Convert text subtitles to MOV subtitles (as used by the @code{mov_text}
263codec) with metadata headers.
264
265See also the @ref{mov2textsub} filter.
266
267@section vp9_superframe
268
269Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
270fixes merging of split/segmented VP9 streams where the alt-ref frame
271was split from its visible counterpart.
272
273@c man end BITSTREAM FILTERS
274