Javicle - a JSON Video Composition Language
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # JVC JavaScript Expressions
  2. JavaScript expressions are used in a couple of places in JVC.
  3. * Operation configuration
  4. * Operation validations
  5. ## Operation Configuration
  6. When you're writing the JSON for an operation, many of the operation's
  7. config parameters can be JS expressions that will be evaluated
  8. when the operation is run.
  9. For example, say you wanted to use `trim` to just chop a video in half.
  10. The `start` and `end` parameters of the `trim` operation support JavaScript
  11. expressions, so you could write:
  12. ```js
  13. {
  14. "comment": "cut video at midpoint",
  15. "operation": "trim",
  16. "creates": "chopped"
  17. "source": "some_vid",
  18. "end": "source.duration / 2"
  19. }
  20. ```
  21. or run:
  22. ```shell script
  23. jtrim some_vid.mp4 output_vid.mp4 0 "source.duration / 2"
  24. ```
  25. In the above, `source` is referring to the source asset, `some_vid`.
  26. When JVC loads an asset (like `some_vid`), or an operation creates a new asset,
  27. the asset metadata is read using `mediainfo`. The metadata is stored in an object
  28. that is then put into the JavaScript context using the variable name `source`.
  29. ## Operation Validations
  30. Once an operation completes, the validations run to ensure that the output
  31. assets pass whatever tests you want to run.
  32. Each test is a JavaScript expressions, which is evaluated to a boolean value.
  33. If the expression is true, the test passes. If false, the test fails and the
  34. `comment` associated with the failing test is printed.
  35. ## JavaScript Context
  36. What variables are available in the JS context? And what properties do they have?
  37. ### Assets
  38. Assets can be defined in the JVC's `assets` array, or as the output of an
  39. operation.
  40. Assets are referenced by their asset name. Learn more about
  41. [Asset References](asset_refs.md).
  42. In a JVC JavaScript context, assets are JS objects with some useful properties:
  43. #### `duration`
  44. Duration in seconds of the asset (audio or video).
  45. #### `width`
  46. Resolution width in pixes (video or image).
  47. #### `height`
  48. Resolution height in pixes (video or image).
  49. #### `aspectRatio`
  50. Ratio of width / height (video or image).
  51. #### `samplingRate`
  52. Sampling rate in Hz (audio).
  53. #### `tracks`
  54. An array of the A/V tracks in a video. Only includes audio and video tracks.
  55. #### `allTracks`
  56. An array of **all** the tracks in a video. Includes subtitles/data/other tracks.
  57. #### `audioTracks`
  58. An array of the audio tracks in a video.
  59. #### `videoTracks`
  60. An array of the video tracks in a video.
  61. #### `hasAudio`
  62. A boolean, true if the asset has any audio tracks, false otherwise
  63. #### `hasVideo`
  64. A boolean, true if the asset has any video tracks, false otherwise
  65. #### `assets`
  66. If an asset is a list asset, this is an array of the sub-assets. Each sub-asset
  67. has the same properties described above.
  68. #### more properties
  69. The list of asset properties supported today is fairly limited.
  70. More properties will be exposed in the future.
  71. ### JS Functions
  72. The JavaScript environment that JVC sets up includes some useful built-in
  73. functions.
  74. #### `is_within`
  75. Check if a variable is "close" to another value by comparing against a delta.
  76. ```js
  77. x = 10.2
  78. is_within(x, 10, 1); // true
  79. is_within(x, 9.5, 0.5); // false
  80. is_within(x, 10.3, 0.1); // true
  81. ```
  82. #### `is_within_pct`
  83. Check if a variable is "close" to another value by percentage. The percentage
  84. argument is an integer where 1 == 1% and 100 == 100%
  85. ```js
  86. x = 10.2
  87. is_within_pct(x, 10, 2); // true
  88. is_within_pct(x, 9, 10); // false (9 + (10% of 9) only gets you to 9.9, x is 10.2)
  89. is_within_pct(x, 10.3, 10); // true
  90. ```