When you upload a video to your Media Library account, it is recommended that you apply video eager transformation that will allow you to immediately access its optimized version once the asset has been uploaded. Performing the eager transformation for videos can be done either by defining the optimization parameters in an upload preset or as a parameter for the Upload API.
Uploading of videos together with eager transformation
-
Using eager transformation in an upload preset
You can create an upload present in your Media Library account and define the eager transformation in the Upload manipulation page - as shown in this demo:
-
Using eager transformation as a parameter for Upload API
When using SDK, you could do video optimizations using an eager transformation that can be requested for new videos in the Upload API call - https://cloudinary.com/documentation/eager_and_incoming_transformations#eager_transformations
As shown in the sample below, both the format and codec parameters are necessary to be included in the eager transformation parameters:
cloudinary.uploader.upload("sample_video.mp4",
resource_type: 'video',
overwrite: true,
eager = [
{ format: 'mp4', codec: 'h264', quality: 'auto', width: 1080, height: 1080, crop: 'scale' },
{ format: 'mp4', codec: 'h264', quality: 'auto', width: 1080, height: 1920, crop: 'scale' },
{ format: 'mp4', codec: 'h_265', quality: 'auto', width: 1080, height: 1080, crop: 'scale' },
{ format: 'mp4', codec: 'h_265', quality: 'auto', width: 1080, height: 1920, crop: 'scale' },
{ format: 'webm', codec: 'vc_vp9/mp4', quality: 'auto', width: 1080, height: 1080, crop: 'scale' },
{ format: 'webm', codec: 'vc_vp9/mp4', quality: 'auto', width: 1080, height: 1920, crop: 'scale' },
{ format: 'auto', quality: 'auto', width: 1080, height: 1080, crop: 'scale' },
{ format: 'auto', quality: 'auto', width: 1080, height: 1920, crop: 'scale' },
],
eager_async = True,
eager_notification_url = "https://your_webhook_site",
notification_url = "https://your_webhook_site"
)
In using the eager transformations, this means that the transformation of assets will be done during the upload call so that those transformations will already be available for delivery before your users access them for the first time. Note that the generated transformations, together with the unmodified original image source, will be saved into your account. This approach is useful, especially with transformations requiring some time to be performed before delivering it to the client browsers.
Uploading of videos together with eager transformation
Concerning the videos that are already uploaded to your account, you could use the Explicit API method to perform the eager transformation:
https://cloudinary.com/documentation/image_upload_api_reference#explicit_method
Once the video is transformed eagerly/asynchronously it will be available via the URL as normal. You may refer to the following link for some example implementations:
cloudinary.uploader.explicit("sample_video",
type = "upload",
resource_type = "video",
eager = [
{ format: 'mp4', codec: 'h264', quality: 'auto', width: 1080, height: 1080 },
{ format: 'mp4', codec: 'h264', quality: 'auto', width: 1080, height: 1920 },
{ format: 'mp4', codec: 'h_265', quality: 'auto', width: 1080, height: 1080 },
{ format: 'mp4', codec: 'h_265', quality: 'auto', width: 1080, height: 1920 },
{ format: 'webm', codec: 'vc_vp9/mp4', quality: 'auto', width: 1080, height: 1080 },
{ format: 'webm', codec: 'vc_vp9/mp4', quality: 'auto', width: 1080, height: 1920 },
{ format: 'auto', quality: 'auto', width: 1080, height: 1080 },
{ format: 'auto', quality: 'auto', width: 1080, height: 1920 },
]
)
Comments
0 comments
Please sign in to leave a comment.