Skip to main content

04.七牛云视频瘦身demo

tip

demo 参考视频转码文档 官方demo转码说明文档写出来的.

demo

VoxelDog.tsx

var qiniu = require("qiniu");
//要上传的空间
bucket = '1v1';
//需要填写你的 Access Key 和 Secret Key
var accessKey = 'qKJM7ruEYGhN6q3eoEUD3Ep6RfaPr-esV6Bxdzer';
var secretKey = 'iiBt1mGKOP5A8yYoaiWJ0MbKCoZVaUuAxsn-8KDf';

var date = new Date();;
var upload_file = date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate() + '/' +date.getHours() + '-' + date.getMinutes() + '-' + date.getSeconds() + '.mp4';

//转码是使用的队列名称。
var pipeline = '1v1queue'; //设定自己账号下的pipleline
//要进行转码的转码操作。
fops = "avthumb/mp4/s/640x360/vb/1.25m"
//可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当间。
saveas_key = qiniu.util.urlsafeBase64Encode(bucket+':'+upload_file);
fops = fops+'|saveas/'+saveas_key;;

var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
var options = {
scope: bucket,
}
var putPolicy = new qiniu.rs.PutPolicy(options);
putPolicy.persistentOps = fops;
putPolicy.persistentPipeline = pipeline;
var uploadToken = putPolicy.uploadToken(mac);

var config = new qiniu.conf.Config();
config.useCdnDomain = true;
var localFile = './test.mp4';
//config.zone = qiniu.zone.Zone_z0;

var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();

formUploader.putFile(uploadToken, upload_file, localFile, putExtra, function(respErr, respBody, respInfo) {
if (respErr) {
throw respErr;
}
if (respInfo.statusCode == 200) {
console.log(respBody);
} else {
console.log(respInfo.statusCode);
console.log(respBody);
}
});

package.json

{
"dependencies": {
"qiniu": "^7.2.2"
}
}