Convert GIF to MP4 and add to Video library
Hi,
My project involves converting a Gif to an MP4 and then adding this MP4 as an overlay into a longer MP4.
I can upload my Gif:
$default_upload_options = array('tags' => 'basic_sample');
$file_path = 'input.gif';
$files['unnamed_local'] = \Cloudinary\Uploader::upload($file_path, $default_upload_options);
$files['unnamed_local']['secure_url'] now has the URL:
https://res.cloudinary.com/redacted/image/upload/v1234567/[image_id].gif
so
https://res.cloudinary.com/redacted/image/upload/v1234567/[image_id].mp4
will be an MP4 file.
The next step is to add the video as an overlay to a longer video using this syntax:
But I can't used [image_id] because it's an image not a video.
Is there a way to upload a .gif and add it to the Videos & Audio section as an MP4? Or do I need to upload the .gif, get the returned URL and then upload the .mp4 separately.
Thanks,
Al
-
Hi @Al Petfield,
There are two options that we can do, however, option 1 would be the better approach:
- Convert the GIF to MP4 during upload by applying an incoming transformation.
- The videos can then be concatenated together by following the steps outlined here.
- If you wish to use an existing GIF, a time duration will need to be specified. Also, the height and width of the overlay needs to match the dimensions of the video. I have made an example here: https://res.cloudinary.com/demo/video/upload/w_300,h_200/w_300,h_200,l_kitten_fighting.gif,fl_splice,du_3/so_0,fl_layer_apply/dog.mp4.
- More details on how to do that can be found here.
Hope this helps, please let me know if you have any further questions.
- Convert the GIF to MP4 during upload by applying an incoming transformation.
-
Thanks, the way I achieved the GIF to MP4 transformation was to do this:
$image_path = 'path/to/image.gif';
$filename = 'filename';
$default_upload_options = array(
'format' => 'mp4',
'public_id' => $filename,
'resource_type' => 'video'
);
$files['unnamed_local'] = \Cloudinary\Uploader::upload($image_path, $default_upload_options);
Please sign in to leave a comment.
Comments
3 comments