|
| 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 | +  |
| 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 | +  |
| 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 | +  |
| 73 | + |
| 74 | +#### Task 4. Set up Local environment and push container images. |
| 75 | + 1. Create container registry in OCI |
| 76 | +  |
| 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 | +  |
| 86 | + 4. Create Object Storage buckets for input and output video |
| 87 | + |
| 88 | +  |
| 89 | + |
| 90 | +  |
| 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 | +  |
| 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. |
0 commit comments