Repository navigation
Expand file tree
/
Copy pathtransform-and-deliver-video.php
More file actions
66 lines (52 loc) · 1.95 KB
/
Copy pathtransform-and-deliver-video.php
File metadata and controls
66 lines (52 loc) · 1.95 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
<?php
/**
* Build video delivery URLs, edit the timeline, and generate a <video> tag.
*
* Prerequisites:
* composer require cloudinary/cloudinary_php
* export CLOUDINARY_URL=cloudinary://<api_key>:<api_secret>@<cloud_name>
* php examples/upload-large-video.php (creates the asset this file transforms)
*
* Run:
* php examples/transform-and-deliver-video.php
*
* In your own project, the import and instantiation are:
* require 'vendor/autoload.php';
* use Cloudinary\Cloudinary;
* $cloudinary = new Cloudinary();
*/
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use Cloudinary\Cloudinary;
use Cloudinary\Transformation\Delivery;
use Cloudinary\Transformation\Format;
use Cloudinary\Transformation\Quality;
use Cloudinary\Transformation\Resize;
use Cloudinary\Transformation\VideoEdit;
const PUBLIC_ID = 'examples/upload-large-video';
function main(): void
{
$cloudinary = new Cloudinary();
// Resize with auto format and quality.
$optimized = $cloudinary->video(PUBLIC_ID)
->resize(Resize::fill(640, 360))
->delivery(Delivery::format(Format::auto()))
->delivery(Delivery::quality(Quality::auto()));
echo 'Optimized: ', $optimized, PHP_EOL;
// Trim to the first five seconds.
$trimmed = $cloudinary->video(PUBLIC_ID)
->videoEdit(VideoEdit::trim()->startOffset(0)->endOffset(5));
echo 'Trimmed: ', $trimmed, PHP_EOL;
// Auto-generated highlight preview.
echo 'Preview: ', $cloudinary->video(PUBLIC_ID)->videoEdit(VideoEdit::preview(5)), PHP_EOL;
// The <video> tag carries a generated poster image.
$tag = $cloudinary->videoTag(PUBLIC_ID)->resize(Resize::fill(640, 360));
echo 'Tag: ', $tag, PHP_EOL;
}
try {
main();
} catch (Throwable $e) {
fwrite(STDERR, 'Building video URLs failed: ' . $e->getMessage() . PHP_EOL);
fwrite(STDERR, 'Check that CLOUDINARY_URL is set (Console > Settings > API Keys).' . PHP_EOL);
exit(1);
}