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.

696 lines
19KB

  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 av1_metadata
  30. Modify metadata embedded in an AV1 stream.
  31. @table @option
  32. @item td
  33. Insert or remove temporal delimiter OBUs in all temporal units of the
  34. stream.
  35. @table @samp
  36. @item insert
  37. Insert a TD at the beginning of every TU which does not already have one.
  38. @item remove
  39. Remove the TD from the beginning of every TU which has one.
  40. @end table
  41. @item color_primaries
  42. @item transfer_characteristics
  43. @item matrix_coefficients
  44. Set the color description fields in the stream (see AV1 section 6.4.2).
  45. @item color_range
  46. Set the color range in the stream (see AV1 section 6.4.2; note that
  47. this cannot be set for streams using BT.709 primaries, sRGB transfer
  48. characteristic and identity (RGB) matrix coefficients).
  49. @table @samp
  50. @item tv
  51. Limited range.
  52. @item pc
  53. Full range.
  54. @end table
  55. @item chroma_sample_position
  56. Set the chroma sample location in the stream (see AV1 section 6.4.2).
  57. This can only be set for 4:2:0 streams.
  58. @table @samp
  59. @item vertical
  60. Left position (matching the default in MPEG-2 and H.264).
  61. @item colocated
  62. Top-left position.
  63. @end table
  64. @item tick_rate
  65. Set the tick rate (@emph{num_units_in_display_tick / time_scale}) in
  66. the timing info in the sequence header.
  67. @item num_ticks_per_picture
  68. Set the number of ticks in each picture, to indicate that the stream
  69. has a fixed framerate. Ignored if @option{tick_rate} is not also set.
  70. @item delete_padding
  71. Deletes Padding OBUs.
  72. @end table
  73. @section chomp
  74. Remove zero padding at the end of a packet.
  75. @section dca_core
  76. Extract the core from a DCA/DTS stream, dropping extensions such as
  77. DTS-HD.
  78. @section dump_extra
  79. Add extradata to the beginning of the filtered packets.
  80. @table @option
  81. @item freq
  82. The additional argument specifies which packets should be filtered.
  83. It accepts the values:
  84. @table @samp
  85. @item k
  86. @item keyframe
  87. add extradata to all key packets
  88. @item e
  89. @item all
  90. add extradata to all packets
  91. @end table
  92. @end table
  93. If not specified it is assumed @samp{k}.
  94. For example the following @command{ffmpeg} command forces a global
  95. header (thus disabling individual packet headers) in the H.264 packets
  96. generated by the @code{libx264} encoder, but corrects them by adding
  97. the header stored in extradata to the key packets:
  98. @example
  99. ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
  100. @end example
  101. @section eac3_core
  102. Extract the core from a E-AC-3 stream, dropping extra channels.
  103. @section extract_extradata
  104. Extract the in-band extradata.
  105. Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers,
  106. or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part
  107. of the bitstream containing the coded frames) or "out of band" (e.g. on the
  108. container level). This latter form is called "extradata" in FFmpeg terminology.
  109. This bitstream filter detects the in-band headers and makes them available as
  110. extradata.
  111. @table @option
  112. @item remove
  113. When this option is enabled, the long-term headers are removed from the
  114. bitstream after extraction.
  115. @end table
  116. @section filter_units
  117. Remove units with types in or not in a given set from the stream.
  118. @table @option
  119. @item pass_types
  120. List of unit types or ranges of unit types to pass through while removing
  121. all others. This is specified as a '|'-separated list of unit type values
  122. or ranges of values with '-'.
  123. @item remove_types
  124. Identical to @option{pass_types}, except the units in the given set
  125. removed and all others passed through.
  126. @end table
  127. Extradata is unchanged by this transformation, but note that if the stream
  128. contains inline parameter sets then the output may be unusable if they are
  129. removed.
  130. For example, to remove all non-VCL NAL units from an H.264 stream:
  131. @example
  132. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=pass_types=1-5' OUTPUT
  133. @end example
  134. To remove all AUDs, SEI and filler from an H.265 stream:
  135. @example
  136. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=35|38-40' OUTPUT
  137. @end example
  138. @section hapqa_extract
  139. Extract Rgb or Alpha part of an HAPQA file, without recompression, in order to create an HAPQ or an HAPAlphaOnly file.
  140. @table @option
  141. @item texture
  142. Specifies the texture to keep.
  143. @table @option
  144. @item color
  145. @item alpha
  146. @end table
  147. @end table
  148. Convert HAPQA to HAPQ
  149. @example
  150. 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
  151. @end example
  152. Convert HAPQA to HAPAlphaOnly
  153. @example
  154. 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
  155. @end example
  156. @section h264_metadata
  157. Modify metadata embedded in an H.264 stream.
  158. @table @option
  159. @item aud
  160. Insert or remove AUD NAL units in all access units of the stream.
  161. @table @samp
  162. @item insert
  163. @item remove
  164. @end table
  165. @item sample_aspect_ratio
  166. Set the sample aspect ratio of the stream in the VUI parameters.
  167. @item video_format
  168. @item video_full_range_flag
  169. Set the video format in the stream (see H.264 section E.2.1 and
  170. table E-2).
  171. @item colour_primaries
  172. @item transfer_characteristics
  173. @item matrix_coefficients
  174. Set the colour description in the stream (see H.264 section E.2.1
  175. and tables E-3, E-4 and E-5).
  176. @item chroma_sample_loc_type
  177. Set the chroma sample location in the stream (see H.264 section
  178. E.2.1 and figure E-1).
  179. @item tick_rate
  180. Set the tick rate (num_units_in_tick / time_scale) in the VUI
  181. parameters. This is the smallest time unit representable in the
  182. stream, and in many cases represents the field rate of the stream
  183. (double the frame rate).
  184. @item fixed_frame_rate_flag
  185. Set whether the stream has fixed framerate - typically this indicates
  186. that the framerate is exactly half the tick rate, but the exact
  187. meaning is dependent on interlacing and the picture structure (see
  188. H.264 section E.2.1 and table E-6).
  189. @item crop_left
  190. @item crop_right
  191. @item crop_top
  192. @item crop_bottom
  193. Set the frame cropping offsets in the SPS. These values will replace
  194. the current ones if the stream is already cropped.
  195. These fields are set in pixels. Note that some sizes may not be
  196. representable if the chroma is subsampled or the stream is interlaced
  197. (see H.264 section 7.4.2.1.1).
  198. @item sei_user_data
  199. Insert a string as SEI unregistered user data. The argument must
  200. be of the form @emph{UUID+string}, where the UUID is as hex digits
  201. possibly separated by hyphens, and the string can be anything.
  202. For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
  203. insert the string ``hello'' associated with the given UUID.
  204. @item delete_filler
  205. Deletes both filler NAL units and filler SEI messages.
  206. @item level
  207. Set the level in the SPS. Refer to H.264 section A.3 and tables A-1
  208. to A-5.
  209. The argument must be the name of a level (for example, @samp{4.2}), a
  210. level_idc value (for example, @samp{42}), or the special name @samp{auto}
  211. indicating that the filter should attempt to guess the level from the
  212. input stream properties.
  213. @end table
  214. @section h264_mp4toannexb
  215. Convert an H.264 bitstream from length prefixed mode to start code
  216. prefixed mode (as defined in the Annex B of the ITU-T H.264
  217. specification).
  218. This is required by some streaming formats, typically the MPEG-2
  219. transport stream format (muxer @code{mpegts}).
  220. For example to remux an MP4 file containing an H.264 stream to mpegts
  221. format with @command{ffmpeg}, you can use the command:
  222. @example
  223. ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
  224. @end example
  225. Please note that this filter is auto-inserted for MPEG-TS (muxer
  226. @code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
  227. @section h264_redundant_pps
  228. This applies a specific fixup to some Blu-ray streams which contain
  229. redundant PPSs modifying irrelevant parameters of the stream which
  230. confuse other transformations which require correct extradata.
  231. A new single global PPS is created, and all of the redundant PPSs
  232. within the stream are removed.
  233. @section hevc_metadata
  234. Modify metadata embedded in an HEVC stream.
  235. @table @option
  236. @item aud
  237. Insert or remove AUD NAL units in all access units of the stream.
  238. @table @samp
  239. @item insert
  240. @item remove
  241. @end table
  242. @item sample_aspect_ratio
  243. Set the sample aspect ratio in the stream in the VUI parameters.
  244. @item video_format
  245. @item video_full_range_flag
  246. Set the video format in the stream (see H.265 section E.3.1 and
  247. table E.2).
  248. @item colour_primaries
  249. @item transfer_characteristics
  250. @item matrix_coefficients
  251. Set the colour description in the stream (see H.265 section E.3.1
  252. and tables E.3, E.4 and E.5).
  253. @item chroma_sample_loc_type
  254. Set the chroma sample location in the stream (see H.265 section
  255. E.3.1 and figure E.1).
  256. @item tick_rate
  257. Set the tick rate in the VPS and VUI parameters (num_units_in_tick /
  258. time_scale). Combined with @option{num_ticks_poc_diff_one}, this can
  259. set a constant framerate in the stream. Note that it is likely to be
  260. overridden by container parameters when the stream is in a container.
  261. @item num_ticks_poc_diff_one
  262. Set poc_proportional_to_timing_flag in VPS and VUI and use this value
  263. to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
  264. E.3.1). Ignored if @option{tick_rate} is not also set.
  265. @item crop_left
  266. @item crop_right
  267. @item crop_top
  268. @item crop_bottom
  269. Set the conformance window cropping offsets in the SPS. These values
  270. will replace the current ones if the stream is already cropped.
  271. These fields are set in pixels. Note that some sizes may not be
  272. representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
  273. @item level
  274. Set the level in the VPS and SPS. See H.265 section A.4 and tables
  275. A.6 and A.7.
  276. The argument must be the name of a level (for example, @samp{5.1}), a
  277. @emph{general_level_idc} value (for example, @samp{153} for level 5.1),
  278. or the special name @samp{auto} indicating that the filter should
  279. attempt to guess the level from the input stream properties.
  280. @end table
  281. @section hevc_mp4toannexb
  282. Convert an HEVC/H.265 bitstream from length prefixed mode to start code
  283. prefixed mode (as defined in the Annex B of the ITU-T H.265
  284. specification).
  285. This is required by some streaming formats, typically the MPEG-2
  286. transport stream format (muxer @code{mpegts}).
  287. For example to remux an MP4 file containing an HEVC stream to mpegts
  288. format with @command{ffmpeg}, you can use the command:
  289. @example
  290. ffmpeg -i INPUT.mp4 -codec copy -bsf:v hevc_mp4toannexb OUTPUT.ts
  291. @end example
  292. Please note that this filter is auto-inserted for MPEG-TS (muxer
  293. @code{mpegts}) and raw HEVC/H.265 (muxer @code{h265} or
  294. @code{hevc}) output formats.
  295. @section imxdump
  296. Modifies the bitstream to fit in MOV and to be usable by the Final Cut
  297. Pro decoder. This filter only applies to the mpeg2video codec, and is
  298. likely not needed for Final Cut Pro 7 and newer with the appropriate
  299. @option{-tag:v}.
  300. For example, to remux 30 MB/sec NTSC IMX to MOV:
  301. @example
  302. ffmpeg -i input.mxf -c copy -bsf:v imxdump -tag:v mx3n output.mov
  303. @end example
  304. @section mjpeg2jpeg
  305. Convert MJPEG/AVI1 packets to full JPEG/JFIF packets.
  306. MJPEG is a video codec wherein each video frame is essentially a
  307. JPEG image. The individual frames can be extracted without loss,
  308. e.g. by
  309. @example
  310. ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg
  311. @end example
  312. Unfortunately, these chunks are incomplete JPEG images, because
  313. they lack the DHT segment required for decoding. Quoting from
  314. @url{http://www.digitalpreservation.gov/formats/fdd/fdd000063.shtml}:
  315. Avery Lee, writing in the rec.video.desktop newsgroup in 2001,
  316. commented that "MJPEG, or at least the MJPEG in AVIs having the
  317. MJPG fourcc, is restricted JPEG with a fixed -- and *omitted* --
  318. Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2,
  319. and it must use basic Huffman encoding, not arithmetic or
  320. progressive. . . . You can indeed extract the MJPEG frames and
  321. decode them with a regular JPEG decoder, but you have to prepend
  322. the DHT segment to them, or else the decoder won't have any idea
  323. how to decompress the data. The exact table necessary is given in
  324. the OpenDML spec."
  325. This bitstream filter patches the header of frames extracted from an MJPEG
  326. stream (carrying the AVI1 header ID and lacking a DHT segment) to
  327. produce fully qualified JPEG images.
  328. @example
  329. ffmpeg -i mjpeg-movie.avi -c:v copy -bsf:v mjpeg2jpeg frame_%d.jpg
  330. exiftran -i -9 frame*.jpg
  331. ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
  332. @end example
  333. @section mjpegadump
  334. Add an MJPEG A header to the bitstream, to enable decoding by
  335. Quicktime.
  336. @anchor{mov2textsub}
  337. @section mov2textsub
  338. Extract a representable text file from MOV subtitles, stripping the
  339. metadata header from each subtitle packet.
  340. See also the @ref{text2movsub} filter.
  341. @section mp3decomp
  342. Decompress non-standard compressed MP3 audio headers.
  343. @section mpeg2_metadata
  344. Modify metadata embedded in an MPEG-2 stream.
  345. @table @option
  346. @item display_aspect_ratio
  347. Set the display aspect ratio in the stream.
  348. The following fixed values are supported:
  349. @table @option
  350. @item 4/3
  351. @item 16/9
  352. @item 221/100
  353. @end table
  354. Any other value will result in square pixels being signalled instead
  355. (see H.262 section 6.3.3 and table 6-3).
  356. @item frame_rate
  357. Set the frame rate in the stream. This is constructed from a table
  358. of known values combined with a small multiplier and divisor - if
  359. the supplied value is not exactly representable, the nearest
  360. representable value will be used instead (see H.262 section 6.3.3
  361. and table 6-4).
  362. @item video_format
  363. Set the video format in the stream (see H.262 section 6.3.6 and
  364. table 6-6).
  365. @item colour_primaries
  366. @item transfer_characteristics
  367. @item matrix_coefficients
  368. Set the colour description in the stream (see H.262 section 6.3.6
  369. and tables 6-7, 6-8 and 6-9).
  370. @end table
  371. @section mpeg4_unpack_bframes
  372. Unpack DivX-style packed B-frames.
  373. DivX-style packed B-frames are not valid MPEG-4 and were only a
  374. workaround for the broken Video for Windows subsystem.
  375. They use more space, can cause minor AV sync issues, require more
  376. CPU power to decode (unless the player has some decoded picture queue
  377. to compensate the 2,0,2,0 frame per packet style) and cause
  378. trouble if copied into a standard container like mp4 or mpeg-ps/ts,
  379. because MPEG-4 decoders may not be able to decode them, since they are
  380. not valid MPEG-4.
  381. For example to fix an AVI file containing an MPEG-4 stream with
  382. DivX-style packed B-frames using @command{ffmpeg}, you can use the command:
  383. @example
  384. ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
  385. @end example
  386. @section noise
  387. Damages the contents of packets or simply drops them without damaging the
  388. container. Can be used for fuzzing or testing error resilience/concealment.
  389. Parameters:
  390. @table @option
  391. @item amount
  392. A numeral string, whose value is related to how often output bytes will
  393. be modified. Therefore, values below or equal to 0 are forbidden, and
  394. the lower the more frequent bytes will be modified, with 1 meaning
  395. every byte is modified.
  396. @item dropamount
  397. A numeral string, whose value is related to how often packets will be dropped.
  398. Therefore, values below or equal to 0 are forbidden, and the lower the more
  399. frequent packets will be dropped, with 1 meaning every packet is dropped.
  400. @end table
  401. The following example applies the modification to every byte but does not drop
  402. any packets.
  403. @example
  404. ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
  405. @end example
  406. @section null
  407. This bitstream filter passes the packets through unchanged.
  408. @section prores_metadata
  409. Modify color property metadata embedded in prores stream.
  410. @table @option
  411. @item color_primaries
  412. Set the color primaries.
  413. Available values are:
  414. @table @samp
  415. @item auto
  416. Keep the same color primaries property (default).
  417. @item unknown
  418. @item bt709
  419. @item bt470bg
  420. BT601 625
  421. @item smpte170m
  422. BT601 525
  423. @item bt2020
  424. @item smpte431
  425. DCI P3
  426. @item smpte432
  427. P3 D65
  428. @end table
  429. @item transfer_characteristics
  430. Set the color transfer.
  431. Available values are:
  432. @table @samp
  433. @item auto
  434. Keep the same transfer characteristics property (default).
  435. @item unknown
  436. @item bt709
  437. BT 601, BT 709, BT 2020
  438. @end table
  439. @item matrix_coefficients
  440. Set the matrix coefficient.
  441. Available values are:
  442. @table @samp
  443. @item auto
  444. Keep the same transfer characteristics property (default).
  445. @item unknown
  446. @item bt709
  447. @item smpte170m
  448. BT 601
  449. @item bt2020nc
  450. @end table
  451. @end table
  452. Set Rec709 colorspace for each frame of the file
  453. @example
  454. ffmpeg -i INPUT -c copy -bsf:v prores_metadata=color_primaries=bt709:color_trc=bt709:colorspace=bt709 output.mov
  455. @end example
  456. @section remove_extra
  457. Remove extradata from packets.
  458. It accepts the following parameter:
  459. @table @option
  460. @item freq
  461. Set which frame types to remove extradata from.
  462. @table @samp
  463. @item k
  464. Remove extradata from non-keyframes only.
  465. @item keyframe
  466. Remove extradata from keyframes only.
  467. @item e, all
  468. Remove extradata from all frames.
  469. @end table
  470. @end table
  471. @anchor{text2movsub}
  472. @section text2movsub
  473. Convert text subtitles to MOV subtitles (as used by the @code{mov_text}
  474. codec) with metadata headers.
  475. See also the @ref{mov2textsub} filter.
  476. @section trace_headers
  477. Log trace output containing all syntax elements in the coded stream
  478. headers (everything above the level of individual coded blocks).
  479. This can be useful for debugging low-level stream issues.
  480. Supports AV1, H.264, H.265, (M)JPEG, MPEG-2 and VP9, but depending
  481. on the build only a subset of these may be available.
  482. @section truehd_core
  483. Extract the core from a TrueHD stream, dropping ATMOS data.
  484. @section vp9_metadata
  485. Modify metadata embedded in a VP9 stream.
  486. @table @option
  487. @item color_space
  488. Set the color space value in the frame header.
  489. @table @samp
  490. @item unknown
  491. @item bt601
  492. @item bt709
  493. @item smpte170
  494. @item smpte240
  495. @item bt2020
  496. @item rgb
  497. @end table
  498. @item color_range
  499. Set the color range value in the frame header. Note that this cannot
  500. be set in RGB streams.
  501. @table @samp
  502. @item tv
  503. @item pc
  504. @end table
  505. @end table
  506. @section vp9_superframe
  507. Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
  508. fixes merging of split/segmented VP9 streams where the alt-ref frame
  509. was split from its visible counterpart.
  510. @section vp9_superframe_split
  511. Split VP9 superframes into single frames.
  512. @section vp9_raw_reorder
  513. Given a VP9 stream with correct timestamps but possibly out of order,
  514. insert additional show-existing-frame packets to correct the ordering.
  515. @c man end BITSTREAM FILTERS