bitstream_filters.texi 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. @chapter Bitstream Filters
  2. @c man begin BITSTREAM FILTERS
  3. When you configure your FFmpeg build, all the supported bitstream
  4. filters are enabled by default. You can list all available ones using
  5. the configure option @code{--list-bsfs}.
  6. You can disable all the bitstream filters using the configure option
  7. @code{--disable-bsfs}, and selectively enable any bitstream filter using
  8. the option @code{--enable-bsf=BSF}, or you can disable a particular
  9. bitstream filter using the option @code{--disable-bsf=BSF}.
  10. The option @code{-bsfs} of the ff* tools will display the list of
  11. all the supported bitstream filters included in your build.
  12. The ff* tools have a -bsf option applied per stream, taking a
  13. comma-separated list of filters, whose parameters follow the filter
  14. name after a '='.
  15. @example
  16. ffmpeg -i INPUT -c:v copy -bsf:v filter1[=opt1=str1:opt2=str2][,filter2] OUTPUT
  17. @end example
  18. Below is a description of the currently available bitstream filters,
  19. with their parameters, if any.
  20. @section aac_adtstoasc
  21. Convert MPEG-2/4 AAC ADTS to an MPEG-4 Audio Specific Configuration
  22. bitstream.
  23. This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
  24. ADTS header and removes the ADTS header.
  25. This filter is required for example when copying an AAC stream from a
  26. raw ADTS AAC or an MPEG-TS container to MP4A-LATM, to an FLV file, or
  27. to MOV/MP4 files and related formats such as 3GP or M4A. Please note
  28. that it is auto-inserted for MP4A-LATM and MOV/MP4 and related formats.
  29. @section chomp
  30. Remove zero padding at the end of a packet.
  31. @section dca_core
  32. Extract the core from a DCA/DTS stream, dropping extensions such as
  33. DTS-HD.
  34. @section dump_extra
  35. Add extradata to the beginning of the filtered packets.
  36. @table @option
  37. @item freq
  38. The additional argument specifies which packets should be filtered.
  39. It accepts the values:
  40. @table @samp
  41. @item k
  42. @item keyframe
  43. add extradata to all key packets
  44. @item e
  45. @item all
  46. add extradata to all packets
  47. @end table
  48. @end table
  49. If not specified it is assumed @samp{e}.
  50. For example the following @command{ffmpeg} command forces a global
  51. header (thus disabling individual packet headers) in the H.264 packets
  52. generated by the @code{libx264} encoder, but corrects them by adding
  53. the header stored in extradata to the key packets:
  54. @example
  55. ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
  56. @end example
  57. @section eac3_core
  58. Extract the core from a E-AC-3 stream, dropping extra channels.
  59. @section extract_extradata
  60. Extract the in-band extradata.
  61. Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers,
  62. or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part
  63. of the bitstream containing the coded frames) or "out of band" (e.g. on the
  64. container level). This latter form is called "extradata" in FFmpeg terminology.
  65. This bitstream filter detects the in-band headers and makes them available as
  66. extradata.
  67. @table @option
  68. @item remove
  69. When this option is enabled, the long-term headers are removed from the
  70. bitstream after extraction.
  71. @end table
  72. @section filter_units
  73. Remove units with types in or not in a given set from the stream.
  74. @table @option
  75. @item pass_types
  76. List of unit types or ranges of unit types to pass through while removing
  77. all others. This is specified as a '|'-separated list of unit type values
  78. or ranges of values with '-'.
  79. @item remove_types
  80. Identical to @option{pass_types}, except the units in the given set
  81. removed and all others passed through.
  82. @end table
  83. Extradata is unchanged by this transformation, but note that if the stream
  84. contains inline parameter sets then the output may be unusable if they are
  85. removed.
  86. For example, to remove all non-VCL NAL units from an H.264 stream:
  87. @example
  88. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=pass_types=1-5' OUTPUT
  89. @end example
  90. To remove all AUDs, SEI and filler from an H.265 stream:
  91. @example
  92. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=35|38-40' OUTPUT
  93. @end example
  94. @section hapqa_extract
  95. Extract Rgb or Alpha part of an HAPQA file, without recompression, in order to create an HAPQ or an HAPAlphaOnly file.
  96. @table @option
  97. @item texture
  98. Specifies the texture to keep.
  99. @table @option
  100. @item color
  101. @item alpha
  102. @end table
  103. @end table
  104. Convert HAPQA to HAPQ
  105. @example
  106. 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
  107. @end example
  108. Convert HAPQA to HAPAlphaOnly
  109. @example
  110. 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
  111. @end example
  112. @section h264_metadata
  113. Modify metadata embedded in an H.264 stream.
  114. @table @option
  115. @item aud
  116. Insert or remove AUD NAL units in all access units of the stream.
  117. @table @samp
  118. @item insert
  119. @item remove
  120. @end table
  121. @item sample_aspect_ratio
  122. Set the sample aspect ratio of the stream in the VUI parameters.
  123. @item video_format
  124. @item video_full_range_flag
  125. Set the video format in the stream (see H.264 section E.2.1 and
  126. table E-2).
  127. @item colour_primaries
  128. @item transfer_characteristics
  129. @item matrix_coefficients
  130. Set the colour description in the stream (see H.264 section E.2.1
  131. and tables E-3, E-4 and E-5).
  132. @item chroma_sample_loc_type
  133. Set the chroma sample location in the stream (see H.264 section
  134. E.2.1 and figure E-1).
  135. @item tick_rate
  136. Set the tick rate (num_units_in_tick / time_scale) in the VUI
  137. parameters. This is the smallest time unit representable in the
  138. stream, and in many cases represents the field rate of the stream
  139. (double the frame rate).
  140. @item fixed_frame_rate_flag
  141. Set whether the stream has fixed framerate - typically this indicates
  142. that the framerate is exactly half the tick rate, but the exact
  143. meaning is dependent on interlacing and the picture structure (see
  144. H.264 section E.2.1 and table E-6).
  145. @item crop_left
  146. @item crop_right
  147. @item crop_top
  148. @item crop_bottom
  149. Set the frame cropping offsets in the SPS. These values will replace
  150. the current ones if the stream is already cropped.
  151. These fields are set in pixels. Note that some sizes may not be
  152. representable if the chroma is subsampled or the stream is interlaced
  153. (see H.264 section 7.4.2.1.1).
  154. @item sei_user_data
  155. Insert a string as SEI unregistered user data. The argument must
  156. be of the form @emph{UUID+string}, where the UUID is as hex digits
  157. possibly separated by hyphens, and the string can be anything.
  158. For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
  159. insert the string ``hello'' associated with the given UUID.
  160. @item delete_filler
  161. Deletes both filler NAL units and filler SEI messages.
  162. @end table
  163. @section h264_mp4toannexb
  164. Convert an H.264 bitstream from length prefixed mode to start code
  165. prefixed mode (as defined in the Annex B of the ITU-T H.264
  166. specification).
  167. This is required by some streaming formats, typically the MPEG-2
  168. transport stream format (muxer @code{mpegts}).
  169. For example to remux an MP4 file containing an H.264 stream to mpegts
  170. format with @command{ffmpeg}, you can use the command:
  171. @example
  172. ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
  173. @end example
  174. Please note that this filter is auto-inserted for MPEG-TS (muxer
  175. @code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
  176. @section h264_redundant_pps
  177. This applies a specific fixup to some Blu-ray streams which contain
  178. redundant PPSs modifying irrelevant parameters of the stream which
  179. confuse other transformations which require correct extradata.
  180. A new single global PPS is created, and all of the redundant PPSs
  181. within the stream are removed.
  182. @section hevc_metadata
  183. Modify metadata embedded in an HEVC stream.
  184. @table @option
  185. @item aud
  186. Insert or remove AUD NAL units in all access units of the stream.
  187. @table @samp
  188. @item insert
  189. @item remove
  190. @end table
  191. @item sample_aspect_ratio
  192. Set the sample aspect ratio in the stream in the VUI parameters.
  193. @item video_format
  194. @item video_full_range_flag
  195. Set the video format in the stream (see H.265 section E.3.1 and
  196. table E.2).
  197. @item colour_primaries
  198. @item transfer_characteristics
  199. @item matrix_coefficients
  200. Set the colour description in the stream (see H.265 section E.3.1
  201. and tables E.3, E.4 and E.5).
  202. @item chroma_sample_loc_type
  203. Set the chroma sample location in the stream (see H.265 section
  204. E.3.1 and figure E.1).
  205. @item tick_rate
  206. Set the tick rate in the VPS and VUI parameters (num_units_in_tick /
  207. time_scale). Combined with @option{num_ticks_poc_diff_one}, this can
  208. set a constant framerate in the stream. Note that it is likely to be
  209. overridden by container parameters when the stream is in a container.
  210. @item num_ticks_poc_diff_one
  211. Set poc_proportional_to_timing_flag in VPS and VUI and use this value
  212. to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
  213. E.3.1). Ignored if @option{tick_rate} is not also set.
  214. @item crop_left
  215. @item crop_right
  216. @item crop_top
  217. @item crop_bottom
  218. Set the conformance window cropping offsets in the SPS. These values
  219. will replace the current ones if the stream is already cropped.
  220. These fields are set in pixels. Note that some sizes may not be
  221. representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
  222. @end table
  223. @section hevc_mp4toannexb
  224. Convert an HEVC/H.265 bitstream from length prefixed mode to start code
  225. prefixed mode (as defined in the Annex B of the ITU-T H.265
  226. specification).
  227. This is required by some streaming formats, typically the MPEG-2
  228. transport stream format (muxer @code{mpegts}).
  229. For example to remux an MP4 file containing an HEVC stream to mpegts
  230. format with @command{ffmpeg}, you can use the command:
  231. @example
  232. ffmpeg -i INPUT.mp4 -codec copy -bsf:v hevc_mp4toannexb OUTPUT.ts
  233. @end example
  234. Please note that this filter is auto-inserted for MPEG-TS (muxer
  235. @code{mpegts}) and raw HEVC/H.265 (muxer @code{h265} or
  236. @code{hevc}) output formats.
  237. @section imxdump
  238. Modifies the bitstream to fit in MOV and to be usable by the Final Cut
  239. Pro decoder. This filter only applies to the mpeg2video codec, and is
  240. likely not needed for Final Cut Pro 7 and newer with the appropriate
  241. @option{-tag:v}.
  242. For example, to remux 30 MB/sec NTSC IMX to MOV:
  243. @example
  244. ffmpeg -i input.mxf -c copy -bsf:v imxdump -tag:v mx3n output.mov
  245. @end example
  246. @section mjpeg2jpeg
  247. Convert MJPEG/AVI1 packets to full JPEG/JFIF packets.
  248. MJPEG is a video codec wherein each video frame is essentially a
  249. JPEG image. The individual frames can be extracted without loss,
  250. e.g. by
  251. @example
  252. ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg
  253. @end example
  254. Unfortunately, these chunks are incomplete JPEG images, because
  255. they lack the DHT segment required for decoding. Quoting from
  256. @url{http://www.digitalpreservation.gov/formats/fdd/fdd000063.shtml}:
  257. Avery Lee, writing in the rec.video.desktop newsgroup in 2001,
  258. commented that "MJPEG, or at least the MJPEG in AVIs having the
  259. MJPG fourcc, is restricted JPEG with a fixed -- and *omitted* --
  260. Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2,
  261. and it must use basic Huffman encoding, not arithmetic or
  262. progressive. . . . You can indeed extract the MJPEG frames and
  263. decode them with a regular JPEG decoder, but you have to prepend
  264. the DHT segment to them, or else the decoder won't have any idea
  265. how to decompress the data. The exact table necessary is given in
  266. the OpenDML spec."
  267. This bitstream filter patches the header of frames extracted from an MJPEG
  268. stream (carrying the AVI1 header ID and lacking a DHT segment) to
  269. produce fully qualified JPEG images.
  270. @example
  271. ffmpeg -i mjpeg-movie.avi -c:v copy -bsf:v mjpeg2jpeg frame_%d.jpg
  272. exiftran -i -9 frame*.jpg
  273. ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
  274. @end example
  275. @section mjpegadump
  276. Add an MJPEG A header to the bitstream, to enable decoding by
  277. Quicktime.
  278. @anchor{mov2textsub}
  279. @section mov2textsub
  280. Extract a representable text file from MOV subtitles, stripping the
  281. metadata header from each subtitle packet.
  282. See also the @ref{text2movsub} filter.
  283. @section mp3decomp
  284. Decompress non-standard compressed MP3 audio headers.
  285. @section mpeg2_metadata
  286. Modify metadata embedded in an MPEG-2 stream.
  287. @table @option
  288. @item display_aspect_ratio
  289. Set the display aspect ratio in the stream.
  290. The following fixed values are supported:
  291. @table @option
  292. @item 4/3
  293. @item 16/9
  294. @item 221/100
  295. @end table
  296. Any other value will result in square pixels being signalled instead
  297. (see H.262 section 6.3.3 and table 6-3).
  298. @item frame_rate
  299. Set the frame rate in the stream. This is constructed from a table
  300. of known values combined with a small multiplier and divisor - if
  301. the supplied value is not exactly representable, the nearest
  302. representable value will be used instead (see H.262 section 6.3.3
  303. and table 6-4).
  304. @item video_format
  305. Set the video format in the stream (see H.262 section 6.3.6 and
  306. table 6-6).
  307. @item colour_primaries
  308. @item transfer_characteristics
  309. @item matrix_coefficients
  310. Set the colour description in the stream (see H.262 section 6.3.6
  311. and tables 6-7, 6-8 and 6-9).
  312. @end table
  313. @section mpeg4_unpack_bframes
  314. Unpack DivX-style packed B-frames.
  315. DivX-style packed B-frames are not valid MPEG-4 and were only a
  316. workaround for the broken Video for Windows subsystem.
  317. They use more space, can cause minor AV sync issues, require more
  318. CPU power to decode (unless the player has some decoded picture queue
  319. to compensate the 2,0,2,0 frame per packet style) and cause
  320. trouble if copied into a standard container like mp4 or mpeg-ps/ts,
  321. because MPEG-4 decoders may not be able to decode them, since they are
  322. not valid MPEG-4.
  323. For example to fix an AVI file containing an MPEG-4 stream with
  324. DivX-style packed B-frames using @command{ffmpeg}, you can use the command:
  325. @example
  326. ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
  327. @end example
  328. @section noise
  329. Damages the contents of packets or simply drops them without damaging the
  330. container. Can be used for fuzzing or testing error resilience/concealment.
  331. Parameters:
  332. @table @option
  333. @item amount
  334. A numeral string, whose value is related to how often output bytes will
  335. be modified. Therefore, values below or equal to 0 are forbidden, and
  336. the lower the more frequent bytes will be modified, with 1 meaning
  337. every byte is modified.
  338. @item dropamount
  339. A numeral string, whose value is related to how often packets will be dropped.
  340. Therefore, values below or equal to 0 are forbidden, and the lower the more
  341. frequent packets will be dropped, with 1 meaning every packet is dropped.
  342. @end table
  343. The following example applies the modification to every byte but does not drop
  344. any packets.
  345. @example
  346. ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
  347. @end example
  348. @section null
  349. This bitstream filter passes the packets through unchanged.
  350. @section remove_extra
  351. Remove extradata from packets.
  352. It accepts the following parameter:
  353. @table @option
  354. @item freq
  355. Set which frame types to remove extradata from.
  356. @table @samp
  357. @item k
  358. Remove extradata from non-keyframes only.
  359. @item keyframe
  360. Remove extradata from keyframes only.
  361. @item e, all
  362. Remove extradata from all frames.
  363. @end table
  364. @end table
  365. @anchor{text2movsub}
  366. @section text2movsub
  367. Convert text subtitles to MOV subtitles (as used by the @code{mov_text}
  368. codec) with metadata headers.
  369. See also the @ref{mov2textsub} filter.
  370. @section trace_headers
  371. Log trace output containing all syntax elements in the coded stream
  372. headers (everything above the level of individual coded blocks).
  373. This can be useful for debugging low-level stream issues.
  374. Supports H.264, H.265 and MPEG-2.
  375. @section vp9_superframe
  376. Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
  377. fixes merging of split/segmented VP9 streams where the alt-ref frame
  378. was split from its visible counterpart.
  379. @section vp9_superframe_split
  380. Split VP9 superframes into single frames.
  381. @section vp9_raw_reorder
  382. Given a VP9 stream with correct timestamps but possibly out of order,
  383. insert additional show-existing-frame packets to correct the ordering.
  384. @c man end BITSTREAM FILTERS