utils.texi 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. @chapter Syntax
  2. @c man begin SYNTAX
  3. This section documents the syntax and formats employed by the FFmpeg
  4. libraries and tools.
  5. @anchor{quoting_and_escaping}
  6. @section Quoting and escaping
  7. FFmpeg adopts the following quoting and escaping mechanism, unless
  8. explicitly specified. The following rules are applied:
  9. @itemize
  10. @item
  11. @samp{'} and @samp{\} are special characters (respectively used for
  12. quoting and escaping). In addition to them, there might be other
  13. special characters depending on the specific syntax where the escaping
  14. and quoting are employed.
  15. @item
  16. A special character is escaped by prefixing it with a @samp{\}.
  17. @item
  18. All characters enclosed between @samp{''} are included literally in the
  19. parsed string. The quote character @samp{'} itself cannot be quoted,
  20. so you may need to close the quote and escape it.
  21. @item
  22. Leading and trailing whitespaces, unless escaped or quoted, are
  23. removed from the parsed string.
  24. @end itemize
  25. Note that you may need to add a second level of escaping when using
  26. the command line or a script, which depends on the syntax of the
  27. adopted shell language.
  28. The function @code{av_get_token} defined in
  29. @file{libavutil/avstring.h} can be used to parse a token quoted or
  30. escaped according to the rules defined above.
  31. The tool @file{tools/ffescape} in the FFmpeg source tree can be used
  32. to automatically quote or escape a string in a script.
  33. @subsection Examples
  34. @itemize
  35. @item
  36. Escape the string @code{Crime d'Amour} containing the @code{'} special
  37. character:
  38. @example
  39. Crime d\'Amour
  40. @end example
  41. @item
  42. The string above contains a quote, so the @code{'} needs to be escaped
  43. when quoting it:
  44. @example
  45. 'Crime d'\''Amour'
  46. @end example
  47. @item
  48. Include leading or trailing whitespaces using quoting:
  49. @example
  50. ' this string starts and ends with whitespaces '
  51. @end example
  52. @item
  53. Escaping and quoting can be mixed together:
  54. @example
  55. ' The string '\'string\'' is a string '
  56. @end example
  57. @item
  58. To include a literal @samp{\} you can use either escaping or quoting:
  59. @example
  60. 'c:\foo' can be written as c:\\foo
  61. @end example
  62. @end itemize
  63. @anchor{date syntax}
  64. @section Date
  65. The accepted syntax is:
  66. @example
  67. [(YYYY-MM-DD|YYYYMMDD)[T|t| ]]((HH:MM:SS[.m...]]])|(HHMMSS[.m...]]]))[Z]
  68. now
  69. @end example
  70. If the value is "now" it takes the current time.
  71. Time is local time unless Z is appended, in which case it is
  72. interpreted as UTC.
  73. If the year-month-day part is not specified it takes the current
  74. year-month-day.
  75. @anchor{time duration syntax}
  76. @section Time duration
  77. There are two accepted syntaxes for expressing time duration.
  78. @example
  79. [-][@var{HH}:]@var{MM}:@var{SS}[.@var{m}...]
  80. @end example
  81. @var{HH} expresses the number of hours, @var{MM} the number of minutes
  82. for a maximum of 2 digits, and @var{SS} the number of seconds for a
  83. maximum of 2 digits. The @var{m} at the end expresses decimal value for
  84. @var{SS}.
  85. @emph{or}
  86. @example
  87. [-]@var{S}+[.@var{m}...][s|ms|us]
  88. @end example
  89. @var{S} expresses the number of seconds, with the optional decimal part
  90. @var{m}. The optional literal suffixes @samp{s}, @samp{ms} or @samp{us}
  91. indicate to interpret the value as seconds, milliseconds or microseconds,
  92. respectively.
  93. In both expressions, the optional @samp{-} indicates negative duration.
  94. @subsection Examples
  95. The following examples are all valid time duration:
  96. @table @samp
  97. @item 55
  98. 55 seconds
  99. @item 0.2
  100. 0.2 seconds
  101. @item 200ms
  102. 200 milliseconds, that's 0.2s
  103. @item 200000us
  104. 200000 microseconds, that's 0.2s
  105. @item 12:03:45
  106. 12 hours, 03 minutes and 45 seconds
  107. @item 23.189
  108. 23.189 seconds
  109. @end table
  110. @anchor{video size syntax}
  111. @section Video size
  112. Specify the size of the sourced video, it may be a string of the form
  113. @var{width}x@var{height}, or the name of a size abbreviation.
  114. The following abbreviations are recognized:
  115. @table @samp
  116. @item ntsc
  117. 720x480
  118. @item pal
  119. 720x576
  120. @item qntsc
  121. 352x240
  122. @item qpal
  123. 352x288
  124. @item sntsc
  125. 640x480
  126. @item spal
  127. 768x576
  128. @item film
  129. 352x240
  130. @item ntsc-film
  131. 352x240
  132. @item sqcif
  133. 128x96
  134. @item qcif
  135. 176x144
  136. @item cif
  137. 352x288
  138. @item 4cif
  139. 704x576
  140. @item 16cif
  141. 1408x1152
  142. @item qqvga
  143. 160x120
  144. @item qvga
  145. 320x240
  146. @item vga
  147. 640x480
  148. @item svga
  149. 800x600
  150. @item xga
  151. 1024x768
  152. @item uxga
  153. 1600x1200
  154. @item qxga
  155. 2048x1536
  156. @item sxga
  157. 1280x1024
  158. @item qsxga
  159. 2560x2048
  160. @item hsxga
  161. 5120x4096
  162. @item wvga
  163. 852x480
  164. @item wxga
  165. 1366x768
  166. @item wsxga
  167. 1600x1024
  168. @item wuxga
  169. 1920x1200
  170. @item woxga
  171. 2560x1600
  172. @item wqsxga
  173. 3200x2048
  174. @item wquxga
  175. 3840x2400
  176. @item whsxga
  177. 6400x4096
  178. @item whuxga
  179. 7680x4800
  180. @item cga
  181. 320x200
  182. @item ega
  183. 640x350
  184. @item hd480
  185. 852x480
  186. @item hd720
  187. 1280x720
  188. @item hd1080
  189. 1920x1080
  190. @item 2k
  191. 2048x1080
  192. @item 2kflat
  193. 1998x1080
  194. @item 2kscope
  195. 2048x858
  196. @item 4k
  197. 4096x2160
  198. @item 4kflat
  199. 3996x2160
  200. @item 4kscope
  201. 4096x1716
  202. @item nhd
  203. 640x360
  204. @item hqvga
  205. 240x160
  206. @item wqvga
  207. 400x240
  208. @item fwqvga
  209. 432x240
  210. @item hvga
  211. 480x320
  212. @item qhd
  213. 960x540
  214. @item 2kdci
  215. 2048x1080
  216. @item 4kdci
  217. 4096x2160
  218. @item uhd2160
  219. 3840x2160
  220. @item uhd4320
  221. 7680x4320
  222. @end table
  223. @anchor{video rate syntax}
  224. @section Video rate
  225. Specify the frame rate of a video, expressed as the number of frames
  226. generated per second. It has to be a string in the format
  227. @var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float
  228. number or a valid video frame rate abbreviation.
  229. The following abbreviations are recognized:
  230. @table @samp
  231. @item ntsc
  232. 30000/1001
  233. @item pal
  234. 25/1
  235. @item qntsc
  236. 30000/1001
  237. @item qpal
  238. 25/1
  239. @item sntsc
  240. 30000/1001
  241. @item spal
  242. 25/1
  243. @item film
  244. 24/1
  245. @item ntsc-film
  246. 24000/1001
  247. @end table
  248. @anchor{ratio syntax}
  249. @section Ratio
  250. A ratio can be expressed as an expression, or in the form
  251. @var{numerator}:@var{denominator}.
  252. Note that a ratio with infinite (1/0) or negative value is
  253. considered valid, so you should check on the returned value if you
  254. want to exclude those values.
  255. The undefined value can be expressed using the "0:0" string.
  256. @anchor{color syntax}
  257. @section Color
  258. It can be the name of a color as defined below (case insensitive match) or a
  259. @code{[0x|#]RRGGBB[AA]} sequence, possibly followed by @@ and a string
  260. representing the alpha component.
  261. The alpha component may be a string composed by "0x" followed by an
  262. hexadecimal number or a decimal number between 0.0 and 1.0, which
  263. represents the opacity value (@samp{0x00} or @samp{0.0} means completely
  264. transparent, @samp{0xff} or @samp{1.0} completely opaque). If the alpha
  265. component is not specified then @samp{0xff} is assumed.
  266. The string @samp{random} will result in a random color.
  267. The following names of colors are recognized:
  268. @table @samp
  269. @item AliceBlue
  270. 0xF0F8FF
  271. @item AntiqueWhite
  272. 0xFAEBD7
  273. @item Aqua
  274. 0x00FFFF
  275. @item Aquamarine
  276. 0x7FFFD4
  277. @item Azure
  278. 0xF0FFFF
  279. @item Beige
  280. 0xF5F5DC
  281. @item Bisque
  282. 0xFFE4C4
  283. @item Black
  284. 0x000000
  285. @item BlanchedAlmond
  286. 0xFFEBCD
  287. @item Blue
  288. 0x0000FF
  289. @item BlueViolet
  290. 0x8A2BE2
  291. @item Brown
  292. 0xA52A2A
  293. @item BurlyWood
  294. 0xDEB887
  295. @item CadetBlue
  296. 0x5F9EA0
  297. @item Chartreuse
  298. 0x7FFF00
  299. @item Chocolate
  300. 0xD2691E
  301. @item Coral
  302. 0xFF7F50
  303. @item CornflowerBlue
  304. 0x6495ED
  305. @item Cornsilk
  306. 0xFFF8DC
  307. @item Crimson
  308. 0xDC143C
  309. @item Cyan
  310. 0x00FFFF
  311. @item DarkBlue
  312. 0x00008B
  313. @item DarkCyan
  314. 0x008B8B
  315. @item DarkGoldenRod
  316. 0xB8860B
  317. @item DarkGray
  318. 0xA9A9A9
  319. @item DarkGreen
  320. 0x006400
  321. @item DarkKhaki
  322. 0xBDB76B
  323. @item DarkMagenta
  324. 0x8B008B
  325. @item DarkOliveGreen
  326. 0x556B2F
  327. @item Darkorange
  328. 0xFF8C00
  329. @item DarkOrchid
  330. 0x9932CC
  331. @item DarkRed
  332. 0x8B0000
  333. @item DarkSalmon
  334. 0xE9967A
  335. @item DarkSeaGreen
  336. 0x8FBC8F
  337. @item DarkSlateBlue
  338. 0x483D8B
  339. @item DarkSlateGray
  340. 0x2F4F4F
  341. @item DarkTurquoise
  342. 0x00CED1
  343. @item DarkViolet
  344. 0x9400D3
  345. @item DeepPink
  346. 0xFF1493
  347. @item DeepSkyBlue
  348. 0x00BFFF
  349. @item DimGray
  350. 0x696969
  351. @item DodgerBlue
  352. 0x1E90FF
  353. @item FireBrick
  354. 0xB22222
  355. @item FloralWhite
  356. 0xFFFAF0
  357. @item ForestGreen
  358. 0x228B22
  359. @item Fuchsia
  360. 0xFF00FF
  361. @item Gainsboro
  362. 0xDCDCDC
  363. @item GhostWhite
  364. 0xF8F8FF
  365. @item Gold
  366. 0xFFD700
  367. @item GoldenRod
  368. 0xDAA520
  369. @item Gray
  370. 0x808080
  371. @item Green
  372. 0x008000
  373. @item GreenYellow
  374. 0xADFF2F
  375. @item HoneyDew
  376. 0xF0FFF0
  377. @item HotPink
  378. 0xFF69B4
  379. @item IndianRed
  380. 0xCD5C5C
  381. @item Indigo
  382. 0x4B0082
  383. @item Ivory
  384. 0xFFFFF0
  385. @item Khaki
  386. 0xF0E68C
  387. @item Lavender
  388. 0xE6E6FA
  389. @item LavenderBlush
  390. 0xFFF0F5
  391. @item LawnGreen
  392. 0x7CFC00
  393. @item LemonChiffon
  394. 0xFFFACD
  395. @item LightBlue
  396. 0xADD8E6
  397. @item LightCoral
  398. 0xF08080
  399. @item LightCyan
  400. 0xE0FFFF
  401. @item LightGoldenRodYellow
  402. 0xFAFAD2
  403. @item LightGreen
  404. 0x90EE90
  405. @item LightGrey
  406. 0xD3D3D3
  407. @item LightPink
  408. 0xFFB6C1
  409. @item LightSalmon
  410. 0xFFA07A
  411. @item LightSeaGreen
  412. 0x20B2AA
  413. @item LightSkyBlue
  414. 0x87CEFA
  415. @item LightSlateGray
  416. 0x778899
  417. @item LightSteelBlue
  418. 0xB0C4DE
  419. @item LightYellow
  420. 0xFFFFE0
  421. @item Lime
  422. 0x00FF00
  423. @item LimeGreen
  424. 0x32CD32
  425. @item Linen
  426. 0xFAF0E6
  427. @item Magenta
  428. 0xFF00FF
  429. @item Maroon
  430. 0x800000
  431. @item MediumAquaMarine
  432. 0x66CDAA
  433. @item MediumBlue
  434. 0x0000CD
  435. @item MediumOrchid
  436. 0xBA55D3
  437. @item MediumPurple
  438. 0x9370D8
  439. @item MediumSeaGreen
  440. 0x3CB371
  441. @item MediumSlateBlue
  442. 0x7B68EE
  443. @item MediumSpringGreen
  444. 0x00FA9A
  445. @item MediumTurquoise
  446. 0x48D1CC
  447. @item MediumVioletRed
  448. 0xC71585
  449. @item MidnightBlue
  450. 0x191970
  451. @item MintCream
  452. 0xF5FFFA
  453. @item MistyRose
  454. 0xFFE4E1
  455. @item Moccasin
  456. 0xFFE4B5
  457. @item NavajoWhite
  458. 0xFFDEAD
  459. @item Navy
  460. 0x000080
  461. @item OldLace
  462. 0xFDF5E6
  463. @item Olive
  464. 0x808000
  465. @item OliveDrab
  466. 0x6B8E23
  467. @item Orange
  468. 0xFFA500
  469. @item OrangeRed
  470. 0xFF4500
  471. @item Orchid
  472. 0xDA70D6
  473. @item PaleGoldenRod
  474. 0xEEE8AA
  475. @item PaleGreen
  476. 0x98FB98
  477. @item PaleTurquoise
  478. 0xAFEEEE
  479. @item PaleVioletRed
  480. 0xD87093
  481. @item PapayaWhip
  482. 0xFFEFD5
  483. @item PeachPuff
  484. 0xFFDAB9
  485. @item Peru
  486. 0xCD853F
  487. @item Pink
  488. 0xFFC0CB
  489. @item Plum
  490. 0xDDA0DD
  491. @item PowderBlue
  492. 0xB0E0E6
  493. @item Purple
  494. 0x800080
  495. @item Red
  496. 0xFF0000
  497. @item RosyBrown
  498. 0xBC8F8F
  499. @item RoyalBlue
  500. 0x4169E1
  501. @item SaddleBrown
  502. 0x8B4513
  503. @item Salmon
  504. 0xFA8072
  505. @item SandyBrown
  506. 0xF4A460
  507. @item SeaGreen
  508. 0x2E8B57
  509. @item SeaShell
  510. 0xFFF5EE
  511. @item Sienna
  512. 0xA0522D
  513. @item Silver
  514. 0xC0C0C0
  515. @item SkyBlue
  516. 0x87CEEB
  517. @item SlateBlue
  518. 0x6A5ACD
  519. @item SlateGray
  520. 0x708090
  521. @item Snow
  522. 0xFFFAFA
  523. @item SpringGreen
  524. 0x00FF7F
  525. @item SteelBlue
  526. 0x4682B4
  527. @item Tan
  528. 0xD2B48C
  529. @item Teal
  530. 0x008080
  531. @item Thistle
  532. 0xD8BFD8
  533. @item Tomato
  534. 0xFF6347
  535. @item Turquoise
  536. 0x40E0D0
  537. @item Violet
  538. 0xEE82EE
  539. @item Wheat
  540. 0xF5DEB3
  541. @item White
  542. 0xFFFFFF
  543. @item WhiteSmoke
  544. 0xF5F5F5
  545. @item Yellow
  546. 0xFFFF00
  547. @item YellowGreen
  548. 0x9ACD32
  549. @end table
  550. @anchor{channel layout syntax}
  551. @section Channel Layout
  552. A channel layout specifies the spatial disposition of the channels in
  553. a multi-channel audio stream. To specify a channel layout, FFmpeg
  554. makes use of a special syntax.
  555. Individual channels are identified by an id, as given by the table
  556. below:
  557. @table @samp
  558. @item FL
  559. front left
  560. @item FR
  561. front right
  562. @item FC
  563. front center
  564. @item LFE
  565. low frequency
  566. @item BL
  567. back left
  568. @item BR
  569. back right
  570. @item FLC
  571. front left-of-center
  572. @item FRC
  573. front right-of-center
  574. @item BC
  575. back center
  576. @item SL
  577. side left
  578. @item SR
  579. side right
  580. @item TC
  581. top center
  582. @item TFL
  583. top front left
  584. @item TFC
  585. top front center
  586. @item TFR
  587. top front right
  588. @item TBL
  589. top back left
  590. @item TBC
  591. top back center
  592. @item TBR
  593. top back right
  594. @item DL
  595. downmix left
  596. @item DR
  597. downmix right
  598. @item WL
  599. wide left
  600. @item WR
  601. wide right
  602. @item SDL
  603. surround direct left
  604. @item SDR
  605. surround direct right
  606. @item LFE2
  607. low frequency 2
  608. @end table
  609. Standard channel layout compositions can be specified by using the
  610. following identifiers:
  611. @table @samp
  612. @item mono
  613. FC
  614. @item stereo
  615. FL+FR
  616. @item 2.1
  617. FL+FR+LFE
  618. @item 3.0
  619. FL+FR+FC
  620. @item 3.0(back)
  621. FL+FR+BC
  622. @item 4.0
  623. FL+FR+FC+BC
  624. @item quad
  625. FL+FR+BL+BR
  626. @item quad(side)
  627. FL+FR+SL+SR
  628. @item 3.1
  629. FL+FR+FC+LFE
  630. @item 5.0
  631. FL+FR+FC+BL+BR
  632. @item 5.0(side)
  633. FL+FR+FC+SL+SR
  634. @item 4.1
  635. FL+FR+FC+LFE+BC
  636. @item 5.1
  637. FL+FR+FC+LFE+BL+BR
  638. @item 5.1(side)
  639. FL+FR+FC+LFE+SL+SR
  640. @item 6.0
  641. FL+FR+FC+BC+SL+SR
  642. @item 6.0(front)
  643. FL+FR+FLC+FRC+SL+SR
  644. @item 3.1.2
  645. FL+FR+FC+LFE+TFL+TFR
  646. @item hexagonal
  647. FL+FR+FC+BL+BR+BC
  648. @item 6.1
  649. FL+FR+FC+LFE+BC+SL+SR
  650. @item 6.1
  651. FL+FR+FC+LFE+BL+BR+BC
  652. @item 6.1(front)
  653. FL+FR+LFE+FLC+FRC+SL+SR
  654. @item 7.0
  655. FL+FR+FC+BL+BR+SL+SR
  656. @item 7.0(front)
  657. FL+FR+FC+FLC+FRC+SL+SR
  658. @item 7.1
  659. FL+FR+FC+LFE+BL+BR+SL+SR
  660. @item 7.1(wide)
  661. FL+FR+FC+LFE+BL+BR+FLC+FRC
  662. @item 7.1(wide-side)
  663. FL+FR+FC+LFE+FLC+FRC+SL+SR
  664. @item 5.1.2
  665. FL+FR+FC+LFE+BL+BR+TFL+TFR
  666. @item octagonal
  667. FL+FR+FC+BL+BR+BC+SL+SR
  668. @item cube
  669. FL+FR+BL+BR+TFL+TFR+TBL+TBR
  670. @item 5.1.4
  671. FL+FR+FC+LFE+BL+BR+TFL+TFR+TBL+TBR
  672. @item 7.1.2
  673. FL+FR+FC+LFE+BL+BR+SL+SR+TFL+TFR
  674. @item 7.1.4
  675. FL+FR+FC+LFE+BL+BR+SL+SR+TFL+TFR+TBL+TBR
  676. @item 7.2.3
  677. FL+FR+FC+LFE+BL+BR+SL+SR+TFL+TFR+TBC+LFE2
  678. @item 9.1.4
  679. FL+FR+FC+LFE+BL+BR+FLC+FRC+SL+SR+TFL+TFR+TBL+TBR
  680. @item hexadecagonal
  681. FL+FR+FC+BL+BR+BC+SL+SR+WL+WR+TBL+TBR+TBC+TFC+TFL+TFR
  682. @item downmix
  683. DL+DR
  684. @item 22.2
  685. FL+FR+FC+LFE+BL+BR+FLC+FRC+BC+SL+SR+TC+TFL+TFC+TFR+TBL+TBC+TBR+LFE2+TSL+TSR+BFC+BFL+BFR
  686. @end table
  687. A custom channel layout can be specified as a sequence of terms, separated by '+'.
  688. Each term can be:
  689. @itemize
  690. @item
  691. the name of a single channel (e.g. @samp{FL}, @samp{FR}, @samp{FC}, @samp{LFE}, etc.),
  692. each optionally containing a custom name after a '@@', (e.g. @samp{FL@@Left},
  693. @samp{FR@@Right}, @samp{FC@@Center}, @samp{LFE@@Low_Frequency}, etc.)
  694. @end itemize
  695. A standard channel layout can be specified by the following:
  696. @itemize
  697. @item
  698. the name of a single channel (e.g. @samp{FL}, @samp{FR}, @samp{FC}, @samp{LFE}, etc.)
  699. @item
  700. the name of a standard channel layout (e.g. @samp{mono},
  701. @samp{stereo}, @samp{4.0}, @samp{quad}, @samp{5.0}, etc.)
  702. @item
  703. a number of channels, in decimal, followed by 'c', yielding the default channel
  704. layout for that number of channels (see the function
  705. @code{av_channel_layout_default}). Note that not all channel counts have a
  706. default layout.
  707. @item
  708. a number of channels, in decimal, followed by 'C', yielding an unknown channel
  709. layout with the specified number of channels. Note that not all channel layout
  710. specification strings support unknown channel layouts.
  711. @item
  712. a channel layout mask, in hexadecimal starting with "0x" (see the
  713. @code{AV_CH_*} macros in @file{libavutil/channel_layout.h}.
  714. @end itemize
  715. Before libavutil version 53 the trailing character "c" to specify a number of
  716. channels was optional, but now it is required, while a channel layout mask can
  717. also be specified as a decimal number (if and only if not followed by "c" or "C").
  718. See also the function @code{av_channel_layout_from_string} defined in
  719. @file{libavutil/channel_layout.h}.
  720. @c man end SYNTAX
  721. @chapter Expression Evaluation
  722. @c man begin EXPRESSION EVALUATION
  723. When evaluating an arithmetic expression, FFmpeg uses an internal
  724. formula evaluator, implemented through the @file{libavutil/eval.h}
  725. interface.
  726. An expression may contain unary, binary operators, constants, and
  727. functions.
  728. Two expressions @var{expr1} and @var{expr2} can be combined to form
  729. another expression "@var{expr1};@var{expr2}".
  730. @var{expr1} and @var{expr2} are evaluated in turn, and the new
  731. expression evaluates to the value of @var{expr2}.
  732. The following binary operators are available: @code{+}, @code{-},
  733. @code{*}, @code{/}, @code{^}.
  734. The following unary operators are available: @code{+}, @code{-}.
  735. Some internal variables can be used to store and load intermediary
  736. results. They can be accessed using the @code{ld} and @code{st}
  737. functions with an index argument varying from 0 to 9 to specify which
  738. internal variable to access.
  739. The following functions are available:
  740. @table @option
  741. @item abs(x)
  742. Compute absolute value of @var{x}.
  743. @item acos(x)
  744. Compute arccosine of @var{x}.
  745. @item asin(x)
  746. Compute arcsine of @var{x}.
  747. @item atan(x)
  748. Compute arctangent of @var{x}.
  749. @item atan2(y, x)
  750. Compute principal value of the arc tangent of @var{y}/@var{x}.
  751. @item between(x, min, max)
  752. Return 1 if @var{x} is greater than or equal to @var{min} and lesser than or
  753. equal to @var{max}, 0 otherwise.
  754. @item bitand(x, y)
  755. @item bitor(x, y)
  756. Compute bitwise and/or operation on @var{x} and @var{y}.
  757. The results of the evaluation of @var{x} and @var{y} are converted to
  758. integers before executing the bitwise operation.
  759. Note that both the conversion to integer and the conversion back to
  760. floating point can lose precision. Beware of unexpected results for
  761. large numbers (usually 2^53 and larger).
  762. @item ceil(expr)
  763. Round the value of expression @var{expr} upwards to the nearest
  764. integer. For example, "ceil(1.5)" is "2.0".
  765. @item clip(x, min, max)
  766. Return the value of @var{x} clipped between @var{min} and @var{max}.
  767. @item cos(x)
  768. Compute cosine of @var{x}.
  769. @item cosh(x)
  770. Compute hyperbolic cosine of @var{x}.
  771. @item eq(x, y)
  772. Return 1 if @var{x} and @var{y} are equivalent, 0 otherwise.
  773. @item exp(x)
  774. Compute exponential of @var{x} (with base @code{e}, the Euler's number).
  775. @item floor(expr)
  776. Round the value of expression @var{expr} downwards to the nearest
  777. integer. For example, "floor(-1.5)" is "-2.0".
  778. @item gauss(x)
  779. Compute Gauss function of @var{x}, corresponding to
  780. @code{exp(-x*x/2) / sqrt(2*PI)}.
  781. @item gcd(x, y)
  782. Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and
  783. @var{y} are 0 or either or both are less than zero then behavior is undefined.
  784. @item gt(x, y)
  785. Return 1 if @var{x} is greater than @var{y}, 0 otherwise.
  786. @item gte(x, y)
  787. Return 1 if @var{x} is greater than or equal to @var{y}, 0 otherwise.
  788. @item hypot(x, y)
  789. This function is similar to the C function with the same name; it returns
  790. "sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a
  791. right triangle with sides of length @var{x} and @var{y}, or the distance of the
  792. point (@var{x}, @var{y}) from the origin.
  793. @item if(x, y)
  794. Evaluate @var{x}, and if the result is non-zero return the result of
  795. the evaluation of @var{y}, return 0 otherwise.
  796. @item if(x, y, z)
  797. Evaluate @var{x}, and if the result is non-zero return the evaluation
  798. result of @var{y}, otherwise the evaluation result of @var{z}.
  799. @item ifnot(x, y)
  800. Evaluate @var{x}, and if the result is zero return the result of the
  801. evaluation of @var{y}, return 0 otherwise.
  802. @item ifnot(x, y, z)
  803. Evaluate @var{x}, and if the result is zero return the evaluation
  804. result of @var{y}, otherwise the evaluation result of @var{z}.
  805. @item isinf(x)
  806. Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise.
  807. @item isnan(x)
  808. Return 1.0 if @var{x} is NAN, 0.0 otherwise.
  809. @item ld(idx)
  810. Load the value of the internal variable with index @var{idx}, which was
  811. previously stored with st(@var{idx}, @var{expr}).
  812. The function returns the loaded value.
  813. @item lerp(x, y, z)
  814. Return linear interpolation between @var{x} and @var{y} by amount of @var{z}.
  815. @item log(x)
  816. Compute natural logarithm of @var{x}.
  817. @item lt(x, y)
  818. Return 1 if @var{x} is lesser than @var{y}, 0 otherwise.
  819. @item lte(x, y)
  820. Return 1 if @var{x} is lesser than or equal to @var{y}, 0 otherwise.
  821. @item max(x, y)
  822. Return the maximum between @var{x} and @var{y}.
  823. @item min(x, y)
  824. Return the minimum between @var{x} and @var{y}.
  825. @item mod(x, y)
  826. Compute the remainder of division of @var{x} by @var{y}.
  827. @item not(expr)
  828. Return 1.0 if @var{expr} is zero, 0.0 otherwise.
  829. @item pow(x, y)
  830. Compute the power of @var{x} elevated @var{y}, it is equivalent to
  831. "(@var{x})^(@var{y})".
  832. @item print(t)
  833. @item print(t, l)
  834. Print the value of expression @var{t} with loglevel @var{l}. If @var{l} is not
  835. specified then a default log level is used.
  836. Return the value of the expression printed.
  837. @item random(idx)
  838. Return a pseudo random value between 0.0 and 1.0. @var{idx} is the
  839. index of the internal variable used to save the seed/state, which can be
  840. previously stored with @code{st(idx)}.
  841. To initialize the seed, you need to store the seed value as a 64-bit
  842. unsigned integer in the internal variable with index @var{idx}.
  843. For example, to store the seed with value @code{42} in the internal
  844. variable with index @code{0} and print a few random values:
  845. @example
  846. st(0,42); print(random(0)); print(random(0)); print(random(0))
  847. @end example
  848. @item randomi(idx, min, max)
  849. Return a pseudo random value in the interval between @var{min} and
  850. @var{max}. @var{idx} is the index of the internal variable which will be used to
  851. save the seed/state, which can be previously stored with @code{st(idx)}.
  852. To initialize the seed, you need to store the seed value as a 64-bit
  853. unsigned integer in the internal variable with index @var{idx}.
  854. @item root(expr, max)
  855. Find an input value for which the function represented by @var{expr}
  856. with argument @var{ld(0)} is 0 in the interval 0..@var{max}.
  857. The expression in @var{expr} must denote a continuous function or the
  858. result is undefined.
  859. @var{ld(0)} is used to represent the function input value, which means that the
  860. given expression will be evaluated multiple times with various input values that
  861. the expression can access through @code{ld(0)}. When the expression evaluates to
  862. 0 then the corresponding input value will be returned.
  863. @item round(expr)
  864. Round the value of expression @var{expr} to the nearest integer. For example,
  865. "round(1.5)" is "2.0".
  866. @item sgn(x)
  867. Compute sign of @var{x}.
  868. @item sin(x)
  869. Compute sine of @var{x}.
  870. @item sinh(x)
  871. Compute hyperbolic sine of @var{x}.
  872. @item sqrt(expr)
  873. Compute the square root of @var{expr}. This is equivalent to
  874. "(@var{expr})^.5".
  875. @item squish(x)
  876. Compute expression @code{1/(1 + exp(4*x))}.
  877. @item st(idx, expr)
  878. Store the value of the expression @var{expr} in an internal
  879. variable. @var{idx} specifies the index of the variable where to store
  880. the value, and it is a value ranging from 0 to 9. The function returns
  881. the value stored in the internal variable.
  882. The stored value can be retrieved with @code{ld(var)}.
  883. Note: variables are currently not shared between expressions.
  884. @item tan(x)
  885. Compute tangent of @var{x}.
  886. @item tanh(x)
  887. Compute hyperbolic tangent of @var{x}.
  888. @item taylor(expr, x)
  889. @item taylor(expr, x, idx)
  890. Evaluate a Taylor series at @var{x}, given an expression representing
  891. the @code{ld(idx)}-th derivative of a function at 0.
  892. When the series does not converge the result is undefined.
  893. @var{ld(idx)} is used to represent the derivative order in @var{expr},
  894. which means that the given expression will be evaluated multiple times
  895. with various input values that the expression can access through
  896. @code{ld(idx)}. If @var{idx} is not specified then 0 is assumed.
  897. Note, when you have the derivatives at y instead of 0,
  898. @code{taylor(expr, x-y)} can be used.
  899. @item time(0)
  900. Return the current (wallclock) time in seconds.
  901. @item trunc(expr)
  902. Round the value of expression @var{expr} towards zero to the nearest
  903. integer. For example, "trunc(-1.5)" is "-1.0".
  904. @item while(cond, expr)
  905. Evaluate expression @var{expr} while the expression @var{cond} is
  906. non-zero, and returns the value of the last @var{expr} evaluation, or
  907. NAN if @var{cond} was always false.
  908. @end table
  909. The following constants are available:
  910. @table @option
  911. @item PI
  912. area of the unit disc, approximately 3.14
  913. @item E
  914. exp(1) (Euler's number), approximately 2.718
  915. @item PHI
  916. golden ratio (1+sqrt(5))/2, approximately 1.618
  917. @end table
  918. Assuming that an expression is considered "true" if it has a non-zero
  919. value, note that:
  920. @code{*} works like AND
  921. @code{+} works like OR
  922. For example the construct:
  923. @example
  924. if (A AND B) then C
  925. @end example
  926. is equivalent to:
  927. @example
  928. if(A*B, C)
  929. @end example
  930. In your C code, you can extend the list of unary and binary functions,
  931. and define recognized constants, so that they are available for your
  932. expressions.
  933. The evaluator also recognizes the International System unit prefixes.
  934. If 'i' is appended after the prefix, binary prefixes are used, which
  935. are based on powers of 1024 instead of powers of 1000.
  936. The 'B' postfix multiplies the value by 8, and can be appended after a
  937. unit prefix or used alone. This allows using for example 'KB', 'MiB',
  938. 'G' and 'B' as number postfix.
  939. The list of available International System prefixes follows, with
  940. indication of the corresponding powers of 10 and of 2.
  941. @table @option
  942. @item y
  943. 10^-24 / 2^-80
  944. @item z
  945. 10^-21 / 2^-70
  946. @item a
  947. 10^-18 / 2^-60
  948. @item f
  949. 10^-15 / 2^-50
  950. @item p
  951. 10^-12 / 2^-40
  952. @item n
  953. 10^-9 / 2^-30
  954. @item u
  955. 10^-6 / 2^-20
  956. @item m
  957. 10^-3 / 2^-10
  958. @item c
  959. 10^-2
  960. @item d
  961. 10^-1
  962. @item h
  963. 10^2
  964. @item k
  965. 10^3 / 2^10
  966. @item K
  967. 10^3 / 2^10
  968. @item M
  969. 10^6 / 2^20
  970. @item G
  971. 10^9 / 2^30
  972. @item T
  973. 10^12 / 2^40
  974. @item P
  975. 10^15 / 2^50
  976. @item E
  977. 10^18 / 2^60
  978. @item Z
  979. 10^21 / 2^70
  980. @item Y
  981. 10^24 / 2^80
  982. @end table
  983. @c man end EXPRESSION EVALUATION