Skip to content

Commit ce4e7b7

Browse files
authored
feat: add Video Stitcher slate code samples and tests (GoogleCloudPlatform#7164)
* feat: add Video Stitcher slate code samples and tests * address feedback
1 parent 1278c48 commit ce4e7b7

11 files changed

Lines changed: 826 additions & 0 deletions

File tree

media/stitcher/pom.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2022 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<groupId>com.example</groupId>
22+
<artifactId>stitcher</artifactId>
23+
<version>1.0-SNAPSHOT</version>
24+
<packaging>jar</packaging>
25+
<!--
26+
The parent pom defines common style checks and testing strategies for our samples.
27+
Removing or replacing it should not affect the execution of the samples in any way.
28+
-->
29+
<parent>
30+
<groupId>com.google.cloud.samples</groupId>
31+
<artifactId>shared-configuration</artifactId>
32+
<version>1.2.0</version>
33+
</parent>
34+
<properties>
35+
<maven.compiler.target>11</maven.compiler.target>
36+
<maven.compiler.source>11</maven.compiler.source>
37+
</properties>
38+
<!-- Using libraries-bom to manage versions.
39+
See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM -->
40+
<dependencyManagement>
41+
<dependencies>
42+
<dependency>
43+
<groupId>com.google.cloud</groupId>
44+
<artifactId>libraries-bom</artifactId>
45+
<version>25.2.0</version>
46+
<type>pom</type>
47+
<scope>import</scope>
48+
</dependency>
49+
</dependencies>
50+
</dependencyManagement>
51+
<dependencies>
52+
<dependency>
53+
<groupId>com.google.cloud</groupId>
54+
<artifactId>google-cloud-video-stitcher</artifactId>
55+
<version>0.1.2</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.google.cloud</groupId>
59+
<artifactId>google-cloud-core</artifactId>
60+
<scope>compile</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-compiler-plugin</artifactId>
65+
<version>3.8.1</version>
66+
</dependency>
67+
<!-- Test dependencies -->
68+
<dependency>
69+
<groupId>junit</groupId>
70+
<artifactId>junit</artifactId>
71+
<version>4.13.2</version>
72+
<scope>test</scope>
73+
</dependency>
74+
</dependencies>
75+
</project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_create_slate]
20+
21+
import com.google.cloud.video.stitcher.v1.CreateSlateRequest;
22+
import com.google.cloud.video.stitcher.v1.LocationName;
23+
import com.google.cloud.video.stitcher.v1.Slate;
24+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
25+
import java.io.IOException;
26+
27+
public class CreateSlate {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
String slateId = "my-slate-id";
34+
String slateUri =
35+
"https://my-slate-uri/test.mp4"; // URI of an MP4 video with at least one audio track
36+
37+
createSlate(projectId, location, slateId, slateUri);
38+
}
39+
40+
public static void createSlate(String projectId, String location, String slateId, String slateUri)
41+
throws IOException {
42+
// Initialize client that will be used to send requests. This client only needs to be created
43+
// once, and can be reused for multiple requests. After completing all of your requests, call
44+
// the "close" method on the client to safely clean up any remaining background resources.
45+
try (VideoStitcherServiceClient videoStitcherServiceClient =
46+
VideoStitcherServiceClient.create()) {
47+
CreateSlateRequest createSlateRequest =
48+
CreateSlateRequest.newBuilder()
49+
.setParent(LocationName.of(projectId, location).toString())
50+
.setSlateId(slateId)
51+
.setSlate(Slate.newBuilder().setUri(slateUri).build())
52+
.build();
53+
54+
Slate response = videoStitcherServiceClient.createSlate(createSlateRequest);
55+
System.out.println("Created new slate: " + response.getName());
56+
}
57+
}
58+
}
59+
// [END video_stitcher_create_slate]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_delete_slate]
20+
21+
import com.google.cloud.video.stitcher.v1.DeleteSlateRequest;
22+
import com.google.cloud.video.stitcher.v1.SlateName;
23+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
24+
import java.io.IOException;
25+
26+
public class DeleteSlate {
27+
28+
public static void main(String[] args) throws Exception {
29+
// TODO(developer): Replace these variables before running the sample.
30+
String projectId = "my-project-id";
31+
String location = "us-central1";
32+
String slateId = "my-slate-id";
33+
34+
deleteSlate(projectId, location, slateId);
35+
}
36+
37+
public static void deleteSlate(String projectId, String location, String slateId)
38+
throws IOException {
39+
// Initialize client that will be used to send requests. This client only needs to be created
40+
// once, and can be reused for multiple requests. After completing all of your requests, call
41+
// the "close" method on the client to safely clean up any remaining background resources.
42+
try (VideoStitcherServiceClient videoStitcherServiceClient =
43+
VideoStitcherServiceClient.create()) {
44+
DeleteSlateRequest deleteSlateRequest =
45+
DeleteSlateRequest.newBuilder()
46+
.setName(SlateName.of(projectId, location, slateId).toString())
47+
.build();
48+
49+
videoStitcherServiceClient.deleteSlate(deleteSlateRequest);
50+
System.out.println("Deleted slate");
51+
}
52+
}
53+
}
54+
// [END video_stitcher_delete_slate]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_get_slate]
20+
21+
import com.google.cloud.video.stitcher.v1.GetSlateRequest;
22+
import com.google.cloud.video.stitcher.v1.Slate;
23+
import com.google.cloud.video.stitcher.v1.SlateName;
24+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
25+
import java.io.IOException;
26+
27+
public class GetSlate {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
String slateId = "my-slate-id";
34+
35+
getSlate(projectId, location, slateId);
36+
}
37+
38+
public static void getSlate(String projectId, String location, String slateId)
39+
throws IOException {
40+
// Initialize client that will be used to send requests. This client only needs to be created
41+
// once, and can be reused for multiple requests. After completing all of your requests, call
42+
// the "close" method on the client to safely clean up any remaining background resources.
43+
try (VideoStitcherServiceClient videoStitcherServiceClient =
44+
VideoStitcherServiceClient.create()) {
45+
GetSlateRequest getSlateRequest =
46+
GetSlateRequest.newBuilder()
47+
.setName(SlateName.of(projectId, location, slateId).toString())
48+
.build();
49+
50+
Slate response = videoStitcherServiceClient.getSlate(getSlateRequest);
51+
System.out.println("Slate: " + response.getName());
52+
}
53+
}
54+
}
55+
// [END video_stitcher_get_slate]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_list_slates]
20+
21+
import com.google.cloud.video.stitcher.v1.ListSlatesRequest;
22+
import com.google.cloud.video.stitcher.v1.LocationName;
23+
import com.google.cloud.video.stitcher.v1.Slate;
24+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
25+
import java.io.IOException;
26+
27+
public class ListSlates {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
34+
listSlates(projectId, location);
35+
}
36+
37+
public static void listSlates(String projectId, String location) throws IOException {
38+
// Initialize client that will be used to send requests. This client only needs to be created
39+
// once, and can be reused for multiple requests. After completing all of your requests, call
40+
// the "close" method on the client to safely clean up any remaining background resources.
41+
try (VideoStitcherServiceClient videoStitcherServiceClient =
42+
VideoStitcherServiceClient.create()) {
43+
ListSlatesRequest listSlatesRequest =
44+
ListSlatesRequest.newBuilder()
45+
.setParent(LocationName.of(projectId, location).toString())
46+
.build();
47+
48+
VideoStitcherServiceClient.ListSlatesPagedResponse response =
49+
videoStitcherServiceClient.listSlates(listSlatesRequest);
50+
System.out.println("Slates:");
51+
52+
for (Slate slate : response.iterateAll()) {
53+
System.out.println(slate.getName());
54+
}
55+
}
56+
}
57+
}
58+
// [END video_stitcher_list_slates]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_update_slate]
20+
21+
import com.google.cloud.video.stitcher.v1.Slate;
22+
import com.google.cloud.video.stitcher.v1.SlateName;
23+
import com.google.cloud.video.stitcher.v1.UpdateSlateRequest;
24+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
25+
import com.google.protobuf.FieldMask;
26+
import java.io.IOException;
27+
28+
public class UpdateSlate {
29+
30+
public static void main(String[] args) throws Exception {
31+
// TODO(developer): Replace these variables before running the sample.
32+
String projectId = "my-project-id";
33+
String location = "us-central1";
34+
String slateId = "my-slate-id";
35+
String slateUri =
36+
"https://my-slate-uri/test.mp4"; // URI of an MP4 video with at least one audio track
37+
38+
updateSlate(projectId, location, slateId, slateUri);
39+
}
40+
41+
// updateSlate updates the slate URI for an existing slate.
42+
public static void updateSlate(String projectId, String location, String slateId, String slateUri)
43+
throws IOException {
44+
// Initialize client that will be used to send requests. This client only needs to be created
45+
// once, and can be reused for multiple requests. After completing all of your requests, call
46+
// the "close" method on the client to safely clean up any remaining background resources.
47+
try (VideoStitcherServiceClient videoStitcherServiceClient =
48+
VideoStitcherServiceClient.create()) {
49+
UpdateSlateRequest updateSlateRequest =
50+
UpdateSlateRequest.newBuilder()
51+
.setSlate(
52+
Slate.newBuilder()
53+
.setName(SlateName.of(projectId, location, slateId).toString())
54+
.setUri(slateUri)
55+
.build())
56+
// Set the update mask to the uri field in the existing slate. You must set the mask
57+
// to the field you want to update.
58+
.setUpdateMask(FieldMask.newBuilder().addPaths("uri").build())
59+
.build();
60+
61+
Slate response = videoStitcherServiceClient.updateSlate(updateSlateRequest);
62+
System.out.println("Updated slate: " + response.getName());
63+
}
64+
}
65+
}
66+
// [END video_stitcher_update_slate]

0 commit comments

Comments
 (0)