Scripting Basics

A simple script walk-through.

The code below is a simple script that contains:

  1. Two clips using camera footage as the source, with the second playing at 2x speed

  2. A still image (bumper/end card) at the end

  3. A music track

  4. A light leak overlay with a screen blend mode

//
// HypnoScript-Stdlib-Demo.js
// HypnoScript-Stdlib-Demo
//

import { Asset, Time, TimeRange, Clip, Vector } from 'hypno'
import { Image, Filter, Kernel } from 'hypno/coreimage'

import * as hypno from './stl.js'

//create tracks 
const mainTrack = composition.track("main")
const screenTrack = composition.track("screen")

hypno.buildTimeline({
    fps: 30,
    resolution: new Vector(960, 1280),
    audio: new Asset("./music.mp3"),
    clips: [
        {
            track: mainTrack,
            start: 0,
            duration: 60, //duration in number of frames
            transform: hypno.transform.fill //scales image to fill entire resolution
        },
        {
            track: mainTrack,
            start: 50,
            duration: 60,
            transform: hypno.transform.fill,
            speed: 2.0
        },
        {
            track: mainTrack,
            start: 0,
            duration: 60,
            asset: new Image("endCard.png")
        },
        {
            track: screenTrack,
            start: 0,
            duration: 180,
            asset: new Asset("screen.mp4"),
            blend: hypno.blend.screen
        }
    ]
})

Here's what this script looks like in NYX:

1. Importing Standard Library

Before your start creating your timeline, first copy and paste the import statements above. Make sure you have the correct file path to the standard library javascript file "./stl.js". We recommend importing the javascript file to your nyx project along with the rest of your media, so you have everything in one place when you upload for testing.

2. Tracks

You can create a track using:

const <trackName> = composition.track("<trackName>")

Tracks in Hypno script can contain media from a variety of inputs, both video and image, which you will fill in when you add clips in hypno.buildTimeline. Note that the order in which you instantiate a track determines the order of the tracks on the timeline.

3. Configuring your script with buildTimeline

hypno.buildTimeline is the function you will use to assemble your sequence, configure your timeline, and much more.

In the example above, we first set the frame rate to 30 fps, the resolution to 960 x 1280 pixels, and set the audio Asset. Setting the audio parameter creates an audio track and audio clip that automatically snaps to the length of your script.

4. Adding Clips & Sequencing

clips[] is an array of objects passed to buildTimeline, each containing keys that determine clip parameters. In this example, the first two clips use the camera asset as the source, which is the default setting unless specified otherwise. Every clip must contain a start and duration. You will notice that all of the time parameters are given in integers, and that's because Hypno script uses frame time. So, duration: 60 means that the clip will be 60 frames long, which, in 30 frames per second (fps), is equivalent to 2 seconds.

There are a variety of other keys you can use to add effects, blend modes, rotations, and more. Click here for the full list of available parameters.

Below is a zip file containing the Nyx project folder for this script. Check it out to experiment with the parameters, and play it back in real-time!

HYPNO Script STL (Standard Timeline Library) Project

Last updated

Was this helpful?