Home > front end >  How to get video duration from Cloudinary with curl fetch?
How to get video duration from Cloudinary with curl fetch?

Time:10-20

I want to get the video duration from Cloudinary. I found this question but I can't find any way to do it in curl. I think i should use explicit method but I tried and I got page not found error.

CodePudding user response:

I'm Danny and I work on Cloudinary's Customer Success team.

Rather than using the explicit method of the Upload API, you simply need need to get the resource(s) from the Admin API, explained here: https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_resource

You need to make a GET request to /resources(/:resource_type)(/:type)/public_id. The video duration isn't returned by default, so you'll need to specify ?image_metadata=true in the GET request in order to return it.

So for instance, to return the duration of our sample dog video, I would do a GET on this URL, replacing the API key and secret as required: https://API_KEY:[email protected]/v1_1/demo/resources/video/upload/dog?image_metadata=true

This would return the following JSON, which includes video_duration:

{
    "asset_id": "c07b6c11dfbc9b8849eacbd4c20da607",
    "public_id": "dog",
    "format": "mp4",
    "version": 1426536413,
    "resource_type": "video",
    "type": "upload",
    "created_at": "2015-03-16T20:06:53Z",
    "bytes": 9094354,
    "width": 854,
    "height": 480,
    "backup": true,
    "access_mode": "public",
    "url": "http://res.cloudinary.com/demo/video/upload/v1426536413/dog.mp4",
    "secure_url": "https://res.cloudinary.com/demo/video/upload/v1426536413/dog.mp4",
    [...]
    "video_duration": 13.4134,
    "audio_duration": 13.413396,
    "audio_start_time": 0.0,
    "video_start_time": 0.0,
    [...]
}

I hope this helps. If you have any followup questions, you're welcome to post them here, or raise a ticket with us via our Support Portal.

  • Related