Vue.js video transformations

Overview

After uploading videos to Cloudinary, they can be transformed in many ways.

The syntax for transforming and delivering videos is generally similar to that for images, and you can apply the majority of available image transformations to video as well. For example, you can resize, crop, rotate, set video quality and format or use auto quality and/or auto format, add text or image overlays to your videos, and more.

There are also a number of special options you can use for transforming and delivering video content. For example, you can adjust their size, shape, speed, duration, quality, and appearance. There are also some features that are specific to audio.

This section introduces you to the basics of Vue.js video streaming and transformation. For complete details on all video transformation functionality, see Video transformations and the Video transformations reference.

See also: Vue.js image transformation

Video transformation functionality

In addition to transformation features that are equally relevant for images and video, such as resizing, cropping, rotating, adding text or image overlays, and setting video quality or format, there are a variety of special transformations you can use for video. For example, you can:

CldVideo component

You can deliver videos and specify video transformations using the cld-video (CldVideo) element, which automatically generates an HTML5 video tag including the URL sources for the main formats supported by web browsers (webm, mp4 and ogv), as well as a poster thumbnail image, which is automatically generated from a frame in the video. This enables the browser to automatically select and play the video format it supports. The video files are created dynamically when first accessed by your users.

As with cld-image, you can add transformation parameters as attributes of the CldVideo component itself, or as optional cld-transformation components that will be used as chained transformations (each transformation is applied to the result of the previous transformation).

For example:

Copy to clipboard
<cld-video cloud-name="my_cloud" public-id="watchme">
  <cld-transformation overlay="text:arial_60:watchme" gravity="north" y="20" />
</cld-video>

Will be rendered to:

Copy to clipboard
<video>
  <source src="https://res.cloudinary.com/my_cloud/video/upload/g_north,l_text:arial_60:watchme,y_20/watchme.webm" type="video/webm">
  <source src="https://res.cloudinary.com/my_cloud/video/upload/g_north,l_text:arial_60:watchme,y_20/watchme.mp4" type="video/mp4">
  <source src="https://res.cloudinary.com/my_cloud/video/upload/g_north,l_text:arial_60:watchme,y_20/watchme.ogv" type="video/ogg">
</video>

You can also add other, non-transformation parameters to the cld-video element such as the asset version, configuration parameters and HTML5 video tag attributes.

  • The version parameter is added to the delivery URL as explained in Asset versions.
  • Configuration parameters that you specify here override any that you have set globally.
  • HTML5 video tag attributes are added to the resulting <video> tag. The video is delivered from Cloudinary using the width and height in the transformation but is displayed at the dimensions specified in the tag.

For details, see the video tag documentation and the HTML5 Video Player blog post.

CldPoster component

An optional cld-poster (CldPoster) child element of the CldVideo element, that will specify an image resource to be provided as the poster attribute of the video element. As with cld-image, you can add transformation parameters as attributes of the CldPoster component itself, or as optional cld-transformation components that will be used as chained transformations (each transformation is applied to the result of the previous transformation).

For example:

Copy to clipboard
<cld-video cloud-name="my_cloud" public-id="dinosaur">
  <cld-poster public-id="small_dinosaur">
    <cld-transformation radius="20" />
  </cld-poster>
</cld-video>

Will be rendered to:

Copy to clipboard
<video poster="https://res.cloudinary.com/my_cloud/image/upload/r_20/small_dinosaur">
  <source src="https://res.cloudinary.com/my_cloud/video/upload/dinosaur.webm" type="video/webm">
  <source src="https://res.cloudinary.com/my_cloud/video/upload/dinosaur.mp4" type="video/mp4">
  <source src="https://res.cloudinary.com/my_cloud/video/upload/dinosaur.ogv" type="video/ogg">
</video>

Note
The CldVideo element also supports a poster attribute for directly adding the full path of the poster image URL, for example:
<cld-video cloud-name="my_cloud" public-id="dinosaur" poster="https://res.cloudinary.com/my_cloud/image/upload/small_dinosaur.jpg" />
</cld-video>

Referencing the HTML video element

If you would like to reference the underlying video HTML element created by the Video component, you can pass an ref parameter to the CldVideo element. This will then allow you to access the video elements attributes, and control the underlying video element using the native video element functions like play/pause/stop.

Copy to clipboard
<cld-video 
  cloud-name="demo" 
  public-id="sample"  
  ref="cldVideo"
</cld-video>

// to control the video element

const video = cldVideo.current; //get the video element
video.play();
video.pause();
console.log(video.currentSrc);

Video transformation examples

This section provides examples of using Vue.js code to apply some of the video transformation features mentioned in the previous section.

Example 1:

The following example resizes the dog video to 40% of its original size and rotates it by 20 degrees. It also adds a semi-transparent cloudinary logo in the bottom right corner, using a southeast gravity with adjusted x and y coordinates to reach the corner of the rotated video.

Copy to clipboard
<cld-video cloud-name="demo" public-id="dog" controls="true" >
  <cld-transformation width="0.4" angle="20" />
  <cld-transformation overlay="cloudinary_icon_white" width="60" opacity="50" gravity="south_east" y="15" x="60" />
</cld-video>

Example 2:

The following example adjusts the brightness of a skiing video, and sets its radius to max in order to give a telescope-like effect. It then appends a copy of the video in reverse, and the plays forward again, but in slow motion.

Copy to clipboard
<cld-video cloud-name="demo" public-id="ski_jump" controls="true" >
  <cld-transformation overlay="video:ski_jump" flags="splice" effect="reverse" />
  <cld-transformation overlay="video:ski_jump" flags="splice" effect="accelerate:-50" />
  <cld-transformation effect="brightness:10" radius="max" />
</cld-video>

Example 3:

The following example generates a video whose first 10 seconds will loop continuously in an HTML5 video player with default controls. The video is cropped to 360X480 using the pad cropping method, and it is generated at 70% quality to control file size, with a custom fallback message for browsers that don't support HTML5:

Copy to clipboard
<cld-video 
  public-id="dog" 
  fallbackContent="Your browser does not support HTML5 video tags." 
  controls="true" 
  loop="true" >
  <cld-transformation crop="pad" height="360" width="480" quality="70" duration="10" />
</cld-video>

The above statement will be rendered to:

Copy to clipboard
<video controls="controls" height="360" loop="loop" poster="https://res.cloudinary.com/demo/video/upload/c_pad,h_360,w_480,q_70,du_10/dog.jpg" width="480">
  <source src="https://res.cloudinary.com/demo/video/upload/c_pad,h_360,w_480,q_70,du_10/dog.webm" type="video/webm" />
  <source src="https://res.cloudinary.com/demo/video/upload/c_pad,h_360,w_480,q_70,du_10/dog.mp4" type="video/mp4" />
  <source src="https://res.cloudinary.com/demo/video/upload/c_pad,h_360,w_480,q_70,du_10/dog.ogv" type="video/ogg" />
  Your browser does not support HTML5 video tags.
</video>

✔️ Feedback sent!

Rate this page: