-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlayers.php
More file actions
110 lines (90 loc) · 3.08 KB
/
layers.php
File metadata and controls
110 lines (90 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
require __DIR__ . '/../vendor/autoload.php';
use Shotstack\Client\Api\EditApi;
use Shotstack\Client\ApiException;
use Shotstack\Client\Configuration;
use Shotstack\Client\Model\Edit;
use Shotstack\Client\Model\Output;
use Shotstack\Client\Model\Soundtrack;
use Shotstack\Client\Model\Timeline;
use Shotstack\Client\Model\Track;
use Shotstack\Client\Model\Clip;
use Shotstack\Client\Model\TitleAsset;
use Shotstack\Client\Model\VideoAsset;
class LayersDemo
{
protected $apiKey;
protected $apiUrl = 'https://api.shotstack.io/stage';
public function __construct()
{
if (empty(getenv('SHOTSTACK_KEY'))) {
die("API Key is required. Set using: export SHOTSTACK_KEY=your_key_here\n");
}
if (!empty(getenv('SHOTSTACK_HOST'))) {
$this->apiUrl = getenv('SHOTSTACK_HOST');
}
$this->apiKey = getenv('SHOTSTACK_KEY');
}
public function render()
{
$config = Configuration::getDefaultConfiguration()
->setHost($this->apiUrl)
->setApiKey('x-api-key', $this->apiKey);
$client = new EditApi(null, $config);
$soundtrack = new Soundtrack();
$soundtrack
->setEffect("fadeOut")
->setSrc("https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/music/freepd/fireworks.mp3");
// Title - top layer (track1)
$titleAsset = new TitleAsset();
$titleAsset
->setStyle('chunk')
->setText('HELLO WORLD')
->setSize('x-large');
$title = new Clip();
$title
->setAsset($titleAsset)
->setStart(0)
->setLength(10)
->setEffect('zoomIn')
->setOpacity(0.35);
$track1 = new Track();
$track1
->setClips([$title]);
// Video - bottom layer (track2)
$videoAsset = new VideoAsset();
$videoAsset
->setSrc('https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/footage/night-sky.mp4');
$video = new Clip();
$video
->setAsset($videoAsset)
->setStart(0)
->setLength(10);
$track2 = new Track();
$track2
->setClips([$video]);
$timeline = new Timeline();
$timeline
->setBackground("#000000")
->setSoundtrack($soundtrack)
->setTracks([$track1, $track2]); // Put track1 first to go above track2
$output = new Output();
$output
->setFormat('mp4')
->setResolution('sd');
$edit = new Edit();
$edit
->setTimeline($timeline)
->setOutput($output);
try {
$response = $client->postRender($edit)->getResponse();
} catch (ApiException $e) {
die('Request failed: ' . $e->getMessage() . $e->getResponseBody());
}
echo $response->getMessage() . "\n";
echo ">> Now check the progress of your render by running:\n";
echo ">> php examples/status.php " . $response->getId() . "\n";
}
}
$editor = new LayersDemo();
$editor->render();