How-to Process a Region of an Input File

Seek to a start time to create a trimmed cut

🚧

The Transcode API does not support this procedure. See the How-to Trim a Media File guide using the Transcode API.

When dealing with large media files you may not want to process the entire file. You may only need a partial region of the file or you may want to preview small segments with different parameters to evaluate the sound of different settings. To enable these types of workflows, you can use the region parameter.

Media APIs such as the Media Enhance API and Media Analyze API can be used to process only a subsection of the entire content. To use region, add it as a parameter inside the input object and specify start and end times, which define the start and the end of the section you want to process in seconds.

❗️

Input Object

The input parameter is allowed to be either a string or an object. To specify a region for processing, you must use the object form.

See the following code example of how to use the region parameter in an enhance function:

import os
import requests

body = {
  "input": {
    "url": "dlb://in/example.mp3",
    "region": {   # Define region here
      "start": 0, # Start of the section to be processed in seconds
      "end": 30   # End of the section to be processed in seconds
    }
  },
  "output" : "dlb://out/example.mp3"
}
url = "https://api.dolby.com/media/enhance"
headers = {
  "x-api-key": os.environ["DOLBYIO_MEDIA_APIKEY"],
  "Content-Type": "application/json",
  "Accept": "application/json"
}

response = requests.post(url, json=body, headers=headers)
response.raise_for_status()
json = response.json()
print(f"File uploaded successfully with the job id: {json['job_id']}")
const options = {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    'x-api-key': process.env.DOLBYIO_MEDIA_APIKEY
  },
  body: JSON.stringify({
    input: {
      url: 'dlb://in/example.mp3',
      
      region: {   // Define region here
        start: 0, // Start of the section to be processed in seconds
        end: 30   // End of the section to be processed in seconds
      }
    },
    output: 'dlb://out/example.mp3'
  })
};

fetch('https://api.dolby.com/media/enhance', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
curl --request POST \
     --url https://api.dolby.com/media/enhance \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --header "x-api-key: $DOLBYIO_MEDIA_APIKEY" \
     --data '
{
     "input": {
          "url": "dlb://in/example.mp3",
          "region": {
               "start": 0,
               "end": 30
          }
     }
     "output": "dlb://out/example.mp3"
}
'

The above code will create an output of only the first thirty seconds of the file having been enhanced.


Did this page help you?