Last updated: Oct-30-2024
Overview
After uploading videos to Cloudinary, they can be transformed in many ways.
The syntax for transforming and streaming videos is generally the same as 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 Python video streaming and transformation. For complete details on all video transformation functionality, see Video transformations and the Transformation URL API Reference.
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:
- Transcode videos from one format to another
- Apply video effects such as fade-in/out, accelerating or decelerating, adjusting volume, playing in reverse
- Play video-in-video, trim videos, or concatenate multiple videos
- Set video and audio quality options such as bitrate, video codec, audio sampling frequency, or audio codec
- Adjust the visual tone of your video with 3D LUTs
- Generate thumbnails or animated images from video
- Deliver your video using adaptive bitrate streaming in HLS or MPEG-DASH
You can optionally specify all of the above transformations to videos using methods that generate image tags or via direct URL-building directives.
Video tag helper method
You can optionally specify all of the above transformations with the video
method of the CloudinaryVideo
class, which automatically generates an HTML5 video tag including the transformation URL sources for the main formats supported by web browsers (webm
, mp4
and ogv
), as well as a poster thumbnail image. 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.
For example:
CloudinaryVideo
method to use the simplified syntax as shown in many examples within in this guide. If you import only cloudinary
without CloudinaryVideo
, you can still access this class with cloudinary.CloudinaryVideo
.The above statement results in the following HTML:
You can also add other, non-transformation parameters to the video
method 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.
Direct URL builder
The video
method described above generates an HTML5 video tag. In certain conditions, you might want to generate a transformation URL directly, without the containing video tag. To return only the URL, either use the build_url
method of the CloudinaryVideo
class, or using a standard Python command - cloudinary.utils.cloudinary_url
.
Here's an example:
Video transformation examples
Here are some examples of using Python to apply some of the video transformation features mentioned in the previous section using the video tag helper method.
Example 1:
The following example resizes the video to 30% of it's original size and rounds the corners by 20 pixels. 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 video.
Example 2:
The following example adjusts the brightness of the 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 plays forward again, but in slow motion.
Example 3:
The following example generates a <video>
tag for 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.
Example 4:
The following example uses direct URL building. It delivers the 2 seconds of a video between seconds 1 and 3 and loops 3 times. The video is resized to a fraction of its width.
Example 5:
The following example uses direct URL building. It delivers the 2.5 seconds of a video between seconds 7.5 and 10 with a light blue border, and then appends a boomeranged (reversed) version of that same clip, resizing the video to a fraction of its original size. An overlay is applied to the top right corner (north_east
) of the video with a height 25 pixels and opacity of 90.