Use the seven KN SDK to upload videos and do shard operations.
Step1 Generating Tokens
const qiniu = require("qiniu");var accessKey = proc.env.QINIU_ACCESS_KEY;var secretKey = proc.env.QINIU_SECRET_KEY;var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);var bucket = proc.env.QINIU_TEST_BUCKET; // 对象存储空间//带数据处理的凭证var origin_filename = "avthumb_test_target.mp4"; // 源文件名var save_as_filename = `${origin_filename}.m3n8`; // 分片后的文件名var saveMp4Entry = qiniu.util.urlsafeBase64Encode(`${bucket}:${save_as_filename}`);var avthumbMp4Fop = "avthumb/m3u8/noDomain/1/segtime/15/vb/440k|saveas/" + saveMp4Entry;var options = { scope: bucket, expires: 3600, // 凭证有效时间 persistentOps: avthumbMp4Fop, // 视频上传后触发预转持久化,切片处理 persistentPipeline: "video-pipe", // 多媒体处理队列 persistentNotifyUrl: "http://api.example.com/qiniu/pfop/notify", // 回调通知地址}var putPolicy = new qiniu.rs.PutPolicy(options);console.log(putPolicy.uploadToken(mac));
Generate vouchers with different effects to view the official sample Nodejs-sdk example.
The code above is a voucher for generating and slicing the video. Upload relevant documents to view the seven KN upload strategy.
A slice action is persistentOps
triggered by a parameter and initiates an asynchronous task,
Persistentops Detailed
The
persistentops
field is used to specify the storage space and resource names for pre-turn data processing commands and saving processing results.
A non-null value is specified for this field, and a Asynchronous data Processing Task is started when a file is successfully uploaded. The persistentid
field, which uniquely identifies this task.
when the persistentid
Magic variable is specified in returnbody
, the response received by the client Returnbody
will have Persistentid
, when returnbody
is not specified, the default is also returned Persistentid
.
- Use default storage space and resource name
* When only data processing commands are specified, the server chooses the bucket that uploads the file as the storage space for the data processing result, and Key is automatically generated by the seven-ox servers.
- use specified storage space and resource name
- use pipe break after data processing command
|
Stitching the saveas/<encodedentryuri>
directive instructs the seven KN server to save processing results using buckets and keys specified in the Encodedentryuri format. such as avthumb/flv|saveas/cwj1y2tlddpxa2v5 , is to save the uploaded video file transcoding flv
format as Qbucket:qkey
, where cwj1y2tlddpxa2v5
is the URL-safe Base64 encoding result of Qbucket:qkey
. The above method can act on multiple data processing commands simultaneously, with ;
Delimited, such as avthumb/mp4|saveas/cwj1y2tlddpxa2v5;avthumb/flv|saveas/cwj1y2tlddpxa2v5mg==
From the seven cows upload voucher
Data processing commands can be used to view official documents, such as video slicing interfaces.
Step2 Front through Balls
POST http://up.qiniu.com格式: form-data参数:key: 文件名,上文代码中的 `origin_filename`token: 上传tokenfile: 具体文件// 上传成功的响应体// 状态码 200{ "hash": "luVJbz9RtE3Ha7c9XaDerE6rPyvP", "key": "prTEDwvJY18YBD_720_p1.mp4", "persistentId": "z0.5b56c9b938b9f324a573edb4" // 可以使用persistentId,检测当前处理状态}youthcity链接:https://www.jianshu.com/p/f73b39ae02dc來源:简书简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
STEP3 Poll Get Results
GET api.qiniu.com/status/get/prefop?id=${persistentId}{ "code": 0, // 状态码0成功,1等待处理,2正在处理,3处理失败,4通知提交失败。 "desc": "The fop was completed successfully", "id": "z0.5b56c9b938b9f324a573edb4", "inputBucket": "ocean", "inputKey": "prTEDwvJY18YBD_720_p1.mp4", "items": [ { "cmd": "avthumb/m3u8/noDomain/1/segtime/15/vb/440k|saveas/b2NlYW46aGxzX3ByVEVEd3ZKWTE4WUJEXzcyMF9wMS5tM3U4", "code": 0, "desc": "The fop was completed successfully", "hash": "FraV6PX6Xp7mYYgAnY0sniTK-pPt", "key": "hls_prTEDwvJY18YBD_720_p1.m3u8", "returnOld": 0 } ], "pipeline": "1381326751.k12_video", "reqid": "FQIAAKAxpZfFOkQV"}youthcity链接:https://www.jianshu.com/p/f73b39ae02dc來源:简书简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
Resources
Seven cows upload voucher
Seven-ox upload strategy
Video Slicing interface
Seven Cattle upload Development (iii) use NODEJS to generate vouchers with data processing
NODEJS-SDK Example
Seven Cow video slicing scheme