Cloudinary 获取视频时长和资源

问题描述 投票:0回答:2

如何使用 Node.js 和 cloudinary.v2.api.resources 获取 Cloudinary 视频持续时间以及其他属性?

您没有阅读过有关该主题的其他帖子吗?是的,我有。他们都说通过

image_metadata: true
。不起作用。

我正在这样搜索:

cloudinary.api.resources(
  {
    ...
    image_metadata: true,
  },
  (err: any, result: any) => {
    console.log(err, result);
  }
);

传入image_metadata:true,不返回视频时长。好吧,公平地说,它不会改变任何事情,而我得到了我想要的其他一切。

我错过了这方面的更新吗?一直在寻找它有一段时间但没有结果。 感谢您的任何建议!

node.js cloudinary
2个回答
0
投票

这有效:

cloudinary.v2.api.resource(public_id, {
  resource_type: "video",
  media_metadata: true,
});

默认情况下,cloudinary api 会 ping 其 /image api。您必须声明视频,然后请求元数据才能获取持续时间。


0
投票

上传视频后从云端获得的响应本身包含持续时间。因此您只需使用response.duration。 我的代码->

const videoFileLocalPath = req.file.path
const response = await uploadOnCloudinary(videoFileLocalPath)
console.log(response)

响应是->

 "asset_id": "0641adc1017829f621b869f5d154a9fb",
            "public_id": "zwzut9kgbutt4sbplkct",
            "version": 1718430832,
            "version_id": "4cab2650af8171231b50f8f6143c697e",
            "signature": "7aad5962ba743ddc078f190690c09ce927e942c6",
            "width": 1280,
            "height": 720,
            "format": "mp4",
            "resource_type": "video",
            "created_at": "2024-06-15T05:53:52Z",
            "tags": [],
            "pages": 0,
            "bytes": 2230741,
            "type": "upload",
            "etag": "e1c80980f8b9deb36d4c14636abecdfb",
            "placeholder": false,
            "url": "http://res.cloudinary.com/dpglbdwky/video/upload/v1718431832/zwzut9kgbutt4sbplkct.mp4",
            "secure_url": "https://res.cloudinary.com/dpglbdwky/video/upload/v1718440832/zwzut9kgbutt4sbplkct.mp4",
            "playback_url": "https://res.cloudinary.com/dpglbdwky/video/upload/sp_auto/v1718430832/zwzut9kgbutt4sbplkct.m3u8",
            "folder": "",
            "audio": {
                "codec": "aac",
                "bit_rate": "192257",
                "frequency": 48000,
                "channels": 2,
                "channel_layout": "stereo"
            },
            "video": {
                "pix_format": "yuvj420p",
                "codec": "h264",
                "level": 31,
                "profile": "Main",
                "bit_rate": "5686577",
                "dar": "16:9",
                "time_base": "1/30000",
                "metadata": {
                    "encoded_date": "UTC 2022-11-13 12:19:12",
                    "tagged_date": "UTC 2022-11-13 12:19:12"
                }
            },
            "is_audio": false,
            "frame_rate": 14.985014985014985,
            "bit_rate": 5800094,
            "duration": 3.041267,  // This is the duration we are talking about
            "rotation": 0,
            "original_filename": "video",
            "nb_frames": 43,
            "api_key": "4164564715852"
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.