DEV Community

Cover image for Transcode video with open web services

Transcode video with open web services

Video file transcoding in your media supply chain using open web services in Eyevinn Open Source Cloud in five minutes or less.

Eyevinn Open Source Cloud was developed to reduce the barrier to getting started with open source and at the same time contribute to a sustainable model for open source by giving back a share of the revenue to the creator.

In this guide

  1. Get an API Access Token and setup project.
  2. Setup a storage for storing the transcoded video files.
  3. Setup a video transcoder.
  4. Transcode a video file

Prerequisites

  • An Eyevinn Open Source Cloud account. Sign up for free if you don't already have an account. No credit card required for free plan.

Access to 1 open web service is included in the free plan. If you choose to use an open web service for storing the transcoded video files you need startup plan that includes access to 2 open web services. See pricing for more details.

Get an API Access Token and setup project

Navigate to Settings / API in the Eyevinn Open Source Cloud web console.

Skärmavbild 2025-01-30 kl  22 54 07

Copy this token and store in your shell's environment in the environment variable OSC_ACCESS_TOKEN.

% export OSC_ACCESS_TOKEN=<access-token-copied-above>
Enter fullscreen mode Exit fullscreen mode

Setup a NodeJS project.

% mkdir transcode
% cd transcode
% npm init
Enter fullscreen mode Exit fullscreen mode

Install the Javascript client SDK.

% npm install --save @osaas/client-core @osaas/client-services @osaas/client-transcode
Enter fullscreen mode Exit fullscreen mode

Create a file called transcode.js and open it in your favorite editor.

Add the following code in the file.

const { Context } = require('@osaas/client-core');

const ctx = new Context();
Enter fullscreen mode Exit fullscreen mode

You can now test running this script.

% node transcode.js
Enter fullscreen mode Exit fullscreen mode

Setup a storage for storing transcoded files

You can skip this step if you already have an S3 compatible storage that you want to use.

Install MinIO client library

% npm install --save minio
Enter fullscreen mode Exit fullscreen mode

Add a new function called setup() that takes the Context as argument.

const { Context, waitForInstanceReady } = require('@osaas/client-core');
const { getMinioMinioInstance, createMinioMinioInstance } = require('@osaas/client-services');
const Minio = require('minio');

const delay = (ms) => new Promise((res) => setTimeout(res, ms));

async function setup(context) {
  console.log('Setting up storage');

  // Check if we already have a storage service running
  let storage = await getMinioMinioInstance(context, 'devguide');
  if (!storage) {
    storage = await createMinioMinioInstance(context, {
      name: 'devguide',
      RootUser: 'admin',
      RootPassword: 'abC12345678'
    });
    await waitForInstanceReady('minio-minio', 'devguide', context);
    await delay(2000);
  }
  // Create a bucket on the storage service if it does not exists
  const client = new Minio.Client({
    endPoint: new URL(storage.url).hostname,
    accessKey: 'admin',
    secretKey: 'abC12345678',
  });
  const buckets = await client.listBuckets();
  if (!buckets.find((bucket) => bucket.name === 'output')) {
    await client.makeBucket('output');
  }
}

async function main() {
  const ctx = new Context();
  await setup(ctx);
}

main();
Enter fullscreen mode Exit fullscreen mode

When we now run the script again it will create a storage service and a bucket.

Setup video transcoder

Next step is to add to the setup function to create a video transcoder instance. If you already have an existing S3 bucket you replace the S3 credentials below with the access credentials to your bucket.

const { getEncoreInstance } = require('@osaas/client-services');
...

async function setup(context) {
  ...
  let transcoder = await getEncoreInstance(context, 'devguide');
  if (!transcoder) {
    transcoder = await createEncoreInstance(context, {
      name: 'devguide',
      s3AccessKeyId: 'admin',
      s3SecretAccessKey: 'abC12345678',
      s3Endpoint: storage.url
    });
  }
}
Enter fullscreen mode Exit fullscreen mode

Transcode a video file

The last step is to transcode a video file and here is a demo video you can use:

Add to the main function after setup the following code

const { transcode } = require('@osaas/client-transcode');
...
async function main() {
  const ctx = new Context();
  await setup(ctx);
  await transcode(ctx, {
    encoreInstanceName: 'devguide',
    inputUrl: new URL('https://testcontent.eyevinn.technology/mp4/VINN.mp4'),
    externalId: 'vinn',
    outputUrl: new URL('s3://output/')
  });
}
Enter fullscreen mode Exit fullscreen mode

And then we wait for the transcoding process to complete. To be notified of the progress of the transcoding process you can provide a webhook URL, for example:

await transcode(ctx, {
    encoreInstanceName: 'devguide',
    inputUrl: new URL('https://testcontent.eyevinn.technology/mp4/VINN.mp4'),
    externalId: 'vinn',
    outputUrl: new URL('s3://output/')
    callBackUrl: 'https://example.com/webhook'
  });
Enter fullscreen mode Exit fullscreen mode

We can verify that the transcoded files are available in the output bucket with an S3 client. For example:

% AWS_ACCESS_KEY_ID=admin AWS_SECRET_ACCESS_KEY=abC12345678 \
  aws --endpoint https://eyevinnlab-devguide.minio-minio.auto.prod.osaas.io \
  s3 ls s3://output/
2025-01-30 23:46:23     531182 vinn_12x20_160x90_thumbnail_map.jpg
2025-01-30 23:46:24    1755553 vinn_STEREO.mp4
2025-01-30 23:46:24      71512 vinn_thumb01.jpg
2025-01-30 23:46:23      45780 vinn_thumb02.jpg
2025-01-30 23:46:24      48038 vinn_thumb03.jpg
2025-01-30 23:46:25   18736955 vinn_x264_1312.mp4
2025-01-30 23:46:24   29213093 vinn_x264_2069.mp4
2025-01-30 23:46:25   42571864 vinn_x264_3100.mp4
2025-01-30 23:46:23    5627650 vinn_x264_324.mp4
2025-01-30 23:46:24   12033920 vinn_x264_806.mp4
Enter fullscreen mode Exit fullscreen mode

Top comments (0)