Skip to content

Commit 09eee4c

Browse files
Merge pull request #2895 from matthewmcdaniel/batch-demo
OCI Batch Service - Video transcoding asset
2 parents 27037af + 4bc2248 commit 09eee4c

13 files changed

Lines changed: 305 additions & 0 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
FROM ubuntu:22.04
3+
4+
RUN apt-get update && \
5+
apt-get install -y ffmpeg curl python3 python3-pip unzip && \
6+
pip3 install oci-cli && \
7+
rm -rf /var/lib/apt/lists/*
8+
9+
RUN mkdir -p /video && chmod 777 /video
10+
11+
WORKDIR /video
12+
13+
COPY entrypoint.sh /entrypoint.sh
14+
RUN chmod +x /entrypoint.sh
15+
16+
ENTRYPOINT ["/entrypoint.sh"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2026 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# OCI Batch Demo - Video transcoding pipeline
2+
3+
# Table of Contents
4+
5+
1. [Description](#description)
6+
2. [Prerequisites](#prerequisites)
7+
3. [Instructions](#instructions)
8+
4. [Useful Links](#useful-links)
9+
5. [License](#license)
10+
11+
# Description
12+
13+
This project contains a small Oracle Cloud Infrastructure (OCI) media-transcoding demo. It builds a Docker image that runs as an OCI Batch task, reads an input video from OCI Object Storage, converts it with `ffmpeg`, and writes the converted output back to Object Storage.
14+
15+
This demo performs the following:
16+
- Downloads an `.mp4` video from an OCI Object Storage bucket.
17+
- Converts the `.mp4` to `.avi` using `ffmpeg`.
18+
- Uploads the resulting `.avi` file to an OCI Object Storage bucket.
19+
20+
# Prerequisites
21+
22+
- An OCI environment with permission to read the input object and create or overwrite the output object in Object Storage.
23+
- The required OCI IAM setup from the `OCI IAM Setup` section below.
24+
- A network in which the batch jobs will run.
25+
- A service gateway to route requests to OCI Object Storage.
26+
- If you do not have access to a browser, you will need the OCI CLI.
27+
28+
## OCI IAM Setup
29+
30+
31+
For this demo, you will need to add IAM policies to authorize your users to modify Batch resources. Furthermore, you will need to add policies that authorizes the Batch service to fetch and upload files to Object Storage. Please follow [this](https://docs.oracle.com/en-us/iaas/Content/oci-batch/iam-policy-example.htm) documentation to create the necessary policies.
32+
33+
Replace the placeholders with your actual compartment name(s).
34+
35+
36+
# Instructions
37+
38+
#### Task 1. Create Batch Context
39+
The batch container is the top-level container for your batch workloads. It consists of the networking, fleets, entitlements, job priorities, and logging configuration.
40+
41+
To create a batch context, go to the batch service and click **Batch Contexts**, then click **Create batch context**. Fill out the following details according to your environment.
42+
43+
1. Name
44+
2. Compartment
45+
3. Description
46+
4. VCN
47+
5. Subnet
48+
6. Fleet
49+
7. Entitlements (Optional)
50+
8. Job Priority Configuration (Optional)
51+
9. Logging Configuration
52+
53+
![Create Batch Context](./images/create_batch_context.png)
54+
55+
#### Task 2. Create Job Pool
56+
A job pool is simply a logical container for jobs. When running a job, you will select a job pool to create it under. To create a job pool, you only need the following configurations.
57+
58+
1. Name
59+
2. Description
60+
3. Compartment
61+
62+
![Create job pool](./images/create_job_pool.png)
63+
64+
#### Task 3. Create Task Profile
65+
A task profile is a reusable configuration which defines the resource requirements for your tasks i.e. 1 OCPU 16 GB of Memory. You can create multiple profiles, each corresponding to a different resource requirement. To create a task profile, you need the following configurations:
66+
67+
1. Name
68+
2. Description
69+
3. Minimum oCPUs
70+
4. Minimum memory in GBs
71+
72+
![Create task profile](./images/create_task_profile.png)
73+
74+
#### Task 4. Set up Local environment and push container images.
75+
1. Create container registry in OCI
76+
![Create container registry](./images/create_container_registry.png)
77+
2. Go to the directory where the Dockerfile is located.
78+
3. Push container image to OCIR. The image should match the region and name of your repository i.e. `iad.ocir.io/convert_mp4_to_avi:latest`
79+
80+
```
81+
docker build -t <image>:<tag> .
82+
docker push <image>:<tag>
83+
```
84+
85+
![Push container to OCIR](./images/push_container_image.png)
86+
4. Create Object Storage buckets for input and output video
87+
88+
![Create input bucket](./images/create_input_bucket.png)
89+
90+
![Create output bucket](./images/create_output_bucket.png)
91+
92+
5. Upload video file to Object Storage.
93+
94+
**NOTE:** If you are using the OCI CLI, you can use this command.
95+
96+
```
97+
oci os object put --namespace <os-namespace> --file <path/to/file> --bucket-name <name_of_bucket>
98+
```
99+
100+
101+
For the purpose of this demo, we've included a `.mp4` that you may use. The file is located here:
102+
103+
```
104+
technology-engineering/app-dev/developer-tools-and-lowcode/batch/20190530-SPITZRf-0001-Stars of Cephus~small.mp4
105+
```
106+
107+
**Disclaimer:** The video is taken from the NASA Image and Video Library, which can be found here: https://images.nasa.gov/
108+
109+
This demonstration is not endorsed by NASA and is compliant with the NASA Images and Media Usage Guidelines: https://www.nasa.gov/nasa-brand-center/images-and-media/
110+
111+
112+
#### Task 5. Create Task environment
113+
A task environment is the runtime configuration for your tasks. To set up a task environment, you will need:
114+
115+
1. Name
116+
2. Description
117+
3. Security Context
118+
a. User ID - 1
119+
b. Group ID - 1
120+
c. Filesystem group ID - 1
121+
**NOTE:** Setting these as 1 should suffice for this example but should be changed according to your security requirements.
122+
4. Working directory
123+
124+
![Create Task Environment](./images/create_task_environment.png)
125+
126+
#### Task 6. Submit Job
127+
128+
There are various ways to submit a job to the Batch service. For this tutorial, we are going to use the OCI CLI.
129+
130+
1. Create a file called `task.json`
131+
2. Copy and paste the following into `task.json`
132+
```
133+
{
134+
"batchJobPoolId": "JOB_POOL_OCID",
135+
"compartmentId": "COMPARTMENT_ID",
136+
"description": "Task to convert video from MP4 to AVI format",
137+
"displayName": "convert_video",
138+
"maxWaitSeconds": 0,
139+
"tasks": [
140+
{
141+
"batchTaskEnvironmentId": "TASK_ENVIRONMENT_OCID",
142+
"batchTaskProfileId": "TASK_PROFILE_OCID",
143+
"description": "Task to convert video from MP4 to AVI format",
144+
"environmentVariables": [
145+
{
146+
"name": "INPUT_BUCKET",
147+
"value": "input_bucket"
148+
},
149+
{
150+
"name": "INPUT_OBJECT",
151+
"value": "input.mp4"
152+
},
153+
{
154+
"name": "OCI_BUCKET",
155+
"value": "output_bucket"
156+
},
157+
{
158+
"name": "OUTPUT_FILENAME",
159+
"value": "output.avi"
160+
},
161+
{
162+
"name": "OCI_NAMESPACE",
163+
"value": "TENANCY_NAMESPACE"
164+
},
165+
{
166+
"name": "OCI_REGION",
167+
"value": "REGION"
168+
}
169+
],
170+
"fleetAssignmentPolicy":
171+
{
172+
"type": "BEST_FIT"
173+
},
174+
"name": "convert_video",
175+
"type": "COMPUTE"
176+
}
177+
],
178+
"waitForState": [
179+
"ACCEPTED"
180+
],
181+
"waitIntervalSeconds": 0
182+
}
183+
```
184+
Replace the following according to your environment:
185+
*JOB_POOL_OCID*
186+
*COMPARTMENT_ID*
187+
*TASK_ENVIRONMENT_OCID*
188+
*TASK_PROFILE_OCID*
189+
*TENANCY_NAMESPACE*
190+
*REGION*
191+
192+
3. Run the following command
193+
194+
```
195+
oci batch batch-job create --from-json file://video_conversion_job.json
196+
```
197+
198+
The job will take up to 10 minutes to complete. Observe the job in the OCI Console to see what stage it is in.
199+
#### Task 8. Validate results
200+
1. In the OCI Console, go to Object Storage.
201+
2. Find the output bucket and validate that the transcoded video is present.
202+
203+
# Useful Links
204+
205+
- [OCI Batch](https://docs.oracle.com/en-us/iaas/Content/oci-batch/overview.htm)
206+
207+
# License
208+
209+
Copyright (c) 2026 Oracle and/or its affiliates.
210+
Licensed under the Universal Permissive License (UPL), Version 1.0.
211+
212+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE.txt) for more details.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Environment variables expected:
5+
# INPUT_BUCKET:
6+
# INPUT_OBJECT:
7+
# OUTPUT_FILENAME
8+
# OCI_BUCKET
9+
# OCI_NAMESPACE
10+
# OCI_REGION
11+
12+
if [[ -z "$INPUT_BUCKET" || -z "$INPUT_OBJECT" ]]; then
13+
echo "Error: INPUT_BUCKET and INPUT_OBJECT environment variables are required."
14+
exit 1
15+
fi
16+
17+
OUTPUT_FILENAME="${OUTPUT_FILENAME:-output.avi}"
18+
OCI_BUCKET="${OCI_BUCKET:-output_files}"
19+
20+
if [[ -z "$OCI_NAMESPACE" || -z "$OCI_REGION" ]]; then
21+
echo "Error: OCI_NAMESPACE and OCI_REGION environment variables are required for upload."
22+
exit 2
23+
fi
24+
25+
echo "Fetching $INPUT_OBJECT from bucket $INPUT_BUCKET (Namespace: $OCI_NAMESPACE, Region: $OCI_REGION) using Resource Principals"
26+
oci --region "$OCI_REGION" --auth resource_principal os object get \
27+
-ns "$OCI_NAMESPACE" \
28+
-bn "$INPUT_BUCKET" \
29+
--name "$INPUT_OBJECT" \
30+
--file input.mp4 \
31+
32+
echo "Converting input.mp4 to $OUTPUT_FILENAME"
33+
ffmpeg -y -i input.mp4 "$OUTPUT_FILENAME"
34+
35+
echo "Uploading $OUTPUT_FILENAME to OCI Bucket: $OCI_BUCKET (Namespace: $OCI_NAMESPACE, Region: $OCI_REGION) using Resource Principals"
36+
oci --region "$OCI_REGION" --auth resource_principal os object put \
37+
-ns "$OCI_NAMESPACE" \
38+
-bn "$OCI_BUCKET" \
39+
--file "$OUTPUT_FILENAME" \
40+
--name "$OUTPUT_FILENAME" \
41+
42+
echo "Upload complete."
57 KB
Loading
34.4 KB
Loading
68.6 KB
Loading
30.4 KB
Loading
68.9 KB
Loading

0 commit comments

Comments
 (0)