Javicle - a JSON Video Composition Language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. # Javicle - a JSON Video Composition Language
  2. JVCL (pronounced "Javicle") is a JSON DSL for audio/video transformations.
  3. Under the hood, it's all shell commands: `ffmpeg`, `mediainfo` and so on.
  4. JVCL provides higher-level semantics for working with these lower level tools.
  5. # A Quick Example
  6. Say you want to split a portion of a video into ten-second chunks. With ffmpeg
  7. and bash, you might do something like this:
  8. ```shell script
  9. INCR=10
  10. for ((i=10;i<130;i=(i+INCR))); do
  11. ffmpeg -i /tmp/my/source.mp4 -ss ${i} -t $((i+INCR)) /tmp/my/slice_${i}_$((i+INCR)).mp4
  12. done
  13. ```
  14. With JVCL, you'd write this spec file and save it to a file (for example `my-spec.jvcl`):
  15. ```json
  16. {
  17. "assets": [ {"name": "src", "path": "/tmp/my/source.mp4"} ],
  18. "operations": [{
  19. "operation": "split",
  20. "creates": "src_split_files",
  21. "source": "src",
  22. "interval": "10s",
  23. "start": "10s",
  24. "end": "130s"
  25. }]
  26. }
  27. ```
  28. and then run it like this:
  29. ```shell script
  30. jvcl my-spec.jvcl
  31. ```
  32. Yes, the JVCL is longer, but I think many would agree it is easier to read and maintain.
  33. **As the number of media assets and operations grows, hand-crafted shell scripts with magical
  34. ffmpeg incantations become ever more inscrutable.**
  35. JVCL is designed for readability and maintainability. JVCL will continue to evolve towards greater
  36. coverage of the full capabilities of ffmpeg.
  37. # Who is JVCL not for?
  38. If you like GUIs, JVCL is probably not for you.
  39. JVCL is not a replacement for Final Cut Pro or even iMovie.
  40. # Who is JVCL for?
  41. JVCL is for people who like CLIs and automation.
  42. JVCL is for people with relatively simple video composition needs (for now),
  43. since the range of operations supported is limited.
  44. # Concepts
  45. In JVCL there are a few main concepts: spec files, assets and operations.
  46. ## JVCL Spec Files
  47. A JVCL spec file is just a regular JSON file that happens to contain a single JSON object,
  48. whose properties are `assets` and `operations`.
  49. When you run `jvcl` on a spec file, it will load the `assets`, then perform the `operations` in order.
  50. Unlike most JSON, comments *are* allowed in JVCL spec files:
  51. * A line comment starts with `//` and continue to the end of the line
  52. * A multi-line block syntax starts with `/*` and ends with `*/`
  53. ### Executing a JVCL Spec
  54. To execute a spec stored in the file `my-spec.json`, you would run:
  55. ```shell script
  56. jvcl my-spec.jvcl
  57. ```
  58. or you use stdin:
  59. ```shell script
  60. cat my-spec.jvcl | jvcl
  61. ```
  62. #### Scratch Directory
  63. Output assets will be placed in the scratch directory, unless otherwise specified
  64. in the spec file. By default, JVCL will create a new temporary directory to use as the scratch
  65. directory. You can set the scratch directory explicitly using the `-t` or `--temp-dir` option:
  66. ```shell script
  67. jvcl -t /some/tempdir my-spec.json
  68. ```
  69. #### Command Help
  70. To view a list of all `jvcl` command-line options, run `jvcl -h` or `jvcl --help`
  71. ## Assets
  72. Assets are your media files: generally image, audio and video files.
  73. All assets have a name and a path.
  74. Input assets are defined using the `assets` array of a JVCL spec.
  75. For input assets, the path can be a file or a URL. URL-based assets will be downloaded
  76. to the scratch directory. This can be overridden using the `dest` property on the asset.
  77. Operations produce one or more output assets, as specified in the `creates` property of
  78. an operation JSON object.
  79. For output assets, the path will be within the scratch directory.
  80. You can override this using the `dest` property on the `creates` object associated with the operation.
  81. ### Asset Properties
  82. Assets expose properties that can be referenced in operations. The properties currently exposed are:
  83. * `duration`: duration of the audio/video in seconds (audio and video assets only)
  84. * `width`: width of the video in pixels (video and image assets only)
  85. * `height`: width of the video in pixels (video and image assets only)
  86. ## Operations
  87. Operations are transformations to perform on the inputs.
  88. An operation can produce one or more new assets, which can then be referenced in
  89. later operations.
  90. Most of the operation settings can be JavaScript expressions, for example:
  91. "start": "someAsset.duration - 10"
  92. The above would set the `start` value to ten seconds before the end of `someAsset`.
  93. ### Supported Operations
  94. Today, JVCL supports several basic operations.
  95. For each operation listed below, the header links to an example from the JVCL test suite.
  96. ### [scale](src/test/resources/tests/test_scale.jvcl)
  97. Scale a video asset from one size to another. Scaling can be proportional or anamorphic.
  98. ### [split](src/test/resources/tests/test_split.jvcl)
  99. Split an audio/video asset into multiple assets of equal time lengths.
  100. ### [concat](src/test/resources/tests/test_concat.jvcl)
  101. Concatenate audio/video assets together into one asset.
  102. ### [trim](src/test/resources/tests/test_trim.jvcl)
  103. Trim audio/video; crop a section of an asset, becomes a new asset.
  104. ### [overlay](src/test/resources/tests/test_overlay.jvcl)
  105. Overlay one asset onto another.
  106. ### [ken-burns](src/test/resources/tests/test_ken_burns.jvcl)
  107. For transforming still images into video via a fade-pan (aka Ken Burns) effect.
  108. ### [letterbox](src/test/resources/tests/test_letterbox.jvcl)
  109. Transform a video in one size to another size using black letterboxes on the sides or top/bottom.
  110. Handy for embedding mobile videos into other screen formats.
  111. ### [remove-track](src/test/resources/tests/test_remove_track.jvcl)
  112. Remove a track from a video asset.
  113. # Complex Example
  114. Here is a complex example using multiple assets and operations.
  115. Note that comments, which are not usually legal in JSON, are allowed in JVCL files.
  116. If you have other JSON-aware tools that need to read JVLC files, you may not want to
  117. use this comment syntax. The `asset` and `operation` JSON objects also support a `comment`
  118. field, which can be used as well.
  119. ```js
  120. {
  121. "assets": [
  122. // file -- will be referenced directory
  123. {
  124. "comment": "first video, already local",
  125. "name": "vid1",
  126. "path": "/tmp/path/to/video1.mp4"
  127. },
  128. // URL -- will be downloaded to scratch directory and referenced from there
  129. {
  130. "comment": "second video, will be downloaded",
  131. "name": "vid2",
  132. "path": "https://archive.org/download/gov.archives.arc.1257628/gov.archives.arc.1257628_512kb.mp4"
  133. },
  134. // URL -- will be downloaded to `dest` directory and referenced from there
  135. {
  136. "comment": "third video, will be downloaded",
  137. "name": "vid3",
  138. "path": "https://archive.org/download/gov.archives.arc.49442/gov.archives.arc.49442_512kb.mp4",
  139. "dest": "src/test/resources/sources/"
  140. },
  141. // Image URL
  142. {
  143. "comment": "JPEG image, will be downloaded",
  144. "name": "img1",
  145. "path": "https://live.staticflickr.com/65535/48159911972_01efa0e5ea_b.jpg",
  146. "dest": "src/test/resources/sources/"
  147. }
  148. ],
  149. "operations": [
  150. // scale examples
  151. {
  152. "comment": "scale using explicity height x width",
  153. "operation": "scale", // name of the operation
  154. "creates": "vid2_scaled", // asset it creates
  155. "source": "vid2", // source asset
  156. "width": "1024", // width of scaled asset. if omitted and height is present, width will be proportional
  157. "height": "768" // height of scaled asset. if omitted and width is present, height will be proportional
  158. },
  159. {
  160. "comment": "scale proportionally by a scale factor",
  161. "operation": "scale", // name of the operation
  162. "creates": "vid2_big", // asset it creates
  163. "source": "vid2", // source asset
  164. "factor": "2.2" // scale factor. if factor is set, width and height are ignored.
  165. },
  166. // split example
  167. {
  168. "comment": "split one asset into many",
  169. "operation": "split", // name of the operation
  170. "creates": "vid1_split_%", // assets it creates, the '%' will be replaced with a counter
  171. "source": "vid1", // split this source asset
  172. "interval": "10" // split every ten seconds
  173. },
  174. // concat examples
  175. {
  176. "comment": "re-combine previously split assets back together",
  177. "operation": "concat", // name of the operation
  178. "creates": "recombined_vid1", // assets it creates, the '%' will be replaced with a counter
  179. "source": ["vid1_split"] // recombine all split assets
  180. },
  181. {
  182. "comment": "append vid2 to the end of vid1 and create a new asset",
  183. "operation": "concat", // name of the operation
  184. "creates": "combined_vid2", // asset it creates, can be referenced later
  185. "source": ["vid1", "vid2"] // operation-specific: this says, concatenate these named assets
  186. },
  187. {
  188. "comment": "re-combine only some of the previously split assets",
  189. "operation": "concat", // name of the operation
  190. "sources": ["vid1_splits[1..2]"],// concatentate these sources -- the 2nd and 3rd files only
  191. "creates": "combined_vid3" // name of the output asset, will be written to scratch directory
  192. },
  193. // trim example
  194. {
  195. "comment": "trim all of the assets that were split above",
  196. "operation": "trim", // name of the operation
  197. "creates": { // create multiple files, will be prefixed with `name`, store them in `dest`
  198. "name": "vid1_trims",
  199. "dest": "src/test/resources/outputs/trims/"
  200. },
  201. "source": "vid1_split", // trim these source assets
  202. "start": "1", // cropped region starts here, default is zero
  203. "end": "6" // cropped region ends here, default is end of video
  204. },
  205. // overlay example
  206. {
  207. "comment": "overlay one video onto another",
  208. "operation": "overlay", // name of the operation
  209. "creates": "overlay1", // asset it creates
  210. "source": "combined_vid1", // main video asset
  211. "start": "30", // when (on the main video timeline) to begin showing the overlay. default is 0 (beginning)
  212. "end": "60", // when (on the main video timeline) to stop showing the overlay. default is to play the entire overlay
  213. "overlay": {
  214. "source": "vid2", // overlay this video on the main video
  215. "start": "0", // when (on the overlay video timeline) to begin playback on the overlay. default is 0 (beginning)
  216. "end": "overlay.duration", // when (on the overlay video timeline) to end playback on the overlay. default is to play the entire overlay
  217. "width": "overlay.width / 2", // how wide the overlay will be, in pixels. default is the full overlay width, or maintain aspect ratio if height was set
  218. "height": "source.height", // how tall the overlay will be, in pixels. default is the full overlay height, or maintain aspect ratio if width was set
  219. "x": "source.width / 2", // horizontal overlay position on main video. default is 0
  220. "y": "source.height / 2" // vertical overlay position on main video. default is 0
  221. }
  222. },
  223. // ken-burns example
  224. {
  225. "comment": "apply zoom-pan effect to image, creates video",
  226. "operation": "ken-burns", // name of the operation
  227. "creates": "ken1", // asset it creates
  228. "source": "img1", // source image
  229. "zoom": "1.3", // zoom level, from 1 to 10
  230. "duration": "5", // how long the resulting video will be
  231. "start": "0", // when to start zooming, default is 0
  232. "end": "duration", // when to end zooming, default is duration
  233. "x": "source.width * 0.6", // pan to this x-position
  234. "y": "source.height * 0.4", // pan to this y-position
  235. "upscale": "8", // upscale factor. upscaling the image results in a smoother pan, but a longer encode, default is 8
  236. "width": "1024", // width of output video
  237. "height": "768" // height of output video
  238. },
  239. // letterbox example
  240. {
  241. "comment": "increase video size without scaling, add letterboxes as needed",
  242. "operation": "letterbox", // name of the operation
  243. "creates": "boxed1", // asset it creates
  244. "source": "ken1", // source asset
  245. "width": "source.width * 1.5", // make it wider
  246. "height": "source.height * 0.9", // and shorter
  247. "color": "AliceBlue" // default is black. can be a hex value (0xff0000 for red) or a color name from here: https://ffmpeg.org/ffmpeg-utils.html#color-syntax
  248. },
  249. // remove-track examples
  250. {
  251. "comment": "remove all audio tracks",
  252. "operation": "remove-track", // name of the operation
  253. "creates": "vid2_video_only", // name of the output asset
  254. "source": "vid2", // main video asset
  255. "track": "audio" // remove all audio tracks
  256. },
  257. {
  258. "comment": "remove all video tracks",
  259. "operation": "remove-track", // name of the operation
  260. "creates": "vid2_audio_only", // name of the output asset
  261. "source": "vid2", // main video asset
  262. "track": "video" // remove all video tracks
  263. },
  264. {
  265. "comment": "remove a specific audio track",
  266. "operation": "remove-track", // name of the operation
  267. "creates": "vid2_video_only2", // name of the output asset
  268. "source": "vid2", // main video asset
  269. "track": {
  270. // only remove the first audio track
  271. "type": "audio", // track type to remove
  272. "number": "0" // track number to remove
  273. }
  274. }
  275. ]
  276. }
  277. ```
  278. ## What's up with the name?
  279. I dunno, a cross between a javelin and an icicle? does that have any positive connotations? ok then...