Skip to content

Video Management Made Easy

Like it or not, visuals tell better stories than words. But using images and videos on a website presents challenges. This article is a follow-up to Website Image Performance Improvement, in which we discussed how to upload, store, manipulate, optimize and deliver images, efficiently and effectively. Now, let’s talk video.

Much like we talked in our previous article about the managing images on your website, you may also have a need to render video content. Trust me – simply throwing a <video> tag with an accurate source to the browser does not deliver user satisfaction. At a high level, you need to consider the website layout, video quality and delivery, as well as address challenges, such as:

Adjusting video quality based on network conditions. For example, users in developing countries may have a slower internet connection compared to users in developed countries:

  • Delivering content to mobile users
  • Transcoding for different browsers
  • Manipulating video, such as resizing, cropping and adding visual effects

All these requirements make video complex. You cannot just take care of videos in few hours. In fact, you may find it difficult to find answers to certain questions on video management. But, there is one swift solution – Cloudinary.

Cloudinary is an all-in-one media management solution. In this article, we are going to delve into using Cloudinary to easily upload, manipulate and deliver videos.

Let’s see how we can use Cloudinary in our Node application.

Using Cloudinary in your existing application is easy:

  • Create a free Cloudinary account. You will receive an API key and secret. Store the key and your cloud name somewhere safe and easily accessible.
  • Install the Cloudinary SDK in your existing project:
npm install --save cloudinary
  • Include and configure Cloudinary in your Node app using the credentials received after creating a new account:
var cloudinary = require('cloudinary');

cloudinary.config({ 
	cloud_name: '<CLOUD_NAME>', 
	api_key: '<API_KEY>', 
	api_secret: '<API_SECRET>' 
});
Code language: JavaScript (javascript)

The cloud_name is enough when making and opening API calls like delivering videos. The key and secret are needed for secure calls, such as video uploads.

All you need to start managing videos is to upload the best video quality you have. You can manipulate videos on-the-fly using Cloudinary’s comprehensive API and easy to use manipulation URLs. Therefore, there is no need to do that before uploading. Let’s see a simple code example from Node for making a video upload:

cloudinary.uploader.upload("MLB_Vid.mp4", 
        function(result) {console.log(result); }, 
        { resource_type: "video" });
Code language: JavaScript (javascript)

It’s the same API method for images, but this time you have to explicitly tell the uploader that the resource type is video by passing the following as the third argument for the upload method:

{ resource_type: "video" }
Code language: CSS (css)

After uploading videos, you need to determine how they should be delivered. You can use the SDK’s video API to achieve this:

cloudinary.video("MLB_Vid")
Code language: JavaScript (javascript)

Transformation is the act of adjusting the existing properties and quality of the videos to achieve the desired output.

Manual transformations can be complex and time-consuming. Mitigating these challenges is not easy, but that is where Cloudinary comes in.

Video transformations come in a variety of forms:

  • Quality Optimization
  • Resizing and Cropping
  • Transcoding
  • Content manipulation
  • Audio adjustment
  • and a lot more

You can transform videos at one of two different stages:

  • When uploading (known as Eager Transformation)
  • While delivering (known as Lazy Transformation)

Eager transformation is best when you do not need to manipulate video dynamically. You just need to manipulate once, store and deliver to users.

Let’s see an example of transforming videos while uploading:

cloudinary.uploader.upload("MLB_Vid.mp4", 
    function(result) {console.log(result); }, 
    { resource_type: "video", 
      eager: [
      { width: 300, height: 300,
        crop: "pad", audio_codec: "none" }, 
      { width: 160, height: 100,
        crop: "crop", gravity: "south",
        audio_codec: "none" } ]});

Code language: JavaScript (javascript)

The third argument, which is an object, is also used to specify the eager transformation using an eager property.

In lazy transformation, the reverse becomes the case. Rather than manipulating videos during upload, you can store the best quality available and manipulate them on delivery.

Therefore, you have the control to dynamically generate a transformed variation of a given video when you are about to embed it in the browser: Loading code examples

Let’s see five interesting techniques you can apply using video transformation:

You can adjust the size and width of your videos to fit the user’s screen, which will in turn reduce the amount of kilobytes that will need to be downloaded:

Loading code examples

You also can retain the aspect ratio by providing only the width and using the scale crop type:

Loading code examples

There are other scaling options that will help you gain full control over your videos’ dimensions.

It is possible to use a desired format or quality level that suites a given video delivery situation. The fact that you uploaded an .mp4 video does not mean you have to upload another .webm version of that video. Cloudinary uses a feature called transcoding that enables you upload a single video and deliver it dynamically in different formats:

Loading code examples

You also can adjust the quality of the video: Loading code examples

Find out more about format and quality control here

You can trim video content and discard the parts you don’t need by telling Cloudinary which part of the videos you want to keep:

If you would like to start at 6.5sec and end after at 10sec: Loading code examples

See more on video trimming here

Cloudinary lets you add a variety of cool effects to your videos during playtime. Effects like fade in and fade out, visual noise, blur, saturation and lots more.

Let’s see a simple example of using Cloudinary to apply fade in to a video at start and fade out at end: Loading code examples

The positive fade value controls fade in, while the negative fade value controls fade out.

It is possible to add text content to your video at a given play time. Let’s add a text, “Cool Video”, at the down-middle part of our video. The text should be displayed after 2 seconds and should be removed after 5 seconds:

Loading code examples

Cloudinary can deliver videos optimally using a smart technique know as Adaptive Bitrate Streaming. This is a video delivery technique that adjusts the quality of a video stream in real time according to detected bandwidth and CPU capacity. With adaptive bitrate streaming, videos start quicker, with fewer buffering interruptions, and is delivered at the best possible quality for the current device and network connection, to maximize user experience.

cloudinary.uploader.upload('MLB_Vid.mp4', 
        function(result) {console.log(result); }, 
        { resource_type: "video", 
        eager: [
            { streaming_profile: "full_hd", format: "m3u8" }],                                   
        eager_async: true,
        eager_notification_url: "http://mywebsite/upload_completed",
        public_id: "my_MLB"});
Code language: JavaScript (javascript)

An eager transformation is initiated during upload. This transformation is an array that takes a streaming profile configuration. The MLB_Vid.mp4 video is encoded into HLS format using a Full HD streaming profile.

You can learn more about this technique in the documentation

Eliminate stretching or shrinking videos when adapting them for different screen dimensions. Based on the resizing and cropping transformation feature we have seen, you can perform automatic resizing and cropping to fit the graphic design and layout on any device, at any resolution, using Cloudinary’s powerful URL-based transformations.

Now is the time to step back and reflect. Compare what you could afford to do with your videos manually and how long it would take, to what you can accomplish with Cloudinary in your arsenal. With Cloudinary, you’ll improve your productivity with its robust features and be able to cater to whatever media management needs you might have. Get started by signing up if you haven’t already!


Back to top

Featured Post