-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathvideo-audio-transcoding.php
222 lines (199 loc) · 7.15 KB
/
video-audio-transcoding.php
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
use Filestack\FilestackClient;
use Filestack\FilestackSecurity;
use Filestack\Filelink;
use Filestack\FilestackException;
$test_api_key = 'YOUR_FILESTACK_API_KEY';
$test_secret = 'YOUR_FILESTACK_SECURITY_SECRET';
$security = new FilestackSecurity($test_secret);
$client = new FilestackClient($test_api_key, $security);
/**
* IMPORTANT: To use the audio conversion function, you must setup webhooks to
* notify you when the transcoding has completed. See our online documentation
* for more details:
* https://www.filestack.com/docs/audio-transformations
*/
// transcoding video with client
$source = 'Q5eBTKldRfCSuEjUYuAz';
$output_options = [
'access' => 'public',
'aspect_mode' => 'letterbox',
'audio_bitrate' => 256,
'audio_channels' => 2,
'audio_sample_rate' => 44100,
'fps' => 60,
'title' => 'test Filestack Audio conversion',
'video_bitrate' => 1024,
'watermark_top' => 10,
'watermark_url' => 'Bc2FQwXReueTsaeXB6rO'
];
$force = true;
$result = $client->convertVideo($source, 'm4a', $output_options, $force);
$uuid = $result['uuid'];
$conversion_url = $result['conversion_url'];
$info = $client->getConvertTaskInfo($conversion_url);
$status = $info['status'];
if ($status === 'completed') {
$thumbnail = $info['data']['thumb'];
$url = $info['data']['url'];
}
# echo "\nvideo conversion, uuid=$uuid\n";
// transcoding video with filelink
$filelink = new Filelink('Q5eBTKldRfCSuEjUYuAz', $test_api_key, $security);
$output_options = [
'access' => 'public',
'aspect_mode' => 'letterbox',
'audio_bitrate' => 256,
'audio_channels' => 2,
'audio_sample_rate' => 44100,
'fps' => 60,
'title' => 'test Filestack Audio conversion',
'video_bitrate' => 1024,
'watermark_top' => 10,
'watermark_url' => 'Bc2FQwXReueTsaeXB6rO'
];
$result = $filelink->convertVideo('m4a', $output_options);
// check the status of a conversion task
$info = $client->getConvertTaskInfo($result['conversion_url']);
# vardump($info);
$status = $info['status'];
if ($status === 'completed') {
$thumbnail = $info['data']['thumb'];
$url = $info['data']['url'];
}
# Example video transcoding task callback data, which will post to your webhook
# once the conversion task is completed
/*
{
"status":"completed",
"message":"Done",
"data":{
"thumb":"https://cdn.filestackcontent.com/f1e8V88QDuxzOvtOAq1W",
"thumb100x100":"https://process.filestackapi.com/AhTgLagciQByzXpFGRI0Az/resize=w:100,h:100,f:crop/output=f:jpg,q:66/https://cdn.filestackcontent.com/f1e8V88QDuxzOvtOAq1W",
"thumb200x200":"https://process.filestackapi.com/AhTgLagciQByzXpFGRI0Az/resize=w:200,h:200,f:crop/output=f:jpg,q:66/https://cdn.filestackcontent.com/f1e8V88QDuxzOvtOAq1W",
"thumb300x300":"https://process.filestackapi.com/AhTgLagciQByzXpFGRI0Az/resize=w:300,h:300,f:crop/output=f:jpg,q:66/https://cdn.filestackcontent.com/f1e8V88QDuxzOvtOAq1W",
"url":"https://cdn.filestackcontent.com/VgvFVdvvTkml0WXPIoGn"
},
"metadata":{
"result":{
"audio_channels":2,
"audio_codec":"vorbis",
"audio_sample_rate":44100,
"created_at":"2015/12/21 20:45:19 +0000",
"duration":10587,
"encoding_progress":100,
"encoding_time":8,
"extname":".webm",
"file_size":293459,
"fps":24,
"height":260,
"mime_type":"video/webm",
"started_encoding_at":"2015/12/21 20:45:22 +0000",
"updated_at":"2015/12/21 20:45:32 +0000",
"video_bitrate":221,
"video_codec":"vp8",
"width":300
},
"source":{
"audio_bitrate":125,
"audio_channels":2,
"audio_codec":"aac",
"audio_sample_rate":44100,
"created_at":"2015/12/21 20:45:19 +0000",
"duration":10564,
"extname":".mp4",
"file_size":875797,
"fps":24,
"height":360,
"mime_type":"video/mp4",
"updated_at":"2015/12/21 20:45:32 +0000",
"video_bitrate":196,
"video_codec":"h264",
"width":480
}
},
"timestamp":"1453850583",
"uuid":"638311d89d2bc849563a674a45809b7c"
}
*/
// transcoding audio with client
$source = 'https://upload.wikimedia.org/wikipedia/commons/b/b5/'.
'Op.14%2C_Scherzo_No.2_in_C_minor_for_piano%2C_C._Schumann.ogg';
$output_options = [
'access' => 'public',
'audio_bitrate' => 256,
'audio_channels' => 2,
'audio_sample_rate' => 44100,
'force' => true,
'title' => 'test Filestack Audio conversion'
];
$result = $client->convertAudio($source, 'mp3', $output_options);
// check the status of a conversion task
$info = $client->getConvertTaskInfo($result['conversion_url']);
# vardump($info);
$status = $info['status'];
if ($status === 'completed') {
$thumbnail = $info['data']['thumb'];
$url = $info['data']['url'];
}
# echo "\naudio conversion, uuid=$uuid\n";
// audio conversion with filelink
$filelink = new Filelink('Q5eBTKldRfCSuEjUYuAz', $test_api_key, $security);
$output_options = [
'access' => 'public',
'audio_bitrate' => 256,
'audio_channels' => 2,
'audio_sample_rate' => 44100,
'force' => true,
'title' => 'test Filestack Audio conversion'
];
$result = $filelink->convertAudio('mp3', $output_options);
// check the status of a conversion task
$info = $filelink->getConvertTaskInfo($result['conversion_url']);
# vardump($info);
$status = $info['status'];
if ($status === 'completed') {
$thumbnail = $info['data']['thumb'];
$url = $info['data']['url'];
}
# echo "\naudio conversion, uuid=$uuid\n";
// example audio transcoding task callback data
/*
{
"data":{
"url":"https://cdn.filestackcontent.com/2xIn8g3AQdmfFPD5Brkk"
},
"metadata":{
"result":{
"audio_bitrate":64,
"audio_channels":2,
"audio_codec":"mp3",
"audio_sample_rate":48000,
"created_at":"2016/02/25 07:16:08 +0000",
"duration":251472,
"encoding_progress":100,
"encoding_time":16,
"extname":".mp3",
"file_size":2.012013e+06,
"mime_type":"audio/mpeg",
"started_encoding_at":"2016/02/25 07:16:09 +0000",
"updated_at":"2016/02/25 07:16:27 +0000"
},
"source":{
"audio_bitrate":128,
"audio_channels":2,
"audio_codec":"vorbis",
"audio_sample_rate":44100,
"created_at":"2016/02/25 07:16:08 +0000",
"duration":251427,
"extname":".ogg",
"file_size":3.062342e+06,
"mime_type":"audio/ogg",
"updated_at":"2016/02/25 07:16:27 +0000"
}
},
"status":"completed",
"timestamp":"1456384626",
"uuid":"57694303a5d29c148154d5f706b4c256"
}
*/