-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeff Shillitto
committed
Dec 5, 2022
1 parent
a872195
commit e454eae
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
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; | ||
|
||
const videoAsset = new Shotstack.VideoAsset; | ||
videoAsset | ||
.setSrc('{{ URL }}') | ||
.setTrim('{{ TRIM }}'); | ||
|
||
const videoClip = new Shotstack.Clip; | ||
videoClip | ||
.setAsset(videoAsset) | ||
.setStart(0) | ||
.setLength('{{ LENGTH }}'); | ||
|
||
const track = new Shotstack.Track; | ||
track.setClips([videoClip]); | ||
|
||
const timeline = new Shotstack.Timeline; | ||
timeline.setTracks([track]); | ||
|
||
const output = new Shotstack.Output; | ||
output | ||
.setFormat('mp4') | ||
.setResolution('sd'); | ||
|
||
const mergeFieldUrl = new Shotstack.MergeField; | ||
mergeFieldUrl | ||
.setFind('URL') | ||
.setReplace('https://s3-ap-southeast-2.amazonaws.com/shotstack-assets/footage/skater.hd.mp4'); | ||
|
||
const mergeFieldTrim = new Shotstack.MergeField; | ||
mergeFieldTrim | ||
.setFind('TRIM') | ||
.setReplace(3); | ||
|
||
const mergeFieldLength = new Shotstack.MergeField; | ||
mergeFieldLength | ||
.setFind('LENGTH') | ||
.setReplace(6); | ||
|
||
const edit = new Shotstack.Edit; | ||
edit | ||
.setTimeline(timeline) | ||
.setOutput(output) | ||
.setMerge([ | ||
mergeFieldUrl, | ||
mergeFieldTrim, | ||
mergeFieldLength, | ||
]); | ||
|
||
api.postRender(edit).then((data) => { | ||
const message = data.response.message; | ||
const 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); | ||
}); |