Skip to content

Commit

Permalink
Add trim example
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffski committed Sep 15, 2021
1 parent 557d172 commit cef4148
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
- **titles.js** -
Create a video to demo titles using the available preset font styles, a soundtrack, zoom in motion effect and
wipe right transition.


- **trim.js** -
Trim the start and end of a video clip to output a shortened video.

- **filters.js** -
Applies filters to a video clip, including a title with the name of the filter and a soundtrack.

Expand Down
59 changes: 59 additions & 0 deletions examples/trim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const Shotstack = require('shotstack-sdk');

const defaultClient = Shotstack.ApiClient.instance;
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
const api = new Shotstack.EditApi();

let apiUrl = 'https://api.shotstack.io/stage';

if (!process.env.SHOTSTACK_KEY) {
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
process.exit(1);
}

if (process.env.SHOTSTACK_HOST) {
apiUrl = process.env.SHOTSTACK_HOST;
}

defaultClient.basePath = apiUrl;
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;

let videoAsset = new Shotstack.VideoAsset;
videoAsset
.setSrc('https://s3-ap-southeast-2.amazonaws.com/shotstack-assets/footage/skater.hd.mp4')
.setTrim(3)

let videoClip = new Shotstack.Clip;
videoClip
.setAsset(videoAsset)
.setStart(0)
.setLength(8);

let track = new Shotstack.Track;
track.setClips([videoClip]);

let timeline = new Shotstack.Timeline;
timeline.setTracks([track]);

let output = new Shotstack.Output;
output
.setFormat('mp4')
.setResolution('sd');

let edit = new Shotstack.Edit;
edit
.setTimeline(timeline)
.setOutput(output);

api.postRender(edit).then((data) => {
let message = data.response.message;
let id = data.response.id

console.log(message + '\n');
console.log('>> Now check the progress of your render by running:');
console.log('>> node examples/status.js ' + id);

}, (error) => {
console.error('Request failed: ', error);
process.exit(1);
});

0 comments on commit cef4148

Please sign in to comment.