Encode a Video From URL

Launch a video encoding job from a publicly accessible video URL.

This guide is your go-to if you want to encode a video that is stored somewhere on the internet with public visibility.

Additionally, you can fetch data from a private cloud bucket by generating a temporary signed URL with your cloud provider.

πŸ“˜

Troubleshooting tip

In Python, you can diagnose API errors with response.raise_for_status().

Please check out the HTTP status codes in the API Reference for further details.

1. Get an access token

To begin, use your API key to obtain an access token.

import requests, json
api_key = 'BYTENITE_API_KEY' # << Paste here your API key

response = requests.post('https://api.bytenite.com/v1/auth/access_token', 
                             json={"apiKey": api_key})
access_token = response.json()['token'] # Your access token will be saved in this variable

2. Create a new job

Create a new job with a name of your choice and utilize the application template named [email protected] In the JSON response, locate job β†’ id to retrieve your new job's ID.

job_name = "Big Buck Bunny SD H.264" # << Insert your custom job name here
app_template = "[email protected]"

response = requests.post('http://api.bytenite.com/v1/customer/jobs', 
                         json={"name": job_name, "templateId": app_template},
                         headers={'Authorization': access_token})
job_id = response.json()['job']['id'] # This variable will contain your job ID

3. Set a URL as data source

Specify the input video source using a URL. Any public URL or temporarily signed URL pointing to a video file is supported. By default, we save your video to a temporary bucket.

input_video_url = "https://storage.googleapis.com/video-test-public/input/bbb.mp4"

data_source_body = {
    "dataSource": {
      "dataSourceDescriptor": "url",
      "params": {
        "@type": "type.googleapis.com/bytenite.data_source.HttpDataSource",
        "url": input_video_url,
      }
    },
    "dataDestination": {
        "dataSourceDescriptor": "bucket",
    }
}

# Use your job ID as the API endpoint slug
response = requests.post(f'https://api.bytenite.com/v1/customer/jobs/datasource/{job_id}', 
                         json=data_source_body, 
                         headers={'Authorization': access_token})

4. Configure the encoding parameters

Use one of our Templates to load a JSON file containing the video parameters for your encoding job.

# Load a video encoding template
with open("path_to_your_template.json") as venc_template: # << Paste the path to your template here
  job_parameters = json.load(venc_template)
  
response = requests.post(f'https://api.bytenite.com/v1/customer/jobs/params/{job_id}', 
                         json=job_parameters, 
                         headers={'Authorization': access_token})  

5. Start the job

Run your video encoding job.

response = requests.post(f'https://api.bytenite.com/v1/customer/jobs/run/{job_id}', 
                         headers={'Authorization': access_token})  

6. Check the job status

Monitor the progress of your job and extract additional information if needed.

response = requests.get(f'https://api.bytenite.com/v1/customer/jobs/{job_id}', 
                         headers={'Authorization': access_token}) 

status = response.json()['job']['state']

7. Download the output video

When your job status changes to JOB_STATE_COMPLETE, you can access the link to your output video. Feel free to download it for your use or any other purposes.

Please keep in mind that if you've chosen our temporary storage option as the data destination, your output will be accessible for 48 hours starting from the moment the job is completed.

response = requests.get(f'https://api.bytenite.com/v1/customer/jobs/{job_id}/results', 
                        headers={'Authorization': access_token})  

results = response.json()['results']
link = results[0]['link']

That's it!

You've now successfully encoded a video from a public URL using ByteNite. Happy encoding!