简介
本文档提供用于获取媒体文件的信息的代码示例。注意 需要 COS PHP SDK v2.3.2 及以上版本。旧版本可能存在 bug,使用时建议升级到 最新版本。
API | 操作名 | 操作描述 |
GetMediaInfo | 查询文件信息 | 用于查询媒体文件的信息 |
查询文件信息
功能说明
用于查询媒体文件的信息。注意 使用此接口前,请确保已打开官网控制台中数据处理下的媒体处理开关,否则会报错media bucket unbinded, bucket's host is unavailable
。
使用示例
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket$cosClient = new Qcloud\Cos\Client( array( 'region' => $region, 'scheme' => 'https', //协议头部,默认为http 'credentials'=> array( 'secretId' => $secretId , 'secretKey' => $secretKey)));
try { $result = $cosClient->GetMediaInfo( array( 'Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket 'Key' => 'exampleobject', //媒体文件对象路径,如folder/movie.mp4 'ci-process' => 'videoinfo' //操作类型,固定使用 videoinfo ) ); // 请求成功 echo($result);} catch (\Exception $e) { // 请求失败 echo($e);}
参数说明
参数名 | 参数描述 | 类型 | 是否必填 |
Bucket | 存储桶的名称,命名规则为 BucketName-APPID,此处填写的存储桶名称必须为此格式 | String | 是 |
Key | 对象键(Object 的名称),这里的形式为媒体文件。对象在存储桶中的唯一标识,详情请参见 对象概述 | String | 是 |
ci-process | 操作类型,固定使用 videoinfo | String | 是 |
返回结果示例
GuzzleHttp\Command\Result Object( [RequestId] => NjE0NTkxMWNfYTkyZTJjMGJfNTgyZF84ZDY2NWY= [ContentType] => application/xml [ContentLength] => 1787 [MediaInfo] => Array ( [Stream] => Array ( [Audio] => Array ( [Bitrate] => 383.727000 [Channel] => 6 [ChannelLayout] => 5.1 [CodecLongName] => AAC (Advanced Audio Coding) [CodecName] => aac [CodecTag] => 0x6134706d [CodecTagString] => mp4a [CodecTimeBase] => 1/48000 [Duration] => 62.314667 [Index] => 1 [Language] => und [SampleFmt] => fltp [SampleRate] => 48000 [StartTime] => 0.000000 [Timebase] => 1/48000 )
[Subtitle] => Array ( )
[Video] => Array ( [CodecTagString] => avc1 [Rotation] => 0.000000 [Index] => 0 [CodecName] => h264 [CodecLongName] => H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [CodecTimeBase] => 1/12800 [CodecTag] => 0x31637661 [Profile] => Main [Height] => 720 [Width] => 1280 [HasBFrame] => 0 [RefFrames] => 1 [Sar] => 1:1 [Dar] => 16:9 [PixFormat] => yuv420p [Level] => 31 [Fps] => 25.500000 [AvgFps] => 25/1 [Timebase] => 1/12800 [StartTime] => 0.000000 [Duration] => 62.280000 [Bitrate] => 959.963000 [NumFrames] => 1557 [Language] => und )
)
[Format] => Array ( [NumStream] => 2 [NumProgram] => 0 [FormatName] => mov,mp4,m4a,3gp,3g2,mj2 [FormatLongName] => QuickTime / MOV [StartTime] => 0.000000 [Duration] => 62.315000 [Bitrate] => 1347.820000 [Size] => 10498677 )
)
[Key] => exampleobject [Bucket] => examplebucket-1250000000 [Location] => examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/exampleobject)
对象存储官网1折活动,限时活动,即将结束,速速收藏
同尘科技为腾讯云授权服务中心。
购买腾讯云产品享受折上折,更有现金返利。同意关联立享优惠
转转请注明出处:https://www.yunxiaoer.com/145947.html