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
11252da2
Commit
11252da2
authored
Oct 27, 2016
by
xiabin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
18d6b038
2725a3a7
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 @
11252da2
...
...
@@ -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>
...
...
src/common/libs/QiniuTranscode.php
View file @
11252da2
...
...
@@ -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
src/environments/dev/common/config/main-local.php
View file @
11252da2
...
...
@@ -44,13 +44,13 @@ return [
'bucket'
=>
'pp-classroom'
,
'fsizeLimit'
=>
pow
(
1024
,
2
)
*
5
,
//5MB
'mimeLimit'
=>
'image/jpeg;image/png;image/gif'
,
'url'
=>
'http://de
v.qdn
.pp.cc/'
'url'
=>
'http://de
img.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
/'
]
]
]
...
...
src/environments/prod/common/config/main-local.php
View file @
11252da2
...
...
@@ -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
/'
]
]
]
...
...
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