You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

522 lines
15KB

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