bitstream_filters.texi 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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{time_scale / num_units_in_display_tick}) 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 dovi_rpu
  79. Manipulate Dolby Vision metadata in a HEVC/AV1 bitstream, optionally enabling
  80. metadata compression.
  81. @table @option
  82. @item strip
  83. If enabled, strip all Dolby Vision metadata (configuration record + RPU data
  84. blocks) from the stream.
  85. @item compression
  86. Which compression level to enable.
  87. @table @samp
  88. @item none
  89. No metadata compression.
  90. @item limited
  91. Limited metadata compression scheme. Should be compatible with most devices.
  92. This is the default.
  93. @item extended
  94. Extended metadata compression. Devices are not required to support this. Note
  95. that this level currently behaves the same as @samp{limited} in libavcodec.
  96. @end table
  97. @end table
  98. @section dump_extra
  99. Add extradata to the beginning of the filtered packets except when
  100. said packets already exactly begin with the extradata that is intended
  101. to be added.
  102. @table @option
  103. @item freq
  104. The additional argument specifies which packets should be filtered.
  105. It accepts the values:
  106. @table @samp
  107. @item k
  108. @item keyframe
  109. add extradata to all key packets
  110. @item e
  111. @item all
  112. add extradata to all packets
  113. @end table
  114. @end table
  115. If not specified it is assumed @samp{k}.
  116. For example the following @command{ffmpeg} command forces a global
  117. header (thus disabling individual packet headers) in the H.264 packets
  118. generated by the @code{libx264} encoder, but corrects them by adding
  119. the header stored in extradata to the key packets:
  120. @example
  121. ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
  122. @end example
  123. @section dv_error_marker
  124. Blocks in DV which are marked as damaged are replaced by blocks of the specified color.
  125. @table @option
  126. @item color
  127. The color to replace damaged blocks by
  128. @item sta
  129. A 16 bit mask which specifies which of the 16 possible error status values are
  130. to be replaced by colored blocks. 0xFFFE is the default which replaces all non 0
  131. error status values.
  132. @table @samp
  133. @item ok
  134. No error, no concealment
  135. @item err
  136. Error, No concealment
  137. @item res
  138. Reserved
  139. @item notok
  140. Error or concealment
  141. @item notres
  142. Not reserved
  143. @item Aa, Ba, Ca, Ab, Bb, Cb, A, B, C, a, b, erri, erru
  144. The specific error status code
  145. @end table
  146. see page 44-46 or section 5.5 of
  147. @url{http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf}
  148. @end table
  149. @section eac3_core
  150. Extract the core from a E-AC-3 stream, dropping extra channels.
  151. @section extract_extradata
  152. Extract the in-band extradata.
  153. Certain codecs allow the long-term headers (e.g. MPEG-2 sequence headers,
  154. or H.264/HEVC (VPS/)SPS/PPS) to be transmitted either "in-band" (i.e. as a part
  155. of the bitstream containing the coded frames) or "out of band" (e.g. on the
  156. container level). This latter form is called "extradata" in FFmpeg terminology.
  157. This bitstream filter detects the in-band headers and makes them available as
  158. extradata.
  159. @table @option
  160. @item remove
  161. When this option is enabled, the long-term headers are removed from the
  162. bitstream after extraction.
  163. @end table
  164. @section filter_units
  165. Remove units with types in or not in a given set from the stream.
  166. @table @option
  167. @item pass_types
  168. List of unit types or ranges of unit types to pass through while removing
  169. all others. This is specified as a '|'-separated list of unit type values
  170. or ranges of values with '-'.
  171. @item remove_types
  172. Identical to @option{pass_types}, except the units in the given set
  173. removed and all others passed through.
  174. @end table
  175. The types used by pass_types and remove_types correspond to NAL unit types
  176. (nal_unit_type) in H.264, HEVC and H.266 (see Table 7-1 in the H.264
  177. and HEVC specifications or Table 5 in the H.266 specification), to
  178. marker values for JPEG (without 0xFF prefix) and to start codes without
  179. start code prefix (i.e. the byte following the 0x000001) for MPEG-2.
  180. For VP8 and VP9, every unit has type zero.
  181. Extradata is unchanged by this transformation, but note that if the stream
  182. contains inline parameter sets then the output may be unusable if they are
  183. removed.
  184. For example, to remove all non-VCL NAL units from an H.264 stream:
  185. @example
  186. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=pass_types=1-5' OUTPUT
  187. @end example
  188. To remove all AUDs, SEI and filler from an H.265 stream:
  189. @example
  190. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=35|38-40' OUTPUT
  191. @end example
  192. To remove all user data from a MPEG-2 stream, including Closed Captions:
  193. @example
  194. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=178' OUTPUT
  195. @end example
  196. To remove all SEI from a H264 stream, including Closed Captions:
  197. @example
  198. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=6' OUTPUT
  199. @end example
  200. To remove all prefix and suffix SEI from a HEVC stream, including Closed Captions and dynamic HDR:
  201. @example
  202. ffmpeg -i INPUT -c:v copy -bsf:v 'filter_units=remove_types=39|40' OUTPUT
  203. @end example
  204. @section hapqa_extract
  205. Extract Rgb or Alpha part of an HAPQA file, without recompression, in order to create an HAPQ or an HAPAlphaOnly file.
  206. @table @option
  207. @item texture
  208. Specifies the texture to keep.
  209. @table @option
  210. @item color
  211. @item alpha
  212. @end table
  213. @end table
  214. Convert HAPQA to HAPQ
  215. @example
  216. 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
  217. @end example
  218. Convert HAPQA to HAPAlphaOnly
  219. @example
  220. 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
  221. @end example
  222. @section h264_metadata
  223. Modify metadata embedded in an H.264 stream.
  224. @table @option
  225. @item aud
  226. Insert or remove AUD NAL units in all access units of the stream.
  227. @table @samp
  228. @item pass
  229. @item insert
  230. @item remove
  231. @end table
  232. Default is pass.
  233. @item sample_aspect_ratio
  234. Set the sample aspect ratio of the stream in the VUI parameters.
  235. See H.264 table E-1.
  236. @item overscan_appropriate_flag
  237. Set whether the stream is suitable for display using overscan
  238. or not (see H.264 section E.2.1).
  239. @item video_format
  240. @item video_full_range_flag
  241. Set the video format in the stream (see H.264 section E.2.1 and
  242. table E-2).
  243. @item colour_primaries
  244. @item transfer_characteristics
  245. @item matrix_coefficients
  246. Set the colour description in the stream (see H.264 section E.2.1
  247. and tables E-3, E-4 and E-5).
  248. @item chroma_sample_loc_type
  249. Set the chroma sample location in the stream (see H.264 section
  250. E.2.1 and figure E-1).
  251. @item tick_rate
  252. Set the tick rate (time_scale / num_units_in_tick) in the VUI
  253. parameters. This is the smallest time unit representable in the
  254. stream, and in many cases represents the field rate of the stream
  255. (double the frame rate).
  256. @item fixed_frame_rate_flag
  257. Set whether the stream has fixed framerate - typically this indicates
  258. that the framerate is exactly half the tick rate, but the exact
  259. meaning is dependent on interlacing and the picture structure (see
  260. H.264 section E.2.1 and table E-6).
  261. @item zero_new_constraint_set_flags
  262. Zero constraint_set4_flag and constraint_set5_flag in the SPS. These
  263. bits were reserved in a previous version of the H.264 spec, and thus
  264. some hardware decoders require these to be zero. The result of zeroing
  265. this is still a valid bitstream.
  266. @item crop_left
  267. @item crop_right
  268. @item crop_top
  269. @item crop_bottom
  270. Set the frame cropping offsets in the SPS. These values will replace
  271. the current ones if the stream is already cropped.
  272. These fields are set in pixels. Note that some sizes may not be
  273. representable if the chroma is subsampled or the stream is interlaced
  274. (see H.264 section 7.4.2.1.1).
  275. @item sei_user_data
  276. Insert a string as SEI unregistered user data. The argument must
  277. be of the form @emph{UUID+string}, where the UUID is as hex digits
  278. possibly separated by hyphens, and the string can be anything.
  279. For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
  280. insert the string ``hello'' associated with the given UUID.
  281. @item delete_filler
  282. Deletes both filler NAL units and filler SEI messages.
  283. @item display_orientation
  284. Insert, extract or remove Display orientation SEI messages.
  285. See H.264 section D.1.27 and D.2.27 for syntax and semantics.
  286. @table @samp
  287. @item pass
  288. @item insert
  289. @item remove
  290. @item extract
  291. @end table
  292. Default is pass.
  293. Insert mode works in conjunction with @code{rotate} and @code{flip} options.
  294. Any pre-existing Display orientation messages will be removed in insert or remove mode.
  295. Extract mode attaches the display matrix to the packet as side data.
  296. @item rotate
  297. Set rotation in display orientation SEI (anticlockwise angle in degrees).
  298. Range is -360 to +360. Default is NaN.
  299. @item flip
  300. Set flip in display orientation SEI.
  301. @table @samp
  302. @item horizontal
  303. @item vertical
  304. @end table
  305. Default is unset.
  306. @item level
  307. Set the level in the SPS. Refer to H.264 section A.3 and tables A-1
  308. to A-5.
  309. The argument must be the name of a level (for example, @samp{4.2}), a
  310. level_idc value (for example, @samp{42}), or the special name @samp{auto}
  311. indicating that the filter should attempt to guess the level from the
  312. input stream properties.
  313. @end table
  314. @section h264_mp4toannexb
  315. Convert an H.264 bitstream from length prefixed mode to start code
  316. prefixed mode (as defined in the Annex B of the ITU-T H.264
  317. specification).
  318. This is required by some streaming formats, typically the MPEG-2
  319. transport stream format (muxer @code{mpegts}).
  320. For example to remux an MP4 file containing an H.264 stream to mpegts
  321. format with @command{ffmpeg}, you can use the command:
  322. @example
  323. ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
  324. @end example
  325. Please note that this filter is auto-inserted for MPEG-TS (muxer
  326. @code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
  327. @section h264_redundant_pps
  328. This applies a specific fixup to some Blu-ray BDMV H264 streams
  329. which contain redundant PPSs. The PPSs modify irrelevant parameters
  330. of the stream, confusing other transformations which require
  331. the correct extradata.
  332. The encoder used on these impacted streams adds extra PPSs throughout
  333. the stream, varying the initial QP and whether weighted prediction
  334. was enabled. This causes issues after copying the stream into
  335. a global header container, as the starting PPS is not suitable
  336. for the rest of the stream. One side effect, for example,
  337. is seeking will return garbled output until a new PPS appears.
  338. This BSF removes the extra PPSs and rewrites the slice headers
  339. such that the stream uses a single leading PPS in the global header,
  340. which resolves the issue.
  341. @section hevc_metadata
  342. Modify metadata embedded in an HEVC stream.
  343. @table @option
  344. @item aud
  345. Insert or remove AUD NAL units in all access units of the stream.
  346. @table @samp
  347. @item insert
  348. @item remove
  349. @end table
  350. @item sample_aspect_ratio
  351. Set the sample aspect ratio in the stream in the VUI parameters.
  352. @item video_format
  353. @item video_full_range_flag
  354. Set the video format in the stream (see H.265 section E.3.1 and
  355. table E.2).
  356. @item colour_primaries
  357. @item transfer_characteristics
  358. @item matrix_coefficients
  359. Set the colour description in the stream (see H.265 section E.3.1
  360. and tables E.3, E.4 and E.5).
  361. @item chroma_sample_loc_type
  362. Set the chroma sample location in the stream (see H.265 section
  363. E.3.1 and figure E.1).
  364. @item tick_rate
  365. Set the tick rate in the VPS and VUI parameters (time_scale /
  366. num_units_in_tick). Combined with @option{num_ticks_poc_diff_one}, this can
  367. set a constant framerate in the stream. Note that it is likely to be
  368. overridden by container parameters when the stream is in a container.
  369. @item num_ticks_poc_diff_one
  370. Set poc_proportional_to_timing_flag in VPS and VUI and use this value
  371. to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
  372. E.3.1). Ignored if @option{tick_rate} is not also set.
  373. @item crop_left
  374. @item crop_right
  375. @item crop_top
  376. @item crop_bottom
  377. Set the conformance window cropping offsets in the SPS. These values
  378. will replace the current ones if the stream is already cropped.
  379. These fields are set in pixels. Note that some sizes may not be
  380. representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
  381. @item width
  382. @item height
  383. Set width and height after crop.
  384. @item level
  385. Set the level in the VPS and SPS. See H.265 section A.4 and tables
  386. A.6 and A.7.
  387. The argument must be the name of a level (for example, @samp{5.1}), a
  388. @emph{general_level_idc} value (for example, @samp{153} for level 5.1),
  389. or the special name @samp{auto} indicating that the filter should
  390. attempt to guess the level from the input stream properties.
  391. @end table
  392. @section hevc_mp4toannexb
  393. Convert an HEVC/H.265 bitstream from length prefixed mode to start code
  394. prefixed mode (as defined in the Annex B of the ITU-T H.265
  395. specification).
  396. This is required by some streaming formats, typically the MPEG-2
  397. transport stream format (muxer @code{mpegts}).
  398. For example to remux an MP4 file containing an HEVC stream to mpegts
  399. format with @command{ffmpeg}, you can use the command:
  400. @example
  401. ffmpeg -i INPUT.mp4 -codec copy -bsf:v hevc_mp4toannexb OUTPUT.ts
  402. @end example
  403. Please note that this filter is auto-inserted for MPEG-TS (muxer
  404. @code{mpegts}) and raw HEVC/H.265 (muxer @code{h265} or
  405. @code{hevc}) output formats.
  406. @section imxdump
  407. Modifies the bitstream to fit in MOV and to be usable by the Final Cut
  408. Pro decoder. This filter only applies to the mpeg2video codec, and is
  409. likely not needed for Final Cut Pro 7 and newer with the appropriate
  410. @option{-tag:v}.
  411. For example, to remux 30 MB/sec NTSC IMX to MOV:
  412. @example
  413. ffmpeg -i input.mxf -c copy -bsf:v imxdump -tag:v mx3n output.mov
  414. @end example
  415. @section mjpeg2jpeg
  416. Convert MJPEG/AVI1 packets to full JPEG/JFIF packets.
  417. MJPEG is a video codec wherein each video frame is essentially a
  418. JPEG image. The individual frames can be extracted without loss,
  419. e.g. by
  420. @example
  421. ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg
  422. @end example
  423. Unfortunately, these chunks are incomplete JPEG images, because
  424. they lack the DHT segment required for decoding. Quoting from
  425. @url{http://www.digitalpreservation.gov/formats/fdd/fdd000063.shtml}:
  426. Avery Lee, writing in the rec.video.desktop newsgroup in 2001,
  427. commented that "MJPEG, or at least the MJPEG in AVIs having the
  428. MJPG fourcc, is restricted JPEG with a fixed -- and *omitted* --
  429. Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2,
  430. and it must use basic Huffman encoding, not arithmetic or
  431. progressive. . . . You can indeed extract the MJPEG frames and
  432. decode them with a regular JPEG decoder, but you have to prepend
  433. the DHT segment to them, or else the decoder won't have any idea
  434. how to decompress the data. The exact table necessary is given in
  435. the OpenDML spec."
  436. This bitstream filter patches the header of frames extracted from an MJPEG
  437. stream (carrying the AVI1 header ID and lacking a DHT segment) to
  438. produce fully qualified JPEG images.
  439. @example
  440. ffmpeg -i mjpeg-movie.avi -c:v copy -bsf:v mjpeg2jpeg frame_%d.jpg
  441. exiftran -i -9 frame*.jpg
  442. ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
  443. @end example
  444. @section mjpegadump
  445. Add an MJPEG A header to the bitstream, to enable decoding by
  446. Quicktime.
  447. @anchor{mov2textsub}
  448. @section mov2textsub
  449. Extract a representable text file from MOV subtitles, stripping the
  450. metadata header from each subtitle packet.
  451. See also the @ref{text2movsub} filter.
  452. @section mpeg2_metadata
  453. Modify metadata embedded in an MPEG-2 stream.
  454. @table @option
  455. @item display_aspect_ratio
  456. Set the display aspect ratio in the stream.
  457. The following fixed values are supported:
  458. @table @option
  459. @item 4/3
  460. @item 16/9
  461. @item 221/100
  462. @end table
  463. Any other value will result in square pixels being signalled instead
  464. (see H.262 section 6.3.3 and table 6-3).
  465. @item frame_rate
  466. Set the frame rate in the stream. This is constructed from a table
  467. of known values combined with a small multiplier and divisor - if
  468. the supplied value is not exactly representable, the nearest
  469. representable value will be used instead (see H.262 section 6.3.3
  470. and table 6-4).
  471. @item video_format
  472. Set the video format in the stream (see H.262 section 6.3.6 and
  473. table 6-6).
  474. @item colour_primaries
  475. @item transfer_characteristics
  476. @item matrix_coefficients
  477. Set the colour description in the stream (see H.262 section 6.3.6
  478. and tables 6-7, 6-8 and 6-9).
  479. @end table
  480. @section mpeg4_unpack_bframes
  481. Unpack DivX-style packed B-frames.
  482. DivX-style packed B-frames are not valid MPEG-4 and were only a
  483. workaround for the broken Video for Windows subsystem.
  484. They use more space, can cause minor AV sync issues, require more
  485. CPU power to decode (unless the player has some decoded picture queue
  486. to compensate the 2,0,2,0 frame per packet style) and cause
  487. trouble if copied into a standard container like mp4 or mpeg-ps/ts,
  488. because MPEG-4 decoders may not be able to decode them, since they are
  489. not valid MPEG-4.
  490. For example to fix an AVI file containing an MPEG-4 stream with
  491. DivX-style packed B-frames using @command{ffmpeg}, you can use the command:
  492. @example
  493. ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
  494. @end example
  495. @section noise
  496. Damages the contents of packets or simply drops them without damaging the
  497. container. Can be used for fuzzing or testing error resilience/concealment.
  498. Parameters:
  499. @table @option
  500. @item amount
  501. Accepts an expression whose evaluation per-packet determines how often bytes in that
  502. packet will be modified. A value below 0 will result in a variable frequency.
  503. Default is 0 which results in no modification. However, if neither amount nor drop is specified,
  504. amount will be set to @var{-1}. See below for accepted variables.
  505. @item drop
  506. Accepts an expression evaluated per-packet whose value determines whether that packet is dropped.
  507. Evaluation to a positive value results in the packet being dropped. Evaluation to a negative
  508. value results in a variable chance of it being dropped, roughly inverse in proportion to the magnitude
  509. of the value. Default is 0 which results in no drops. See below for accepted variables.
  510. @item dropamount
  511. Accepts a non-negative integer, which assigns a variable chance of it being dropped, roughly inverse
  512. in proportion to the value. Default is 0 which results in no drops. This option is kept for backwards
  513. compatibility and is equivalent to setting drop to a negative value with the same magnitude
  514. i.e. @code{dropamount=4} is the same as @code{drop=-4}. Ignored if drop is also specified.
  515. @end table
  516. Both @code{amount} and @code{drop} accept expressions containing the following variables:
  517. @table @samp
  518. @item n
  519. The index of the packet, starting from zero.
  520. @item tb
  521. The timebase for packet timestamps.
  522. @item pts
  523. Packet presentation timestamp.
  524. @item dts
  525. Packet decoding timestamp.
  526. @item nopts
  527. Constant representing AV_NOPTS_VALUE.
  528. @item startpts
  529. First non-AV_NOPTS_VALUE PTS seen in the stream.
  530. @item startdts
  531. First non-AV_NOPTS_VALUE DTS seen in the stream.
  532. @item duration
  533. @itemx d
  534. Packet duration, in timebase units.
  535. @item pos
  536. Packet position in input; may be -1 when unknown or not set.
  537. @item size
  538. Packet size, in bytes.
  539. @item key
  540. Whether packet is marked as a keyframe.
  541. @item state
  542. A pseudo random integer, primarily derived from the content of packet payload.
  543. @end table
  544. @subsection Examples
  545. Apply modification to every byte but don't drop any packets.
  546. @example
  547. ffmpeg -i INPUT -c copy -bsf noise=1 output.mkv
  548. @end example
  549. Drop every video packet not marked as a keyframe after timestamp 30s but do not
  550. modify any of the remaining packets.
  551. @example
  552. ffmpeg -i INPUT -c copy -bsf:v noise=drop='gt(t\,30)*not(key)' output.mkv
  553. @end example
  554. Drop one second of audio every 10 seconds and add some random noise to the rest.
  555. @example
  556. ffmpeg -i INPUT -c copy -bsf:a noise=amount=-1:drop='between(mod(t\,10)\,9\,10)' output.mkv
  557. @end example
  558. @section null
  559. This bitstream filter passes the packets through unchanged.
  560. @section pcm_rechunk
  561. Repacketize PCM audio to a fixed number of samples per packet or a fixed packet
  562. rate per second. This is similar to the @ref{asetnsamples,,asetnsamples audio
  563. filter,ffmpeg-filters} but works on audio packets instead of audio frames.
  564. @table @option
  565. @item nb_out_samples, n
  566. Set the number of samples per each output audio packet. The number is intended
  567. as the number of samples @emph{per each channel}. Default value is 1024.
  568. @item pad, p
  569. If set to 1, the filter will pad the last audio packet with silence, so that it
  570. will contain the same number of samples (or roughly the same number of samples,
  571. see @option{frame_rate}) as the previous ones. Default value is 1.
  572. @item frame_rate, r
  573. This option makes the filter output a fixed number of packets per second instead
  574. of a fixed number of samples per packet. If the audio sample rate is not
  575. divisible by the frame rate then the number of samples will not be constant but
  576. will vary slightly so that each packet will start as close to the frame
  577. boundary as possible. Using this option has precedence over @option{nb_out_samples}.
  578. @end table
  579. You can generate the well known 1602-1601-1602-1601-1602 pattern of 48kHz audio
  580. for NTSC frame rate using the @option{frame_rate} option.
  581. @example
  582. ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf pcm_rechunk=r=30000/1001 -f framecrc -
  583. @end example
  584. @section pgs_frame_merge
  585. Merge a sequence of PGS Subtitle segments ending with an "end of display set"
  586. segment into a single packet.
  587. This is required by some containers that support PGS subtitles
  588. (muxer @code{matroska}).
  589. @section prores_metadata
  590. Modify color property metadata embedded in prores stream.
  591. @table @option
  592. @item color_primaries
  593. Set the color primaries.
  594. Available values are:
  595. @table @samp
  596. @item auto
  597. Keep the same color primaries property (default).
  598. @item unknown
  599. @item bt709
  600. @item bt470bg
  601. BT601 625
  602. @item smpte170m
  603. BT601 525
  604. @item bt2020
  605. @item smpte431
  606. DCI P3
  607. @item smpte432
  608. P3 D65
  609. @end table
  610. @item transfer_characteristics
  611. Set the color transfer.
  612. Available values are:
  613. @table @samp
  614. @item auto
  615. Keep the same transfer characteristics property (default).
  616. @item unknown
  617. @item bt709
  618. BT 601, BT 709, BT 2020
  619. @item smpte2084
  620. SMPTE ST 2084
  621. @item arib-std-b67
  622. ARIB STD-B67
  623. @end table
  624. @item matrix_coefficients
  625. Set the matrix coefficient.
  626. Available values are:
  627. @table @samp
  628. @item auto
  629. Keep the same colorspace property (default).
  630. @item unknown
  631. @item bt709
  632. @item smpte170m
  633. BT 601
  634. @item bt2020nc
  635. @end table
  636. @end table
  637. Set Rec709 colorspace for each frame of the file
  638. @example
  639. ffmpeg -i INPUT -c copy -bsf:v prores_metadata=color_primaries=bt709:color_trc=bt709:colorspace=bt709 output.mov
  640. @end example
  641. Set Hybrid Log-Gamma parameters for each frame of the file
  642. @example
  643. ffmpeg -i INPUT -c copy -bsf:v prores_metadata=color_primaries=bt2020:color_trc=arib-std-b67:colorspace=bt2020nc output.mov
  644. @end example
  645. @section remove_extra
  646. Remove extradata from packets.
  647. It accepts the following parameter:
  648. @table @option
  649. @item freq
  650. Set which frame types to remove extradata from.
  651. @table @samp
  652. @item k
  653. Remove extradata from non-keyframes only.
  654. @item keyframe
  655. Remove extradata from keyframes only.
  656. @item e, all
  657. Remove extradata from all frames.
  658. @end table
  659. @end table
  660. @section setts
  661. Set PTS and DTS in packets.
  662. It accepts the following parameters:
  663. @table @option
  664. @item ts
  665. @item pts
  666. @item dts
  667. Set expressions for PTS, DTS or both.
  668. @item duration
  669. Set expression for duration.
  670. @item time_base
  671. Set output time base.
  672. @end table
  673. The expressions are evaluated through the eval API and can contain the following
  674. constants:
  675. @table @option
  676. @item N
  677. The count of the input packet. Starting from 0.
  678. @item TS
  679. The demux timestamp in input in case of @code{ts} or @code{dts} option or presentation
  680. timestamp in case of @code{pts} option.
  681. @item POS
  682. The original position in the file of the packet, or undefined if undefined
  683. for the current packet
  684. @item DTS
  685. The demux timestamp in input.
  686. @item PTS
  687. The presentation timestamp in input.
  688. @item DURATION
  689. The duration in input.
  690. @item STARTDTS
  691. The DTS of the first packet.
  692. @item STARTPTS
  693. The PTS of the first packet.
  694. @item PREV_INDTS
  695. The previous input DTS.
  696. @item PREV_INPTS
  697. The previous input PTS.
  698. @item PREV_INDURATION
  699. The previous input duration.
  700. @item PREV_OUTDTS
  701. The previous output DTS.
  702. @item PREV_OUTPTS
  703. The previous output PTS.
  704. @item PREV_OUTDURATION
  705. The previous output duration.
  706. @item NEXT_DTS
  707. The next input DTS.
  708. @item NEXT_PTS
  709. The next input PTS.
  710. @item NEXT_DURATION
  711. The next input duration.
  712. @item TB
  713. The timebase of stream packet belongs.
  714. @item TB_OUT
  715. The output timebase.
  716. @item SR
  717. The sample rate of stream packet belongs.
  718. @item NOPTS
  719. The AV_NOPTS_VALUE constant.
  720. @end table
  721. For example, to set PTS equal to DTS (not recommended if B-frames are involved):
  722. @example
  723. ffmpeg -i INPUT -c:a copy -bsf:a setts=pts=DTS out.mkv
  724. @end example
  725. @section showinfo
  726. Log basic packet information. Mainly useful for testing, debugging,
  727. and development.
  728. @anchor{text2movsub}
  729. @section text2movsub
  730. Convert text subtitles to MOV subtitles (as used by the @code{mov_text}
  731. codec) with metadata headers.
  732. See also the @ref{mov2textsub} filter.
  733. @section trace_headers
  734. Log trace output containing all syntax elements in the coded stream
  735. headers (everything above the level of individual coded blocks).
  736. This can be useful for debugging low-level stream issues.
  737. Supports AV1, H.264, H.265, (M)JPEG, MPEG-2 and VP9, but depending
  738. on the build only a subset of these may be available.
  739. @section truehd_core
  740. Extract the core from a TrueHD stream, dropping ATMOS data.
  741. @section vp9_metadata
  742. Modify metadata embedded in a VP9 stream.
  743. @table @option
  744. @item color_space
  745. Set the color space value in the frame header. Note that any frame
  746. set to RGB will be implicitly set to PC range and that RGB is
  747. incompatible with profiles 0 and 2.
  748. @table @samp
  749. @item unknown
  750. @item bt601
  751. @item bt709
  752. @item smpte170
  753. @item smpte240
  754. @item bt2020
  755. @item rgb
  756. @end table
  757. @item color_range
  758. Set the color range value in the frame header. Note that any value
  759. imposed by the color space will take precedence over this value.
  760. @table @samp
  761. @item tv
  762. @item pc
  763. @end table
  764. @end table
  765. @section vp9_superframe
  766. Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
  767. fixes merging of split/segmented VP9 streams where the alt-ref frame
  768. was split from its visible counterpart.
  769. @section vp9_superframe_split
  770. Split VP9 superframes into single frames.
  771. @section vp9_raw_reorder
  772. Given a VP9 stream with correct timestamps but possibly out of order,
  773. insert additional show-existing-frame packets to correct the ordering.
  774. @c man end BITSTREAM FILTERS