Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
38d2e604
Commit
38d2e604
authored
Oct 27, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改获取视频信息音视频顺序不确定时产生的错误
七牛CDN地址确定
parent
ed9c662a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
53 deletions
+83
-53
index.php
src/backend/views/course/index.php
+2
-2
QiniuTranscode.php
src/common/libs/QiniuTranscode.php
+77
-47
main-local.php
src/environments/dev/common/config/main-local.php
+2
-2
main-local.php
src/environments/prod/common/config/main-local.php
+2
-2
No files found.
src/backend/views/course/index.php
View file @
38d2e604
...
@@ -52,8 +52,8 @@ $qiniu = \Yii::$app->qiniu;
...
@@ -52,8 +52,8 @@ $qiniu = \Yii::$app->qiniu;
<th>
时长/秒
</th>
<th>
时长/秒
</th>
<th>
文件大小
</th>
<th>
文件大小
</th>
<th>
原始格式
</th>
<th>
原始格式
</th>
<th>
价格/
分钟
</th>
<th>
价格/
元
</th>
<th>
免费试看/
秒
</th>
<th>
免费试看/
分钟
</th>
<th>
ACTION
</th>
<th>
ACTION
</th>
</tr>
</tr>
</thead>
</thead>
...
...
src/common/libs/QiniuTranscode.php
View file @
38d2e604
...
@@ -36,18 +36,9 @@ class QiniuTranscode
...
@@ -36,18 +36,9 @@ class QiniuTranscode
$auth
=
$qiniu
->
getAuthInstance
();
$auth
=
$qiniu
->
getAuthInstance
();
//获取视频元信息,对比与目标格式的区别
//获取视频元信息,对比与目标格式的区别
$baseUrl
=
$qiniu
->
getStorageConfig
(
'video'
,
'url'
)
.
$sourceKey
;
$avInfo
=
self
::
getAvInfo
(
$sourceKey
);
$avUrl
=
$auth
->
privateDownloadUrl
(
$baseUrl
.
'?avinfo'
);
$response
=
\Qiniu\Http\Client
::
get
(
$avUrl
);
$avInfo
=
$response
->
json
();
if
(
!
$avInfo
)
{
if
(
!
$avInfo
)
{
self
::
$lastError
=
'获取视频文件信息失败'
;
}
if
(
isset
(
$avInfo
[
'error'
]))
{
self
::
$lastError
=
$avInfo
[
'error'
];
return
false
;
return
false
;
}
}
...
@@ -97,20 +88,11 @@ class QiniuTranscode
...
@@ -97,20 +88,11 @@ class QiniuTranscode
$qiniu
=
\Yii
::
$app
->
qiniu
;
$qiniu
=
\Yii
::
$app
->
qiniu
;
$auth
=
$qiniu
->
getAuthInstance
();
$auth
=
$qiniu
->
getAuthInstance
();
$bucket
=
$qiniu
->
getStorageConfig
(
'video'
,
'bucket'
);
$bucket
=
$qiniu
->
getStorageConfig
(
'video'
,
'bucket'
);
//获取视频元信息,对比与目标格式的区别
//获取视频元信息,对比与目标格式的区别
$baseUrl
=
$qiniu
->
getStorageConfig
(
'video'
,
'url'
)
.
$standKey
;
$avInfo
=
self
::
getAvInfo
(
$standKey
);
$avUrl
=
$auth
->
privateDownloadUrl
(
$baseUrl
.
'?avinfo'
);
$response
=
\Qiniu\Http\Client
::
get
(
$avUrl
);
$avInfo
=
$response
->
json
();
if
(
!
$avInfo
)
{
if
(
!
$avInfo
)
{
self
::
$lastError
=
'获取视频文件信息失败'
;
}
if
(
isset
(
$avInfo
[
'error'
]))
{
self
::
$lastError
=
$avInfo
[
'error'
];
return
false
;
return
false
;
}
}
...
@@ -154,40 +136,49 @@ class QiniuTranscode
...
@@ -154,40 +136,49 @@ class QiniuTranscode
'fps'
=>
30
//FPS
'fps'
=>
30
//FPS
];
];
list
(
$video
,
$audio
)
=
$avInfo
[
'streams'
];
$fopsMain
=
''
;
//必要参数,当必要参数具备时一定转换编码
$fopsMain
=
''
;
//必要参数,当必要参数具备时一定转换编码
$fopsAddon
=
'/ab/'
.
$target
[
'ab'
];
//非必要参数,只有必要参数具备,非必要参数才会作为附属添加进去
$fopsAddon
=
'/ab/'
.
$target
[
'ab'
];
//非必要参数,只有必要参数具备,非必要参数才会作为附属添加进去
//音频采样率对比
//视频信息
if
(
$audio
[
'sample_rate'
]
>
$target
[
'ar'
])
{
if
(
isset
(
$avInfo
[
'streams'
][
'video'
]))
{
$fopsAddon
.=
'/ar/'
.
$target
[
'ar'
];
$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'
)
{
if
(
$force
)
{
$fopsMain
.=
'/vcodec/'
.
$target
[
'vcodec'
];
$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
(
$audio
[
'sample_rate'
]
>
$target
[
'ar'
])
{
if
(
$fpsRate
[
'0'
]
>
$target
[
'fps'
])
{
$fopsAddon
.=
'/ar/'
.
$target
[
'ar'
];
$fopsMain
.=
'/r/'
.
$target
[
'fps'
];
}
}
//分辨率对比,以原比例限定在指定分辨率以内
if
(
$audio
[
'codec_name'
]
!=
'aac'
)
{
if
(
$force
)
{
$fopsMain
.=
'/acodec/'
.
$target
[
'acodec'
];
$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'
;
}
}
$fops
=
''
;
$fops
=
''
;
...
@@ -206,5 +197,44 @@ class QiniuTranscode
...
@@ -206,5 +197,44 @@ class QiniuTranscode
?
'http://t.pp.cc/tmp/qiniu_callback.php'
?
'http://t.pp.cc/tmp/qiniu_callback.php'
:
\Yii
::
$app
->
params
[
'baseUrl'
]
.
Url
::
to
([
'qiniu-callback/transcode'
]);
:
\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
src/environments/dev/common/config/main-local.php
View file @
38d2e604
...
@@ -44,13 +44,13 @@ return [
...
@@ -44,13 +44,13 @@ return [
'bucket'
=>
'pp-classroom'
,
'bucket'
=>
'pp-classroom'
,
'fsizeLimit'
=>
pow
(
1024
,
2
)
*
5
,
//5MB
'fsizeLimit'
=>
pow
(
1024
,
2
)
*
5
,
//5MB
'mimeLimit'
=>
'image/jpeg;image/png;image/gif'
,
'mimeLimit'
=>
'image/jpeg;image/png;image/gif'
,
'url'
=>
'http://de
v.qdn
.pp.cc/'
'url'
=>
'http://de
img.c
.pp.cc/'
],
],
'video'
=>
[
'video'
=>
[
'bucket'
=>
'pp-classroom-private'
,
'bucket'
=>
'pp-classroom-private'
,
'fsizeLimit'
=>
pow
(
1024
,
3
)
*
2
,
//2GB
'fsizeLimit'
=>
pow
(
1024
,
3
)
*
2
,
//2GB
'mimeLimit'
=>
'video/*;flv-application/octet-stream'
,
'mimeLimit'
=>
'video/*;flv-application/octet-stream'
,
'url'
=>
'http://
oe9d6dr84.bkt.clouddn.com
/'
'url'
=>
'http://
devdn.c.pp.cc
/'
]
]
]
]
]
]
...
...
src/environments/prod/common/config/main-local.php
View file @
38d2e604
...
@@ -44,13 +44,13 @@ return [
...
@@ -44,13 +44,13 @@ return [
'bucket'
=>
'yunya-public'
,
'bucket'
=>
'yunya-public'
,
'fsizeLimit'
=>
pow
(
1024
,
2
)
*
5
,
//5MB
'fsizeLimit'
=>
pow
(
1024
,
2
)
*
5
,
//5MB
'mimeLimit'
=>
'image/jpeg;image/png;image/gif'
,
'mimeLimit'
=>
'image/jpeg;image/png;image/gif'
,
'url'
=>
'http://
of805nn40.bkt.clouddn.com
/'
'url'
=>
'http://
img.c.pp.cc
/'
],
],
'video'
=>
[
'video'
=>
[
'bucket'
=>
'yunya-video'
,
'bucket'
=>
'yunya-video'
,
'fsizeLimit'
=>
pow
(
1024
,
3
)
*
2
,
//2GB
'fsizeLimit'
=>
pow
(
1024
,
3
)
*
2
,
//2GB
'mimeLimit'
=>
'video/*;flv-application/octet-stream'
,
'mimeLimit'
=>
'video/*;flv-application/octet-stream'
,
'url'
=>
'http://
of80drz7s.bkt.clouddn.com
/'
'url'
=>
'http://
vdn.c.pp.cc
/'
]
]
]
]
]
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment