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.

464 lines
14KB

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