Skip to content

Commit dc99454

Browse files
author
Jeff Shillitto
committed
Add create template and render template examples
1 parent 0f6b236 commit dc99454

File tree

1 file changed

+108
-1
lines changed

1 file changed

+108
-1
lines changed

README.md

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ For examples of how to use the SDK to create videos using code checkout the Node
1616
- [Video Editing](#video-editing)
1717
- [Video Editing Example](#video-editing-example)
1818
- [Status Check Example](#status-check-example)
19+
- [Save a Template Example](#save-a-template-example)
20+
- [Render a Template Example](#render-a-template-example)
1921
- [Video Editing Schemas](#video-editing-schemas)
2022
- [Edit](#edit)
2123
- [Timeline](#timeline)
@@ -163,6 +165,111 @@ api.getRender(id, { data: false, merged: true }).then((data) => {
163165
});
164166
```
165167

168+
### Save a Template Example
169+
170+
The example below uses the Edit we create in the [Video Editing Example](#video-editing-example) and saves it as a
171+
template. The template can be rendered at a later date and can include placeholders. Placeholders can be replaced
172+
when rendered using [merge fields](#mergefield).
173+
174+
This example uses a placeholder for the video src (URL), trim (TRIM), and length (LENGTH) to allow you to trim any video
175+
using a template.
176+
177+
```javascript
178+
const Shotstack = require('shotstack-sdk');
179+
180+
const defaultClient = Shotstack.ApiClient.instance;
181+
defaultClient.basePath = 'https://api.shotstack.io/stage';
182+
183+
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
184+
DeveloperKey.apiKey = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'; // use the correct API key
185+
186+
const api = new Shotstack.EditApi();
187+
188+
let videoAsset = new Shotstack.VideoAsset;
189+
videoAsset
190+
.setSrc('{{ URL }}')
191+
.setTrim('{{ TRIM }}');
192+
193+
let videoClip = new Shotstack.Clip;
194+
videoClip
195+
.setAsset(videoAsset)
196+
.setStart(0)
197+
.setLength('{{ LENGTH }}');
198+
199+
let track = new Shotstack.Track;
200+
track.setClips([videoClip]);
201+
202+
let timeline = new Shotstack.Timeline;
203+
timeline.setTracks([track]);
204+
205+
let output = new Shotstack.Output;
206+
output
207+
.setFormat('mp4')
208+
.setResolution('sd');
209+
210+
let edit = new Shotstack.Edit;
211+
edit
212+
.setTimeline(timeline)
213+
.setOutput(output);
214+
215+
const template = new Shotstack.Template;
216+
template
217+
.setName('Trim Template')
218+
.setTemplate(edit);
219+
220+
api.postTemplate(template).then((data) => {
221+
console.log(data.response.id);
222+
});
223+
```
224+
225+
### Render a Template Example
226+
227+
The example below renders the template we created in the previous example and includes merge fields that will replace
228+
the placeholders. Once submitted use the returned render ID and call the [Status Check Example](#status-check-example)
229+
to get the render progress.
230+
231+
```javascript
232+
const Shotstack = require('shotstack-sdk');
233+
234+
const defaultClient = Shotstack.ApiClient.instance;
235+
defaultClient.basePath = 'https://api.shotstack.io/stage';
236+
237+
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
238+
DeveloperKey.apiKey = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'; // use the correct API key
239+
240+
const api = new Shotstack.EditApi();
241+
242+
const id = '8aeabb0e-b5eb-8c5e-847d-82297dd4802a'; // use the template id from previous example
243+
244+
const mergeFieldUrl = new Shotstack.MergeField;
245+
mergeFieldUrl
246+
.setFind('URL')
247+
.setReplace('https://s3-ap-southeast-2.amazonaws.com/shotstack-assets/footage/skater.hd.mp4');
248+
249+
const mergeFieldTrim = new Shotstack.MergeField;
250+
mergeFieldTrim
251+
.setFind('TRIM')
252+
.setReplace(3);
253+
254+
const mergeFieldLength = new Shotstack.MergeField;
255+
mergeFieldLength
256+
.setFind('LENGTH')
257+
.setReplace(6);
258+
259+
const template = new Shotstack.TemplateRender;
260+
template
261+
.setId(id)
262+
.setMerge([
263+
mergeFieldUrl,
264+
mergeFieldTrim,
265+
mergeFieldLength,
266+
]);
267+
268+
api.postTemplateRender(template).then((data) => {
269+
console.log(data.response.id);
270+
});
271+
```
272+
166273
## Video Editing Schemas
167274

168275
The following schemas are used to prepare a video edit.
@@ -741,7 +848,7 @@ setTemplate([Shotstack.Edit](#edit) edit)) | An edit defines the arrangement of
741848
742849
### TemplateRender
743850
744-
Render a template by its id and optional merge fields.
851+
Configure the id and optional merge fields to render a template by id.
745852
746853
#### Example:
747854

0 commit comments

Comments
 (0)