Media Flow

Oracle Cloud Infrastructure (OCI) Media Flow is a service that enables developers to process video and audio media into different formats for on-demand streaming and run batch operations through APIs and command-line interface (CLI) tools. With OCI Media Flow, you can also enrich metadata to make video content more searchable in a content management system (CMS) and use AI tools to surface video content and add capabilities, such as closed-captioning support for multiple languages.

Oracle Cloud Infrastructure Media Flow: Overview (2:02)

How OCI Media Flow works

How OCI Media Flow works diagram
A video is created and uploaded to Oracle Cloud Infrastructure Object Storage. Through Oracle Cloud Infrastructure Media Flow, thumbnail stills from the video are created from configurable intervals of time and can be stored in OCI Object Storage. OCI Media Flow also creates multiple variants of the video for streaming, and video manifest files for HLS streaming are added to the customer’s file repository. OCI Media Flow creates a JSON file with AI metadata that contains a searchable content index. OCI Media Flow creates the multiple fragmented MP4 and master playlist that are prerequisites for streaming. OCI Media Streams ingests a valid HLS master playlist and creates video packages for video streaming.

How developers can prepare and transcode video files

See how to create a media flow and run OCI Media Flow jobs. This requires the latest java SDK of OCI and takes input of the prefix name for the output files. This is intended for demonstration only and is not for production usage.



/***********
This is a demo program to create media flow and run media flow jobs.
This requires the latest java SDK of OCI.
Takes input of the prefix name for the output files.
This is intended for a demonstration only and not for Production usage.
************/

/***********
1. Accept User Input of prefix for the outputs.
2. Create Media Client. 
3. Create Tasks.
4. Create Media Workflow.
5. Create Media Workflow Job.
************/


import com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider;
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
import com.oracle.bmc.mediaservices.MediaServicesClient;
import com.oracle.bmc.mediaservices.*;
import com.oracle.bmc.mediaservices.model.MediaWorkflowTask;
import com.oracle.bmc.mediaservices.model.CreateMediaWorkflowDetails;
import com.oracle.bmc.mediaservices.responses.CreateMediaWorkflowResponse;
import com.oracle.bmc.mediaservices.model.MediaWorkflow;
import com.oracle.bmc.mediaservices.requests.*;
import com.oracle.bmc.mediaservices.model.CreateMediaWorkflowJobDetails;
import com.oracle.bmc.mediaservices.model.CreateMediaWorkflowJobByIdDetails;
import com.oracle.bmc.mediaservices.responses.CreateMediaWorkflowJobResponse;
import com.oracle.bmc.mediaservices.model.MediaWorkflowJob;
import org.json.simple.*; 
import org.json.simple.parser.*;
import java.util.Collections;
import java.util.*;
import java.util.Scanner;

public class MediaflowDemoApp {
    // Get User Input
    public static String getUserInput(){
        MediaflowDemoApp.printString("Enter a name for the prefix of files:");
        Scanner input = new Scanner(System.in);
        String prefixInput = input.nextLine();
        input.close();
        return prefixInput;
    }
    // Json String to Json Object
    public static JSONObject createJSONObject(String jsonString){
        JSONObject  jsonObject=new JSONObject();
        JSONParser jsonParser=new  JSONParser();
        if ((jsonString != null) && !(jsonString.isEmpty())) {
            try {
                jsonObject=(JSONObject) jsonParser.parse(jsonString);
            } catch (org.json.simple.parser.ParseException e) {
                e.printStackTrace();
            }
        }
        return jsonObject;
    }
    // Print Function
    public static void printString(Object stringtoPrint){
        System.out.println(stringtoPrint);
    }
    // Create Media Service Client.
    public static MediaServicesClient connectMediaService(){
        InstancePrincipalsAuthenticationDetailsProvider provider = InstancePrincipalsAuthenticationDetailsProvider.builder().build();
        MediaServicesClient mediaClient =  new MediaServicesClient(provider);
        // User Principal
        // Read config from the profile DEFAULT in the file "~/.oci/config". You can switch to different profile.
        // AuthenticationDetailsProvider authenticationDetailsProvider = new ConfigFileAuthenticationDetailsProvider(PROFILE_DEFAULT);
        // MediaServicesClient mediaClient = MediaServicesClient.builder().build(authenticationDetailsProvider);
        MediaflowDemoApp.printString("Media Client Instantiated");
        return mediaClient;
    }
    // Close Media Service Client
    public static void closeMediaService(MediaServicesClient mc){
        mc.close();
        MediaflowDemoApp.printString("Media Client Closed");
    }

    // Create Tasks 
    // Tasks are discrete steps in the workflow.
    public static List<MediaWorkflowTask> createTasks(JSONObject arg0,JSONObject arg1,JSONObject arg2,JSONObject arg3,JSONObject arg4){
        long version = 1;
        List<MediaWorkflowTask> task = new ArrayList<MediaWorkflowTask>();
        List<String> typeGetFiles = new ArrayList<String>();
        List<String> typeTranscode = new ArrayList<String>();
        List<String> typeThumbnail = new ArrayList<String>();
        typeGetFiles.add("getFiles");
        typeTranscode.add("transcode1");
        typeThumbnail.add("thumbnail");
        task.add(MediaWorkflowTask.builder().type("getFiles").version(version).key("getFiles").prerequisites(Collections.emptyList()).parameters(arg0).build());
        task.add(MediaWorkflowTask.builder().type("transcribe").version(version).key("transcribe").prerequisites(typeGetFiles).parameters(arg4).build());
        task.add(MediaWorkflowTask.builder().type("transcode").version(version).key("transcode1").prerequisites(typeGetFiles).parameters(arg1).build());
        task.add(MediaWorkflowTask.builder().type("thumbnail").version(version).key("thumbnail").prerequisites(typeTranscode).parameters(arg2).build());
        task.add(MediaWorkflowTask.builder().type("putFiles").version(version).key("PutFiles1").prerequisites(typeThumbnail).parameters(arg3).build());
        return task;
    }
    // Create Media Workflow.
    public static MediaWorkflow createMediaWorkflow(MediaServicesClient mc, List<MediaWorkflowTask> tasks, JSONObject parameters,String compartment_id){
        CreateMediaWorkflowRequest  request = CreateMediaWorkflowRequest.builder().createMediaWorkflowDetails(CreateMediaWorkflowDetails.builder().displayName("test-java-sdk").compartmentId(compartment_id).tasks(tasks).parameters(parameters).build()).build();
        CreateMediaWorkflowResponse response = mc.createMediaWorkflow(request);
        MediaWorkflow mediaflow = response.getMediaWorkflow();
        return mediaflow;
    }
    // Create Media Workflow Job
    public static MediaWorkflowJob createWorkflowJob(MediaServicesClient mc, MediaWorkflow mediaflow, String prefixInput, JSONObject parameters, String compartment_id){
        String mediaWorkflowId = mediaflow.getId();
        CreateMediaWorkflowJobRequest request = CreateMediaWorkflowJobRequest.builder().createMediaWorkflowJobDetails(CreateMediaWorkflowJobByIdDetails.builder().displayName("test-java-sdk-job").compartmentId(compartment_id).mediaWorkflowId(mediaWorkflowId).parameters(parameters).build()).build();
        CreateMediaWorkflowJobResponse response = mc.createMediaWorkflowJob(request);
        MediaWorkflowJob mediaflowJob = response.getMediaWorkflowJob();
        return mediaflowJob;
    }

    public static void main(String[] args) {

        // **Variable Declarations** //
        String compartment_id = "ocid1.compartment.oc1..aaaaaaaabhuut4zoztxlfneotrwuauqt5wjhmj4kxaka6ajme4ipxqlcwv6a";
        String src_bucket = "test";
        String dst_bucket = "test";
        String namespace = "test";
        String src_video = "test";
        String prefix_input = "test";
        
        //* Task Parameters *//
        String getobjectParameters = "{\"taskParameters\": [{\"storageType\": \"objectStorage\",\"target\": \"getFiles/${/input/objectName}\",\"namespaceName\": \"${/input/namespaceName}\",\"bucketName\": \"${/input/bucketName}\",\"objectName\": \"${/input/objectName}\"}]}";
        String transcodeParameters = "{ \"transcodeType\": \"standardTranscode\", \"standardTranscode\": { \"input\": \"${/getFiles/taskParameters/0/target}\", \"outputPrefix\": \"${/transcode/outputPrefix}\", \"videoCodec\": \"h264\", \"audioCodec\": \"aac\", \"packaging\": { \"packageType\": \"hls\", \"segmentLength\": 6 }, \"ladder\": [ { \"size\": { \"height\": 1080, \"resizeMethod\": \"scale\" } }, { \"size\": { \"height\": 720, \"resizeMethod\": \"scale\" } }, { \"size\": { \"height\": 480, \"resizeMethod\": \"scale\" } }, { \"size\": { \"height\": 360, \"resizeMethod\": \"scale\" } } ] } }";
        String thumbnailParameters = "{ \"thumbnails\": { \"input\": \"${/getFiles/taskParameters/0/target}\", \"frameSelectors\": [ { \"namePrefix\": \"thumb\", \"format\": \"jpg\", \"sizes\": [ { \"width\": 390 }, { \"width\": 196 } ], \"clipImagePicker\": { \"percentList\": { \"pickList\": [ 10, 20, 30 ] } } } ] } }";
        String finaltaskParameters = "{ \"taskParameters\": [ { \"namespaceName\": \"${/output/namespaceName}\", \"bucketName\": \"${/output/bucketName}\", \"source\": \"${/transcode/outputPrefix}*.m3u8\", \"objectName\": \"${/output/objectNamePath}${/transcode/outputPrefix}\", \"assetCompartmentId\": \"${/output/assetCompartmentId}\", \"registerMetadata\": true }, { \"namespaceName\": \"${/output/namespaceName}\", \"bucketName\": \"${/output/bucketName}\", \"source\": \"master.m3u8\", \"objectName\": \"${/output/objectNamePath}${/transcode/outputPrefix}-master.m3u8\", \"assetCompartmentId\": \"${/output/assetCompartmentId}\", \"registerMetadata\": true }, { \"namespaceName\": \"${/output/namespaceName}\", \"bucketName\": \"${/output/bucketName}\", \"source\": \"*.fmp4\", \"objectName\": \"${/output/objectNamePath}\", \"assetCompartmentId\": \"${/output/assetCompartmentId}\", \"registerMetadata\": true }, { \"namespaceName\": \"${/output/namespaceName}\", \"bucketName\": \"${/output/bucketName}\", \"source\": \"*.${/thumbnail/thumbnails/frameSelectors/0/format}\", \"objectName\": \"${/output/objectNamePath}${/transcode/outputPrefix}-\", \"assetCompartmentId\": \"${/output/assetCompartmentId}\", \"registerMetadata\": true } ] }";
        String transcibeParmeters = "{ \"inputVideo\": \"${/getFiles/taskParameters/0/target}\", \"outputAudio\": \"${/output/objectNamePath}${/transcode/outputPrefix}.wav\", \"outputBucketName\": \"${/output/bucketName}\", \"outputNamespaceName\": \"${/output/namespaceName}\", \"outputTranscriptionPrefix\": \"${/output/objectNamePath}${/transcode/outputPrefix}\", \"transcriptionJobCompartment\": \"${/output/assetCompartmentId}\", \"waitForCompletion\" : true }";
        String mediaworkflowParameters = "{ \"input\": { \"objectName\": \"${/video/srcVideo}\", \"bucketName\": \"${/video/srcBucket}\", \"namespaceName\": \"${/video/namespace}\" }, \"output\": { \"bucketName\": \"${/video/dstBucket}\", \"namespaceName\": \"${/video/namespace}\", \"assetCompartmentId\": \"${/video/compartmentID}\", \"objectNamePath\": \"sdk_test/${/input/objectName}/\" }, \"transcode\": { \"outputPrefix\": \"${/video/outputPrefixName}\" } }";
        String mediaflowjobParameters = "{ \"video\": { \"srcBucket\": \"" + src_bucket+ "\", \"dstBucket\": \"" +dst_bucket+ "\", \"namespace\": \"" +namespace+ "\", \"compartmentID\": \""+compartment_id+"\", \"srcVideo\": \""+src_video+"\", \"outputPrefixName\" : \""+prefix_input+"\" } }";
        //* Json Objects of the task parameters *//
        JSONObject getobjectParametersJson = MediaflowDemoApp.createJSONObject(getobjectParameters);
        JSONObject transcodeParametersJson = MediaflowDemoApp.createJSONObject(transcodeParameters);
        JSONObject thumbnailParametersJson = MediaflowDemoApp.createJSONObject(thumbnailParameters);
        JSONObject finaltaskParametersJson = MediaflowDemoApp.createJSONObject(finaltaskParameters);
        JSONObject transcibeParmetersJson = MediaflowDemoApp.createJSONObject(transcibeParmeters);
        JSONObject mediaworkflowParametersJson = MediaflowDemoApp.createJSONObject(mediaworkflowParameters);
        JSONObject mediaflowjobParametersJson = MediaflowDemoApp.createJSONObject(mediaflowjobParameters);
        
        /* Debug JSON Prints
        MediaflowDemoApp.printString(getobjectParametersJson);
        MediaflowDemoApp.printString(transcodeParametersJson);
        MediaflowDemoApp.printString(thumbnailParametersJson);
        MediaflowDemoApp.printString(finaltaskParametersJson);
        MediaflowDemoApp.printString(transcibeParmetersJson);
        MediaflowDemoApp.printString(mediaworkflowParametersJson);
        MediaflowDemoApp.printString(mediaflowjobParametersJson);*/
        
        // Get User Input
        String prefixInput = MediaflowDemoApp.getUserInput();
        // Create the tasks for mediaflow
        List<MediaWorkflowTask> tasks = MediaflowDemoApp.createTasks(getobjectParametersJson,transcodeParametersJson,thumbnailParametersJson,finaltaskParametersJson,transcibeParmetersJson);
        // Connect to media services 
        MediaServicesClient mediaClient = MediaflowDemoApp.connectMediaService();
        // Create MediaWorkFlow 
        MediaWorkflow mediaflow = MediaflowDemoApp.createMediaWorkflow(mediaClient, tasks, mediaworkflowParametersJson, compartment_id);
        // Prints MediaWorkflow OCID
        MediaflowDemoApp.printString(mediaflow.getId());
        // Create the Workflow Job
        MediaWorkflowJob mediaflowJob = MediaflowDemoApp.createWorkflowJob(mediaClient, mediaflow, prefixInput, mediaflowjobParametersJson, compartment_id);
        // Print Workflow Job ID
        MediaflowDemoApp.printString(mediaflowJob.getId());
        // Finally Close the Media Client
        MediaflowDemoApp.closeMediaService(mediaClient);
    }
}
	

OCI Media Flow use cases

Store and manage videos

OCI Media Flow provides metadata to process videos and store them in a CMS, transcodes the video for delivery, creates multiple versions of the video to play different video resolutions, and creates a master playlist to prepare for streaming.

Clip videos

Clip videos more easily. After selecting the desired resolutions and configurations, OCI Media Flow can automatically deliver the right video format for popular social media sites such as Facebook and Twitter for easy sharing with various audiences.

Create a learning platform

Easily create, process, and store videos for a learning platform experience with OCI Media Flow, and guarantee a high-quality customer experience.

Archive videos

OCI Media Flow simplifies processing, managing, and performing content discovery for archived videos to enhance searchability. OCI Object Storage can store videos at scale and at a low cost.

Oracle launches OCI Digital Media Services to accelerate video operations in OCI

Remi Fourreau, Principal Product Manager, Oracle

We’re excited to announce the general availability of Digital Media Services (DMS) in Oracle Cloud Infrastructure (OCI). OCI customers with video content can leverage the low-cost media processing capabilities with DMS Media Flow and media distribution with DMS Media Streams services. These services can enhance applications and business processes with new media capabilities that create better customer experiences and improve business operations.

Read the complete post

Featured OCI Media Flow blogs

View all

Get started with OCI Media Flow

Try Always Free cloud services and get a 30-day trial

Oracle offers a Free Tier with no time limits on selection of services like Media Flow, Media Streams, and AI Services as well as US$300 in free credits to try additional cloud services. Get the details and sign up for your free account today.

  • What's included with Oracle Cloud Free Tier?

    • Always Free
    • 2 Autonomous Databases, 20 GB each
    • Compute VMs
    • 100 GB block volume
    • 10 GB object storage

Contact sales

Interested in learning more about Media Flow? Let one of our experts help.

  • They can answer questions like:

    • Which services integrate seamlessly with OCI Media Flow?
    • What does pricing look like for my scenarios?
    • How are the different video formats that Media Flow supports?