diff --git a/examples/destination.js b/examples/destination.js index c2e1aed..972bd5d 100644 --- a/examples/destination.js +++ b/examples/destination.js @@ -76,8 +76,6 @@ edit .setTimeline(timeline) .setOutput(output); - console.log(JSON.stringify(edit)); - api.postRender(edit).then((data) => { let message = data.response.message; let id = data.response.id diff --git a/examples/probe.js b/examples/probe.js new file mode 100644 index 0000000..ded0e75 --- /dev/null +++ b/examples/probe.js @@ -0,0 +1,40 @@ +const Shotstack = require('shotstack-sdk'); + +const defaultClient = Shotstack.ApiClient.instance; +const DeveloperKey = defaultClient.authentications['DeveloperKey']; +const api = new Shotstack.EditApi(); +const url = process.argv[2]; + +if (!url) { + console.log(">> Please provide the URL to a media file to inspect (i.e. php examples/probe.php https://github.com/shotstack/test-media/raw/main/captioning/scott-ko.mp4)\n"); + process.exit(1); +} + +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; + +api.probe(url).then((data) => { + data.response.metadata.streams.forEach(stream => { + if (stream.codec_type === 'video') { + console.log('Example settings for: ' + data.response.metadata.format.filename); + console.log('Width: ' + stream.width + 'px'); + console.log('Height: ' + stream.height + 'px'); + console.log('Framerate: ' + stream.r_frame_rate + ' fps'); + console.log('Duration: ' + stream.duration + ' secs'); + } + }); +}, (error) => { + console.error('Request failed or not found: ', error); + process.exit(1); +}); diff --git a/examples/status.js b/examples/status.js index b1ce0d2..ec8c884 100644 --- a/examples/status.js +++ b/examples/status.js @@ -5,6 +5,11 @@ const DeveloperKey = defaultClient.authentications['DeveloperKey']; const api = new Shotstack.EditApi(); const id = process.argv[2]; +if (!id) { + console.log(">> Please provide the UUID of the render task (i.e. php examples/status.php 2abd5c11-0f3d-4c6d-ba20-235fc9b8e8b7)\n"); + process.exit(1); +} + let apiUrl = 'https://api.shotstack.io/stage'; if (!process.env.SHOTSTACK_KEY) { @@ -19,7 +24,7 @@ if (process.env.SHOTSTACK_HOST) { defaultClient.basePath = apiUrl; DeveloperKey.apiKey = process.env.SHOTSTACK_KEY; -api.getRender(id).then((data) => { +api.getRender(id, { data: false, merged: true }).then((data) => { let status = data.response.status; let url = data.response.url; diff --git a/examples/transform.js b/examples/transform.js new file mode 100644 index 0000000..68b19c6 --- /dev/null +++ b/examples/transform.js @@ -0,0 +1,80 @@ +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('https://s3-ap-southeast-2.amazonaws.com/shotstack-assets/footage/skater.hd.mp4'); + +const rotate = new Shotstack.RotateTransformation; +rotate + .setAngle(45); + +const skew = new Shotstack.SkewTransformation; +skew + .setX(0.25) + .setY(0.1); + +const flip = new Shotstack.FlipTransformation; +flip + .setHorizontal(true) + .setVertical(true); + +const transformation = new Shotstack.Transformation; +transformation + .setRotate(rotate) + .setSkew(skew) + .setFlip(flip); + +const videoClip = new Shotstack.Clip; +videoClip + .setAsset(videoAsset) + .setStart(0) + .setLength(8) + .setScale(0.6) + .setTransform(transformation); + +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 edit = new Shotstack.Edit; +edit + .setTimeline(timeline) + .setOutput(output); + +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); +});