Skip to content

Commit a81cf3e

Browse files
authored
feat: add Video Stitcher samples and tests (GoogleCloudPlatform#1725)
1 parent 660a57d commit a81cf3e

File tree

9 files changed

+517
-0
lines changed

9 files changed

+517
-0
lines changed

media/videostitcher/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Google Cloud Video Stitcher PHP Sample Application
2+
3+
[![Open in Cloud Shell][shell_img]][shell_link]
4+
5+
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.svg
6+
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googlecloudplatform/php-docs-samples&page=editor&working_dir=media/videostitcher
7+
8+
## Description
9+
10+
This simple command-line application demonstrates how to invoke
11+
[Cloud Video Stitcher API][videostitcher-api] from PHP.
12+
13+
[videostitcher-api]: https://cloud.google.com/video-stitcher/docs/reference/libraries
14+
15+
## Build and Run
16+
1. **Enable APIs** - [Enable the Video Stitcher API](
17+
https://console.cloud.google.com/flows/enableapi?apiid=videostitcher.googleapis.com)
18+
and create a new project or select an existing project.
19+
2. **Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click
20+
"New Credentials"
21+
and select "Service Account Key". Create a new service account, use the JSON key type, and
22+
select "Create". Once downloaded, set the environment variable `GOOGLE_APPLICATION_CREDENTIALS`
23+
to the path of the JSON key that was downloaded.
24+
3. **Clone the repo** and cd into this directory
25+
```
26+
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
27+
$ cd media/videostitcher
28+
```
29+
4. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
30+
Run `php composer.phar install` (if composer is installed locally) or `composer install`
31+
(if composer is installed globally).
32+
5. Execute the snippets in the [src/](src/) directory by running
33+
`php src/SNIPPET_NAME.php`. The usage will print for each if no arguments
34+
are provided:
35+
```sh
36+
$ php src/create_slate.php
37+
Usage: create_slate.php $callingProjectId $location $slateId $slateUri
38+
39+
@param string $callingProjectId The project ID to run the API call under
40+
@param string $location The location of the slate
41+
@param string $slateId The name of the slate to be created
42+
@param string $slateUri The public URI for an MP4 video with at least one audio track
43+
44+
$ php create_slate.php my-project us-central1 my-slate https://storage.googleapis.com/my-bucket/my-slate.mp4
45+
Slate: projects/123456789012/locations/us-central1/slates/my-slate
46+
```
47+
48+
See the [Video Stitcher Documentation](https://cloud.google.com/video-stitcher/docs/) for more information.
49+
50+
## Contributing changes
51+
52+
* See [CONTRIBUTING.md](../../CONTRIBUTING.md)
53+
54+
## Licensing
55+
56+
* See [LICENSE](../../LICENSE)

media/videostitcher/composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "google/video-stitcher-sample",
3+
"type": "project",
4+
"require": {
5+
"google/cloud-video-stitcher": "^0.3.0"
6+
}
7+
}

media/videostitcher/phpunit.xml.dist

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
xml version="1.0" encoding="UTF-8"?>
2+
17+
<phpunit bootstrap="../../testing/bootstrap.php">
18+
<testsuites>
19+
<testsuite name="PHP Video Stitcher API tests">
20+
<directory>testdirectory>
21+
testsuite>
22+
testsuites>
23+
<logging>
24+
<log type="coverage-clover" target="build/logs/clover.xml"/>
25+
logging>
26+
<filter>
27+
<whitelist>
28+
<directory suffix=".php">./srcdirectory>
29+
<exclude>
30+
<directory>./vendordirectory>
31+
exclude>
32+
whitelist>
33+
filter>
34+
<php>
35+
<env name="PHPUNIT_TESTS" value="1"/>
36+
php>
37+
phpunit>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_create_slate]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\Slate;
30+
31+
/**
32+
* Creates a slate. A slate is displayed when ads are not available.
33+
*
34+
* @param string $callingProjectId The project ID to run the API call under
35+
* @param string $location The location of the slate
36+
* @param string $slateId The name of the slate to be created
37+
* @param string $slateUri The public URI for an MP4 video with at least one audio track
38+
*/
39+
function create_slate(
40+
string $callingProjectId,
41+
string $location,
42+
string $slateId,
43+
string $slateUri
44+
): void {
45+
// Instantiate a client.
46+
$stitcherClient = new VideoStitcherServiceClient();
47+
48+
$parent = $stitcherClient->locationName($callingProjectId, $location);
49+
$slate = new Slate();
50+
$slate->setUri($slateUri);
51+
52+
// Run slate creation request
53+
$response = $stitcherClient->createSlate($parent, $slateId, $slate);
54+
55+
// Print results
56+
printf('Slate: %s' . PHP_EOL, $response->getName());
57+
}
58+
// [END videostitcher_create_slate]
59+
60+
// The following 2 lines are only needed to run the samples
61+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
62+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_delete_slate]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
30+
/**
31+
* Deletes a slate.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the slate
35+
* @param string $slateId The ID of the slate
36+
*/
37+
function delete_slate(
38+
string $callingProjectId,
39+
string $location,
40+
string $slateId
41+
): void {
42+
// Instantiate a client.
43+
$stitcherClient = new VideoStitcherServiceClient();
44+
45+
$formattedName = $stitcherClient->slateName($callingProjectId, $location, $slateId);
46+
$stitcherClient->deleteSlate($formattedName);
47+
48+
// Print status
49+
printf('Deleted slate %s' . PHP_EOL, $slateId);
50+
}
51+
// [END videostitcher_delete_slate]
52+
53+
// The following 2 lines are only needed to run the samples
54+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
55+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

media/videostitcher/src/get_slate.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_get_slate]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
30+
/**
31+
* Gets a slate.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the slate
35+
* @param string $slateId The ID of the slate
36+
*/
37+
function get_slate(
38+
string $callingProjectId,
39+
string $location,
40+
string $slateId
41+
): void {
42+
// Instantiate a client.
43+
$stitcherClient = new VideoStitcherServiceClient();
44+
45+
$formattedName = $stitcherClient->slateName($callingProjectId, $location, $slateId);
46+
$slate = $stitcherClient->getSlate($formattedName);
47+
48+
// Print results
49+
printf('Slate: %s' . PHP_EOL, $slate->getName());
50+
}
51+
// [END videostitcher_get_slate]
52+
53+
// The following 2 lines are only needed to run the samples
54+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
55+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_list_slates]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
30+
/**
31+
* Lists all slates for a location.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the slates
35+
*/
36+
function list_slates(
37+
string $callingProjectId,
38+
string $location
39+
): void {
40+
// Instantiate a client.
41+
$stitcherClient = new VideoStitcherServiceClient();
42+
43+
$parent = $stitcherClient->locationName($callingProjectId, $location);
44+
$response = $stitcherClient->listSlates($parent);
45+
46+
// Print the slate list.
47+
$slates = $response->iterateAllElements();
48+
print('Slates:' . PHP_EOL);
49+
foreach ($slates as $slate) {
50+
printf('%s' . PHP_EOL, $slate->getName());
51+
}
52+
}
53+
// [END videostitcher_list_slates]
54+
55+
// The following 2 lines are only needed to run the samples
56+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
57+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)