utils.texi 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. @code{'} and @code{\} 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 '\'.
  17. @item
  18. All characters enclosed between '' are included literally in the
  19. parsed string. The quote character @code{'} 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 @code{\} 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. The accepted syntax is:
  78. @example
  79. [-][HH:]MM:SS[.m...]
  80. [-]S+[.m...]
  81. @end example
  82. @var{HH} expresses the number of hours, @var{MM} the number a of minutes
  83. and @var{SS} the number of seconds.
  84. @anchor{video size syntax}
  85. @section Video size
  86. Specify the size of the sourced video, it may be a string of the form
  87. @var{width}x@var{height}, or the name of a size abbreviation.
  88. The following abbreviations are recognized:
  89. @table @samp
  90. @item ntsc
  91. 720x480
  92. @item pal
  93. 720x576
  94. @item qntsc
  95. 352x240
  96. @item qpal
  97. 352x288
  98. @item sntsc
  99. 640x480
  100. @item spal
  101. 768x576
  102. @item film
  103. 352x240
  104. @item ntsc-film
  105. 352x240
  106. @item sqcif
  107. 128x96
  108. @item qcif
  109. 176x144
  110. @item cif
  111. 352x288
  112. @item 4cif
  113. 704x576
  114. @item 16cif
  115. 1408x1152
  116. @item qqvga
  117. 160x120
  118. @item qvga
  119. 320x240
  120. @item vga
  121. 640x480
  122. @item svga
  123. 800x600
  124. @item xga
  125. 1024x768
  126. @item uxga
  127. 1600x1200
  128. @item qxga
  129. 2048x1536
  130. @item sxga
  131. 1280x1024
  132. @item qsxga
  133. 2560x2048
  134. @item hsxga
  135. 5120x4096
  136. @item wvga
  137. 852x480
  138. @item wxga
  139. 1366x768
  140. @item wsxga
  141. 1600x1024
  142. @item wuxga
  143. 1920x1200
  144. @item woxga
  145. 2560x1600
  146. @item wqsxga
  147. 3200x2048
  148. @item wquxga
  149. 3840x2400
  150. @item whsxga
  151. 6400x4096
  152. @item whuxga
  153. 7680x4800
  154. @item cga
  155. 320x200
  156. @item ega
  157. 640x350
  158. @item hd480
  159. 852x480
  160. @item hd720
  161. 1280x720
  162. @item hd1080
  163. 1920x1080
  164. @item 2k
  165. 2048x1080
  166. @item 2kflat
  167. 1998x1080
  168. @item 2kscope
  169. 2048x858
  170. @item 4k
  171. 4096x2160
  172. @item 4kflat
  173. 3996x2160
  174. @item 4kscope
  175. 4096x1716
  176. @end table
  177. @anchor{video rate syntax}
  178. @section Video rate
  179. Specify the frame rate of a video, expressed as the number of frames
  180. generated per second. It has to be a string in the format
  181. @var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float
  182. number or a valid video frame rate abbreviation.
  183. The following abbreviations are recognized:
  184. @table @samp
  185. @item ntsc
  186. 30000/1001
  187. @item pal
  188. 25/1
  189. @item qntsc
  190. 30000/1001
  191. @item qpal
  192. 25/1
  193. @item sntsc
  194. 30000/1001
  195. @item spal
  196. 25/1
  197. @item film
  198. 24/1
  199. @item ntsc-film
  200. 24000/1001
  201. @end table
  202. @anchor{ratio syntax}
  203. @section Ratio
  204. A ratio can be expressed as an expression, or in the form
  205. @var{numerator}:@var{denominator}.
  206. Note that a ratio with infinite (1/0) or negative value is
  207. considered valid, so you should check on the returned value if you
  208. want to exclude those values.
  209. The undefined value can be expressed using the "0:0" string.
  210. @anchor{color syntax}
  211. @section Color
  212. It can be the name of a color (case insensitive match) or a
  213. [0x|#]RRGGBB[AA] sequence, possibly followed by "@@" and a string
  214. representing the alpha component.
  215. The alpha component may be a string composed by "0x" followed by an
  216. hexadecimal number or a decimal number between 0.0 and 1.0, which
  217. represents the opacity value (0x00/0.0 means completely transparent,
  218. 0xff/1.0 completely opaque).
  219. If the alpha component is not specified then 0xff is assumed.
  220. The string "random" will result in a random color.
  221. @c man end SYNTAX
  222. @chapter Expression Evaluation
  223. @c man begin EXPRESSION EVALUATION
  224. When evaluating an arithmetic expression, FFmpeg uses an internal
  225. formula evaluator, implemented through the @file{libavutil/eval.h}
  226. interface.
  227. An expression may contain unary, binary operators, constants, and
  228. functions.
  229. Two expressions @var{expr1} and @var{expr2} can be combined to form
  230. another expression "@var{expr1};@var{expr2}".
  231. @var{expr1} and @var{expr2} are evaluated in turn, and the new
  232. expression evaluates to the value of @var{expr2}.
  233. The following binary operators are available: @code{+}, @code{-},
  234. @code{*}, @code{/}, @code{^}.
  235. The following unary operators are available: @code{+}, @code{-}.
  236. The following functions are available:
  237. @table @option
  238. @item abs(x)
  239. Compute absolute value of @var{x}.
  240. @item acos(x)
  241. Compute arccosine of @var{x}.
  242. @item asin(x)
  243. Compute arcsine of @var{x}.
  244. @item atan(x)
  245. Compute arctangent of @var{x}.
  246. @item between(x, min, max)
  247. Return 1 if @var{x} is greater than or equal to @var{min} and lesser than or
  248. equal to @var{max}, 0 otherwise.
  249. @item bitand(x, y)
  250. @item bitor(x, y)
  251. Compute bitwise and/or operation on @var{x} and @var{y}.
  252. The results of the evaluation of @var{x} and @var{y} are converted to
  253. integers before executing the bitwise operation.
  254. Note that both the conversion to integer and the conversion back to
  255. floating point can lose precision. Beware of unexpected results for
  256. large numbers (usually 2^53 and larger).
  257. @item ceil(expr)
  258. Round the value of expression @var{expr} upwards to the nearest
  259. integer. For example, "ceil(1.5)" is "2.0".
  260. @item cos(x)
  261. Compute cosine of @var{x}.
  262. @item cosh(x)
  263. Compute hyperbolic cosine of @var{x}.
  264. @item eq(x, y)
  265. Return 1 if @var{x} and @var{y} are equivalent, 0 otherwise.
  266. @item exp(x)
  267. Compute exponential of @var{x} (with base @code{e}, the Euler's number).
  268. @item floor(expr)
  269. Round the value of expression @var{expr} downwards to the nearest
  270. integer. For example, "floor(-1.5)" is "-2.0".
  271. @item gauss(x)
  272. Compute Gauss function of @var{x}, corresponding to
  273. @code{exp(-x*x/2) / sqrt(2*PI)}.
  274. @item gcd(x, y)
  275. Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and
  276. @var{y} are 0 or either or both are less than zero then behavior is undefined.
  277. @item gt(x, y)
  278. Return 1 if @var{x} is greater than @var{y}, 0 otherwise.
  279. @item gte(x, y)
  280. Return 1 if @var{x} is greater than or equal to @var{y}, 0 otherwise.
  281. @item hypot(x, y)
  282. This function is similar to the C function with the same name; it returns
  283. "sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a
  284. right triangle with sides of length @var{x} and @var{y}, or the distance of the
  285. point (@var{x}, @var{y}) from the origin.
  286. @item if(x, y)
  287. Evaluate @var{x}, and if the result is non-zero return the result of
  288. the evaluation of @var{y}, return 0 otherwise.
  289. @item if(x, y, z)
  290. Evaluate @var{x}, and if the result is non-zero return the evaluation
  291. result of @var{y}, otherwise the evaluation result of @var{z}.
  292. @item ifnot(x, y)
  293. Evaluate @var{x}, and if the result is zero return the result of the
  294. evaluation of @var{y}, return 0 otherwise.
  295. @item ifnot(x, y, z)
  296. Evaluate @var{x}, and if the result is zero return the evaluation
  297. result of @var{y}, otherwise the evaluation result of @var{z}.
  298. @item isinf(x)
  299. Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise.
  300. @item isnan(x)
  301. Return 1.0 if @var{x} is NAN, 0.0 otherwise.
  302. @item ld(var)
  303. Allow to load the value of the internal variable with number
  304. @var{var}, which was previously stored with st(@var{var}, @var{expr}).
  305. The function returns the loaded value.
  306. @item log(x)
  307. Compute natural logarithm of @var{x}.
  308. @item lt(x, y)
  309. Return 1 if @var{x} is lesser than @var{y}, 0 otherwise.
  310. @item lte(x, y)
  311. Return 1 if @var{x} is lesser than or equal to @var{y}, 0 otherwise.
  312. @item max(x, y)
  313. Return the maximum between @var{x} and @var{y}.
  314. @item min(x, y)
  315. Return the minimum between @var{x} and @var{y}.
  316. @item mod(x, y)
  317. Compute the remainder of division of @var{x} by @var{y}.
  318. @item not(expr)
  319. Return 1.0 if @var{expr} is zero, 0.0 otherwise.
  320. @item pow(x, y)
  321. Compute the power of @var{x} elevated @var{y}, it is equivalent to
  322. "(@var{x})^(@var{y})".
  323. @item print(t)
  324. @item print(t, l)
  325. Print the value of expression @var{t} with loglevel @var{l}. If
  326. @var{l} is not specified then a default log level is used.
  327. Returns the value of the expression printed.
  328. Prints t with loglevel l
  329. @item random(x)
  330. Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the
  331. internal variable which will be used to save the seed/state.
  332. @item root(expr, max)
  333. Find an input value for which the function represented by @var{expr}
  334. with argument @var{ld(0)} is 0 in the interval 0..@var{max}.
  335. The expression in @var{expr} must denote a continuous function or the
  336. result is undefined.
  337. @var{ld(0)} is used to represent the function input value, which means
  338. that the given expression will be evaluated multiple times with
  339. various input values that the expression can access through
  340. @code{ld(0)}. When the expression evaluates to 0 then the
  341. corresponding input value will be returned.
  342. @item sin(x)
  343. Compute sine of @var{x}.
  344. @item sinh(x)
  345. Compute hyperbolic sine of @var{x}.
  346. @item sqrt(expr)
  347. Compute the square root of @var{expr}. This is equivalent to
  348. "(@var{expr})^.5".
  349. @item squish(x)
  350. Compute expression @code{1/(1 + exp(4*x))}.
  351. @item st(var, expr)
  352. Allow to store the value of the expression @var{expr} in an internal
  353. variable. @var{var} specifies the number of the variable where to
  354. store the value, and it is a value ranging from 0 to 9. The function
  355. returns the value stored in the internal variable.
  356. Note, Variables are currently not shared between expressions.
  357. @item tan(x)
  358. Compute tangent of @var{x}.
  359. @item tanh(x)
  360. Compute hyperbolic tangent of @var{x}.
  361. @item taylor(expr, x)
  362. @item taylor(expr, x, id)
  363. Evaluate a Taylor series at @var{x}, given an expression representing
  364. the @code{ld(id)}-th derivative of a function at 0.
  365. When the series does not converge the result is undefined.
  366. @var{ld(id)} is used to represent the derivative order in @var{expr},
  367. which means that the given expression will be evaluated multiple times
  368. with various input values that the expression can access through
  369. @code{ld(id)}. If @var{id} is not specified then 0 is assumed.
  370. Note, when you have the derivatives at y instead of 0,
  371. @code{taylor(expr, x-y)} can be used.
  372. @item time(0)
  373. Return the current (wallclock) time in seconds.
  374. @item trunc(expr)
  375. Round the value of expression @var{expr} towards zero to the nearest
  376. integer. For example, "trunc(-1.5)" is "-1.0".
  377. @item while(cond, expr)
  378. Evaluate expression @var{expr} while the expression @var{cond} is
  379. non-zero, and returns the value of the last @var{expr} evaluation, or
  380. NAN if @var{cond} was always false.
  381. @end table
  382. The following constants are available:
  383. @table @option
  384. @item PI
  385. area of the unit disc, approximately 3.14
  386. @item E
  387. exp(1) (Euler's number), approximately 2.718
  388. @item PHI
  389. golden ratio (1+sqrt(5))/2, approximately 1.618
  390. @end table
  391. Assuming that an expression is considered "true" if it has a non-zero
  392. value, note that:
  393. @code{*} works like AND
  394. @code{+} works like OR
  395. For example the construct:
  396. @example
  397. if (A AND B) then C
  398. @end example
  399. is equivalent to:
  400. @example
  401. if(A*B, C)
  402. @end example
  403. In your C code, you can extend the list of unary and binary functions,
  404. and define recognized constants, so that they are available for your
  405. expressions.
  406. The evaluator also recognizes the International System unit prefixes.
  407. If 'i' is appended after the prefix, binary prefixes are used, which
  408. are based on powers of 1024 instead of powers of 1000.
  409. The 'B' postfix multiplies the value by 8, and can be appended after a
  410. unit prefix or used alone. This allows using for example 'KB', 'MiB',
  411. 'G' and 'B' as number postfix.
  412. The list of available International System prefixes follows, with
  413. indication of the corresponding powers of 10 and of 2.
  414. @table @option
  415. @item y
  416. 10^-24 / 2^-80
  417. @item z
  418. 10^-21 / 2^-70
  419. @item a
  420. 10^-18 / 2^-60
  421. @item f
  422. 10^-15 / 2^-50
  423. @item p
  424. 10^-12 / 2^-40
  425. @item n
  426. 10^-9 / 2^-30
  427. @item u
  428. 10^-6 / 2^-20
  429. @item m
  430. 10^-3 / 2^-10
  431. @item c
  432. 10^-2
  433. @item d
  434. 10^-1
  435. @item h
  436. 10^2
  437. @item k
  438. 10^3 / 2^10
  439. @item K
  440. 10^3 / 2^10
  441. @item M
  442. 10^6 / 2^20
  443. @item G
  444. 10^9 / 2^30
  445. @item T
  446. 10^12 / 2^40
  447. @item P
  448. 10^15 / 2^40
  449. @item E
  450. 10^18 / 2^50
  451. @item Z
  452. 10^21 / 2^60
  453. @item Y
  454. 10^24 / 2^70
  455. @end table
  456. @c man end
  457. @chapter OpenCL Options
  458. @c man begin OPENCL OPTIONS
  459. When FFmpeg is configured with @code{--enable-opencl}, it is possible
  460. to set the options for the global OpenCL context.
  461. The list of supported options follows:
  462. @table @option
  463. @item build_options
  464. Set build options used to compile the registered kernels.
  465. See reference "OpenCL Specification Version: 1.2 chapter 5.6.4".
  466. @item platform_idx
  467. Select the index of the platform to run OpenCL code.
  468. The specified index must be one of the indexes in the device list
  469. which can be obtained with @code{av_opencl_get_device_list()}.
  470. @item device_idx
  471. Select the index of the device used to run OpenCL code.
  472. The specifed index must be one of the indexes in the device list which
  473. can be obtained with @code{av_opencl_get_device_list()}.
  474. @end table
  475. @c man end OPENCL OPTIONS