Commit 38d2e604 authored by 杨培's avatar 杨培

修改获取视频信息音视频顺序不确定时产生的错误

七牛CDN地址确定
parent ed9c662a
......@@ -52,8 +52,8 @@ $qiniu = \Yii::$app->qiniu;
<th>时长/秒</th>
<th>文件大小</th>
<th>原始格式</th>
<th>价格/分钟</th>
<th>免费试看/秒</th>
<th>价格/元</th>
<th>免费试看/分钟</th>
<th>ACTION</th>
</tr>
</thead>
......
......@@ -36,18 +36,9 @@ class QiniuTranscode
$auth = $qiniu->getAuthInstance();
//获取视频元信息,对比与目标格式的区别
$baseUrl = $qiniu->getStorageConfig('video', 'url').$sourceKey;
$avUrl = $auth->privateDownloadUrl($baseUrl.'?avinfo');
$response = \Qiniu\Http\Client::get($avUrl);
$avInfo = $response->json();
$avInfo = self::getAvInfo($sourceKey);
if (!$avInfo) {
self::$lastError = '获取视频文件信息失败';
}
if (isset($avInfo['error'])) {
self::$lastError = $avInfo['error'];
return false;
}
......@@ -97,20 +88,11 @@ class QiniuTranscode
$qiniu = \Yii::$app->qiniu;
$auth = $qiniu->getAuthInstance();
$bucket = $qiniu->getStorageConfig('video', 'bucket');
//获取视频元信息,对比与目标格式的区别
$baseUrl = $qiniu->getStorageConfig('video', 'url').$standKey;
$avUrl = $auth->privateDownloadUrl($baseUrl.'?avinfo');
$response = \Qiniu\Http\Client::get($avUrl);
$avInfo = $response->json();
$avInfo = self::getAvInfo($standKey);
if (!$avInfo) {
self::$lastError = '获取视频文件信息失败';
}
if (isset($avInfo['error'])) {
self::$lastError = $avInfo['error'];
return false;
}
......@@ -154,40 +136,49 @@ class QiniuTranscode
'fps' => 30 //FPS
];
list($video, $audio) = $avInfo['streams'];
$fopsMain = ''; //必要参数,当必要参数具备时一定转换编码
$fopsAddon = '/ab/'.$target['ab']; //非必要参数,只有必要参数具备,非必要参数才会作为附属添加进去
//音频采样率对比
if ($audio['sample_rate'] > $target['ar']) {
$fopsAddon .= '/ar/'.$target['ar'];
}
//视频信息
if (isset($avInfo['streams']['video'])) {
$video = $avInfo['streams']['video'];
//FPS 对比
//Todo: 目前FPS的测算方法都不是很正确,不管是 r_frame_rate 还是 avg_frame_rate 多种情况下结果不正确,还需要继续研究
$frate = explode('/', $video['avg_frame_rate']);
if ($frate[0] / $frate[1] > $target['fps']) {
$fopsMain .= '/r/'.$target['fps'];
}
//视频采样率对比,七牛文档指出如果给出的码率大于原码率,则会使用原码率转换,但某些视频仍然会出现码率变大,所以此处加上判断
$fopsAddon .= '/vb/'.($video['bit_rate'] > $target['vb'] ? $target['vb'] : $video['bit_rate']);
//视频采样率对比,七牛文档指出如果给出的码率大于原码率,则会使用原码率转换,但某些视频仍然会出现码率变大,所以此处加上判断
$fopsAddon .= '/vb/'.($video['bit_rate'] > $target['vb'] ? $target['vb'] : $video['bit_rate']);
//编码对比
if ($video['codec_name'] != 'h264') {
$fopsMain .= '/vcodec/' . $target['vcodec'];
}
//编码对比
if ($video['codec_name'] != 'h264') {
$fopsMain .= '/vcodec/' . $target['vcodec'];
//分辨率对比,以原比例限定在指定分辨率以内
if ($force) {
$fopsMain .= '/s/' . ($video['width'] > $target['width'] ? $target['width'] : $video['width'])
. 'x' . ($video['height'] > $target['height'] ? $target['height'] : $video['height']) . '/autoscale/1';
} elseif ($video['width'] > $target['width'] || $video['height'] > $target['height']) {
$fopsMain .= '/s/'.$target['width'].'x'.$target['height'].'/autoscale/1';
}
}
if ($audio['codec_name'] != 'aac') {
$fopsMain .= '/acodec/'.$target['acodec'];
}
//音频信息
if (isset($avInfo['streams']['audio'])) {
$audio = $avInfo['streams']['audio'];
//FPS 对比
$fpsRate = explode('/', $video['r_frame_rate']);
if ($fpsRate['0'] > $target['fps']) {
$fopsMain .= '/r/'.$target['fps'];
}
//音频采样率对比
if ($audio['sample_rate'] > $target['ar']) {
$fopsAddon .= '/ar/'.$target['ar'];
}
//分辨率对比,以原比例限定在指定分辨率以内
if ($force) {
$fopsMain .= '/s/' . ($video['width'] > $target['width'] ? $target['width'] : $video['width'])
. 'x' . ($video['height'] > $target['height'] ? $target['height'] : $video['height']) . '/autoscale/1';
} elseif ($video['width'] > $target['width'] || $video['height'] > $target['height']) {
$fopsMain .= '/s/'.$target['width'].'x'.$target['height'].'/autoscale/1';
if ($audio['codec_name'] != 'aac') {
$fopsMain .= '/acodec/'.$target['acodec'];
}
}
$fops = '';
......@@ -206,5 +197,44 @@ class QiniuTranscode
? 'http://t.pp.cc/tmp/qiniu_callback.php'
: \Yii::$app->params['baseUrl'].Url::to(['qiniu-callback/transcode']);
}
/**
* 获取流媒体文件信息
*
* 将其中的流按照类型重新命名索引
*
* @param string $key
* @return array|bool|mixed
*/
protected static function getAvInfo($key)
{
/* @var $qiniu \common\components\Qiniu */
$qiniu = \Yii::$app->qiniu;
$auth = $qiniu->getAuthInstance();
//获取视频元信息,对比与目标格式的区别
$baseUrl = $qiniu->getStorageConfig('video', 'url').$key;
$avUrl = $auth->privateDownloadUrl($baseUrl.'?avinfo');
$response = \Qiniu\Http\Client::get($avUrl);
$avInfo = $response->json();
if (!is_array($avInfo)) {
self::$lastError = '获取视频文件信息失败';
return false;
}
if (!empty($avInfo['error'])) {
self::$lastError = $avInfo['error'];
return false;
}
foreach ($avInfo['streams'] as $i => $row) {
$avInfo['streams'][$row['codec_type']] = $row;
unset($avInfo['streams'][$i]);
}
return $avInfo;
}
}
\ No newline at end of file
......@@ -44,13 +44,13 @@ return [
'bucket' => 'pp-classroom',
'fsizeLimit' => pow(1024, 2) * 5, //5MB
'mimeLimit' => 'image/jpeg;image/png;image/gif',
'url' => 'http://dev.qdn.pp.cc/'
'url' => 'http://deimg.c.pp.cc/'
],
'video' => [
'bucket' => 'pp-classroom-private',
'fsizeLimit' => pow(1024, 3) * 2, //2GB
'mimeLimit' => 'video/*;flv-application/octet-stream',
'url' => 'http://oe9d6dr84.bkt.clouddn.com/'
'url' => 'http://devdn.c.pp.cc/'
]
]
]
......
......@@ -44,13 +44,13 @@ return [
'bucket' => 'yunya-public',
'fsizeLimit' => pow(1024, 2) * 5, //5MB
'mimeLimit' => 'image/jpeg;image/png;image/gif',
'url' => 'http://of805nn40.bkt.clouddn.com/'
'url' => 'http://img.c.pp.cc/'
],
'video' => [
'bucket' => 'yunya-video',
'fsizeLimit' => pow(1024, 3) * 2, //2GB
'mimeLimit' => 'video/*;flv-application/octet-stream',
'url' => 'http://of80drz7s.bkt.clouddn.com/'
'url' => 'http://vdn.c.pp.cc/'
]
]
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment