Skip to content

Commit 3553367

Browse files
author
yiyixing
committed
视频混音注释细节添加
1 parent 119485d commit 3553367

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

video-mix/index.html

+38-37
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@
2424
<div class="container">
2525
<div class="resourceFile">
2626
<div>源文件:</div>
27-
<video
28-
src="*******************************"
29-
width="570"
30-
height="450"
31-
controls
32-
></video>
27+
<video id="resourceFile-id" width="570" height="450" controls></video>
3328
</div>
3429

3530
<div class="changeFile">
@@ -64,23 +59,28 @@
6459
// 上传音视频文件
6560
const config = {
6661
// 需要替换成您自己的存储桶信息
67-
Bucket: "******125********" /* 存储桶,必须 */,
68-
Region: "**-*********" /* 存储桶所在地域,必须字段 */,
69-
FileName: "demo1.mp4" /* 文件名 */,
70-
MixFileName: "demo2.mp4" /* 混音视频文件名 */,
62+
Bucket: "******125********", // 存储桶
63+
Region: "**-*********", // 存储桶所在地域
64+
FileName: "demo1.mp4", // 源文件
65+
MixFileName: "demo2.mp4", // 混音文件
66+
ResultName: "demo3.mp4", // 混音之后自定义文件名
7167
};
7268

69+
// 初始化原视频展示
70+
const resourceFile = document.querySelector("#resourceFile-id");
71+
resourceFile.src = config.FileName;
72+
73+
// 任务状态执行各阶段的文字展示
7374
const msgText = document.querySelector("#msg-text");
7475

75-
/**
76-
* 提交一个音视频转码任务。(使用转码模版参数方式)
77-
* AudioSource: 混音音频url
78-
* 1. 传入资源如果为存储桶文件,需先使用cos.getObjectUrl进行处理
79-
* 2. 支持网上资源url传入
80-
*/
76+
// 提交一个音视频转码任务
8177
async function postTranscode() {
8278
msgText.innerHTML = "开始...";
8379

80+
/**
81+
* 支持使用cos桶文件,如果文件为私有读,需要使用cos.getObjectUrl方法得到一个带有签名信息的url
82+
* 如果为其他在线资源,可忽略此步骤
83+
*/
8484
const AkUrl = await cos.getObjectUrl({
8585
Bucket: config.Bucket,
8686
Region: config.Region,
@@ -93,16 +93,16 @@
9393
const url = `https://${host}/${key}`;
9494
const body = COS.util.json2xml({
9595
Request: {
96-
// 创建任务的Tag:Transcode;是否必传:是
96+
// 创建任务的Tag
9797
Tag: "Transcode",
98-
// 待操作的文件信息;是否必传:是
98+
// 待操作的文件信息
9999
Input: {
100-
// 文件路径;是否必传:是
100+
// 源文件路径
101101
Object: config.FileName,
102102
},
103-
// 操作规则;是否必传:是
103+
// 操作规则
104104
Operation: {
105-
// 转码模板参数
105+
// 转码参数
106106
Transcode: {
107107
Container: {
108108
Format: "mp4",
@@ -113,41 +113,42 @@
113113
Audio: {
114114
Codec: "aac",
115115
},
116+
// 混音参数
116117
AudioMix: {
117-
AudioSource: AkUrl,
118-
Replace: true,
118+
AudioSource: AkUrl, // 混音文件路径
119+
Replace: true, // 是否保留被混音视频的源音频
119120
},
120121
},
121-
// 结果输出配置;是否必传:是
122+
// 结果输出配置
122123
Output: {
123-
// 存储桶的地域;是否必传:是
124+
// 存储桶的地域
124125
Region: config.Region,
125-
// 存储结果的存储桶;是否必传:是
126+
// 存储结果的存储桶
126127
Bucket: config.Bucket,
127-
// 输出结果的文件名;是否必传:是
128-
Object: "混音完成的视频.mp4",
128+
// 输出结果的文件名
129+
Object: config.ResultName,
129130
},
130131
},
131132
},
132133
});
133134

134135
const res = await cos.request({
135-
Method: "POST", // 固定值,必须
136-
Key: key, // 必须
137-
Url: url, // 请求的url,必须
138-
Body: body, // 请求体参数,必须
139-
ContentType: "application/xml", // 固定值,必须
136+
Method: "POST", // 固定值
137+
Key: key, // 固定值
138+
Url: url, // 请求的url
139+
Body: body, // 请求体参数
140+
ContentType: "application/xml", // 固定值
140141
});
141142

143+
// 定时查询音视频转码任务执行结果。https://cloud.tencent.com/document/product/460/84765
142144
if (res.statusCode === 200) {
143145
queryTranceTrack(res.Response.JobsDetail.JobId);
144146
}
145147
}
146148

147-
//定时查询音视频转码任务执行结果。https://cloud.tencent.com/document/product/460/84765
148149
function queryTranceTrack(jobId) {
149150
setTimeout(() => {
150-
const key = `jobs/${jobId}`; // jobId: 需要查询的jobId;
151+
const key = `jobs/${jobId}`; // 需要查询的jobId;
151152
const host = config.Bucket + ".ci." + config.Region + ".myqcloud.com";
152153
const url = `https://${host}/${key}`;
153154
cos.request(
@@ -156,8 +157,8 @@
156157
Region: config.Region,
157158
Method: "GET",
158159
Url: url,
159-
Key: key /** 固定值,必须 */,
160-
ContentType: "application/xml" /** 固定值,必须 */,
160+
Key: key,
161+
ContentType: "application/xml",
161162
},
162163
async (err, data) => {
163164
if (err) {

0 commit comments

Comments
 (0)