Skip to content

Commit

Permalink
Add probe and transform examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffski committed Nov 4, 2021
1 parent 3bffca1 commit 77ee0d4
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 3 deletions.
2 changes: 0 additions & 2 deletions examples/destination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions examples/probe.js
Original file line number Diff line number Diff line change
@@ -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);
});
7 changes: 6 additions & 1 deletion examples/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;

Expand Down
80 changes: 80 additions & 0 deletions examples/transform.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 77ee0d4

Please sign in to comment.