From bbbfa0390c6e523f361a71d021420bfc30a170f5 Mon Sep 17 00:00:00 2001 From: Googol Lee Date: Tue, 26 Jan 2016 17:12:43 +0800 Subject: [PATCH 1/6] use saveas to generate playback hls --- example/app.js | 131 +++++++++++++++++++++++++------------------------ lib/api.js | 6 ++- lib/stream.js | 30 +++++------ 3 files changed, 83 insertions(+), 84 deletions(-) diff --git a/example/app.js b/example/app.js index 2ad2a7d..592198b 100644 --- a/example/app.js +++ b/example/app.js @@ -206,16 +206,16 @@ stream.update(options, function(err, stream) { * Disable a Stream */ stream.disable(function(err, stream) { - console.log(stream.disabled); - // true + console.log(stream.disabled); + // true }); /** * Enable a Stream */ stream.enable(function(err, stream) { - console.log(stream.disabled); - // false + console.log(stream.disabled); + // false }); /** @@ -229,12 +229,12 @@ stream.status(function(err, status) { // "addr": "222.73.202.226:2572", // "startFrom": "2015-09-10T05:58:10.289+08:00", // "status": "disconnected", - // "bytesPerSecond": 16870.200000000001, - // "framesPerSecond": { - // "audio": 42.200000000000003, - // "video": 42.200000000000003, - // "data": 0.066666666666666666 - // } + // "bytesPerSecond": 16870.200000000001, + // "framesPerSecond": { + // "audio": 42.200000000000003, + // "video": 42.200000000000003, + // "data": 0.066666666666666666 + // } // } } }); @@ -277,28 +277,28 @@ console.log(urls); * Get Stream segments */ var options = { - startTime : null, // optional, in second, unix timestamp - endTime : null, // optional, in second, unix timestamp - limit : null // optional + startTime : null, // optional, in second, unix timestamp + endTime : null, // optional, in second, unix timestamp + limit : null // optional }; - stream.segments(options, function(err, segments) { - if (!err) { - console.log(segments); - // Log stream segments - // [ - // { - // "start": 1440196065, - // "end": 1440196124 - // }, - // { - // "start": 1440198072, - // "end": 1440198092 - // }, - // ... - // ] - } - }); +stream.segments(options, function(err, segments) { + if (!err) { + console.log(segments); + // Log stream segments + // [ + // { + // "start": 1440196065, + // "end": 1440196124 + // }, + // { + // "start": 1440198072, + // "end": 1440198092 + // }, + // ... + // ] + } +}); /** * Generate HLS playback URL @@ -306,60 +306,61 @@ console.log(urls); var start = 1440196065; var end = 1440196105; -var urls = stream.hlsPlaybackUrls(start, end); -console.log(urls); -// { -// ORIGIN: 'http://scv02k.playback1.z1.pili.qiniucdn.com/coding/55d7fa0ee3ba5723280000cc.m3u8?start=1440196065&end=1440196105' -// } +var urls = stream.hlsPlaybackUrls(start, end, function(err, urls) { + console.log(urls); + // { + // ORIGIN: 'http://scv02k.playback1.z1.pili.qiniucdn.com/coding/55d7fa0ee3ba5723280000cc.m3u8?start=1440196065&end=1440196105' + // } +}); /** * Snapshot Stream */ var name = 'imageName.jpg'; // required -var format = 'jpg'; // required +var format = 'jpg'; // required var options = { - time : 1440196100, // optional, default as now, in second, unix timestamp - notifyUrl : null // optional + time : 1440196100, // optional, default as now, in second, unix timestamp + notifyUrl : null // optional }; stream.snapshot(name, format, options, function(err, responseData) { - console.log(responseData); - // Log responseData - // { - // "targetUrl": "http://scv02k.static1.z1.pili.qiniucdn.com/snapshots/z1.coding.55d7faf0e3ba5723280000cd/imageName.jpg", - // "persistentId": "z1.55d7a6e77823de5a49a8899a" - // } - // - // You can get saving state via Qiniu fop service using persistentId. - // API: `curl -D GET http://api.qiniu.com/status/get/prefop?id=` - // Doc reference: `http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html#pfop-status` + console.log(responseData); + // Log responseData + // { + // "targetUrl": "http://scv02k.static1.z1.pili.qiniucdn.com/snapshots/z1.coding.55d7faf0e3ba5723280000cd/imageName.jpg", + // "persistentId": "z1.55d7a6e77823de5a49a8899a" + // } + // + // You can get saving state via Qiniu fop service using persistentId. + // API: `curl -D GET http://api.qiniu.com/status/get/prefop?id=` + // Doc reference: `http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html#pfop-status` }); /** * Save Stream as a file */ -var name = 'videoName.mp4'; // required -var format = 'mp4'; // required -var start = 1440196065; // required, in second, unix timestamp -var end = 1440196105; // required, in second, unix timestamp +var name = 'videoName.mp4'; // required +var start = 1440196065; // required, in second, unix timestamp +var end = 1440196105; // required, in second, unix timestamp var options = { - notifyUrl : null // optional + notifyUrl : null, // optional + format : 'mp4' // optional }; -stream.saveAs(name, format, start, end, options, function(err, responseData) { - // Log responseData - // { - // "url": "http://scv02k.media1.z1.pili.qiniucdn.com/recordings/z1.coding.55d7faf0e3ba5723280000cd/videoName.m3u8", - // "targetUrl": "http://scv02k.vod1.z1.pili.qiniucdn.com/recordings/z1.coding.55d7faf0e3ba5723280000cd/videoName.mp4", - // "persistentId": "z1.55d7a6e77823de5a49a8899b" - // } - // - // You can get saving state via Qiniu fop service using persistentId. - // API: `curl -D GET http://api.qiniu.com/status/get/prefop?id=` - // Doc reference: `http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html#pfop-status` - console.log(responseData); +stream.saveAs(name, start, end, options, function(err, responseData) { + // Log responseData + // { + // "url": "http://scv02k.media1.z1.pili.qiniucdn.com/recordings/z1.coding.55d7faf0e3ba5723280000cd/videoName.m3u8", + // "targetUrl": "http://scv02k.vod1.z1.pili.qiniucdn.com/recordings/z1.coding.55d7faf0e3ba5723280000cd/videoName.mp4", + // "persistentId": "z1.55d7a6e77823de5a49a8899b" + // } + // + // You can get saving state via Qiniu fop service using persistentId. + // API: `curl -D GET http://api.qiniu.com/status/get/prefop?id=` + // Doc reference: `http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html#pfop-status` + console.log(responseData); }); /** diff --git a/lib/api.js b/lib/api.js index b6d4d55..9da86b8 100644 --- a/lib/api.js +++ b/lib/api.js @@ -154,19 +154,21 @@ exports.deleteStream = function(credentials, streamId, fn) { }); }; -exports.saveStreamAs = function(credentials, streamId, name, format, start, end, options, fn) { +exports.saveStreamAs = function(credentials, streamId, name, start, end, options, fn) { var path = '/streams/' + streamId + '/saveas'; var data = {}; data['name'] = name; data['start'] = start; data['end'] = end; - data['format'] = format; if (options) { if (options.notifyUrl) { data['notifyUrl'] = options.notifyUrl; } + if (options.format) { + data['format'] = options.format; + } } API.request.post(credentials, path, data, function(err, responseData) { diff --git a/lib/stream.js b/lib/stream.js index c362ce6..a667d63 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -85,8 +85,8 @@ Stream.prototype.toJSONString = function() { return JSON.stringify(this, replacer); } -Stream.prototype.saveAs = function(name, format, start, end, options, fn) { - API.saveStreamAs(this.credentials, this.id, name, format, start, end, options, fn); +Stream.prototype.saveAs = function(name, start, end, options, fn) { + API.saveStreamAs(this.credentials, this.id, name, start, end, options, fn); } /** @@ -123,21 +123,17 @@ Stream.prototype.hlsLiveUrls = function() { return result; }; -Stream.prototype.hlsPlaybackUrls = function(startTime, endTime) { - var result = {}; - var hlsPlayHost = this.hosts.playback.hls; - var url = fmt.format('http://%s/%s/%s.m3u8?start=%d&end=%d', hlsPlayHost, - this.hub, this.title, startTime, endTime); - result[ORIGIN] = url; - - if (this.profiles) { - this.profiles.forEach(function(profile) { - var profileUrl = fmt.format('http://%s/%s/%s@%s.m3u8?start=%d&end=%d', hlsPlayHost, this.hub, this.title, profile, startTime, endTime); - result[profile] = profileUrl; - }); - } - - return result; +Stream.prototype.hlsPlaybackUrls = function(startTime, endTime, fn) { + name = fmt.format("%d", Date.now() / 1000); + this.saveAs(name, startTime, endTime, nil, function(err, resp) { + if (err) { + fn(err, null); + } else { + var result = {}; + result[ORIGIN] = resp.url; + fn(nil, result); + } + }) }; Stream.prototype.rtmpPublishUrl = function() { From 4a19efb9108e660e5f123d0b4b23cba92d87d0e1 Mon Sep 17 00:00:00 2001 From: Googol Lee Date: Tue, 26 Jan 2016 22:25:32 +0800 Subject: [PATCH 2/6] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5ab4ff1..870a26f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pili", - "version": "v1.5.2", + "version": "v1.5.3", "description": "Pili Streaming Cloud server-side library for NodeJS", "main": "index.js", "repository": { From fe496d299254523ece31057b93b9186df703e5e3 Mon Sep 17 00:00:00 2001 From: Googol Lee Date: Tue, 26 Jan 2016 23:56:10 +0800 Subject: [PATCH 3/6] fix bugs --- lib/stream.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/stream.js b/lib/stream.js index a667d63..b4e611d 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -124,14 +124,14 @@ Stream.prototype.hlsLiveUrls = function() { }; Stream.prototype.hlsPlaybackUrls = function(startTime, endTime, fn) { - name = fmt.format("%d", Date.now() / 1000); - this.saveAs(name, startTime, endTime, nil, function(err, resp) { + var name = fmt.format("%d", Date.now() / 1000); + this.saveAs(name, startTime, endTime, null, function(err, resp) { if (err) { fn(err, null); } else { var result = {}; result[ORIGIN] = resp.url; - fn(nil, result); + fn(null, result); } }) }; From 6fdc0aab51fb6855a353b609bd3027244a866fa7 Mon Sep 17 00:00:00 2001 From: Googol Lee Date: Wed, 27 Jan 2016 14:56:22 +0800 Subject: [PATCH 4/6] add back format --- example/app.js | 8 ++++---- lib/api.js | 8 ++++---- lib/stream.js | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/example/app.js b/example/app.js index 592198b..b702076 100644 --- a/example/app.js +++ b/example/app.js @@ -341,15 +341,15 @@ stream.snapshot(name, format, options, function(err, responseData) { * Save Stream as a file */ var name = 'videoName.mp4'; // required -var start = 1440196065; // required, in second, unix timestamp -var end = 1440196105; // required, in second, unix timestamp +var format = 'mp4'; // optional +var start = 1440196065; // required, in second, unix timestamp +var end = 1440196105; // required, in second, unix timestamp var options = { notifyUrl : null, // optional - format : 'mp4' // optional }; -stream.saveAs(name, start, end, options, function(err, responseData) { +stream.saveAs(name, format, start, end, options, function(err, responseData) { // Log responseData // { // "url": "http://scv02k.media1.z1.pili.qiniucdn.com/recordings/z1.coding.55d7faf0e3ba5723280000cd/videoName.m3u8", diff --git a/lib/api.js b/lib/api.js index 9da86b8..09f11e9 100644 --- a/lib/api.js +++ b/lib/api.js @@ -154,7 +154,7 @@ exports.deleteStream = function(credentials, streamId, fn) { }); }; -exports.saveStreamAs = function(credentials, streamId, name, start, end, options, fn) { +exports.saveStreamAs = function(credentials, streamId, name, format, start, end, options, fn) { var path = '/streams/' + streamId + '/saveas'; var data = {}; @@ -162,13 +162,13 @@ exports.saveStreamAs = function(credentials, streamId, name, start, end, options data['start'] = start; data['end'] = end; + if (format) { + data['format'] = format; + } if (options) { if (options.notifyUrl) { data['notifyUrl'] = options.notifyUrl; } - if (options.format) { - data['format'] = options.format; - } } API.request.post(credentials, path, data, function(err, responseData) { diff --git a/lib/stream.js b/lib/stream.js index b4e611d..e02a575 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -85,8 +85,8 @@ Stream.prototype.toJSONString = function() { return JSON.stringify(this, replacer); } -Stream.prototype.saveAs = function(name, start, end, options, fn) { - API.saveStreamAs(this.credentials, this.id, name, start, end, options, fn); +Stream.prototype.saveAs = function(name, format, start, end, options, fn) { + API.saveStreamAs(this.credentials, this.id, name, format, start, end, options, fn); } /** @@ -125,7 +125,7 @@ Stream.prototype.hlsLiveUrls = function() { Stream.prototype.hlsPlaybackUrls = function(startTime, endTime, fn) { var name = fmt.format("%d", Date.now() / 1000); - this.saveAs(name, startTime, endTime, null, function(err, resp) { + this.saveAs(name, null, startTime, endTime, null, function(err, resp) { if (err) { fn(err, null); } else { From 9795d18020b8a5baabd3db33c36fd75deff4482d Mon Sep 17 00:00:00 2001 From: Googol Lee Date: Wed, 27 Jan 2016 15:10:16 +0800 Subject: [PATCH 5/6] update history --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0d47aba..d34d410 100644 --- a/README.md +++ b/README.md @@ -446,6 +446,8 @@ hub.deleteStream(streamId, function(err, data) { ## History +- 1.5.3 + - Use saveAs in hlsPlaybackUrls - 1.5.2 - Update `Stream`'s `hosts` - Add `startFrom` in `Stream status` From 733de5edf3b0cefa3a038ae5a673b3787cf84aa4 Mon Sep 17 00:00:00 2001 From: Googol Lee Date: Thu, 28 Jan 2016 15:41:03 +0800 Subject: [PATCH 6/6] add changelog --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d34d410..d2fbb62 100644 --- a/README.md +++ b/README.md @@ -447,7 +447,7 @@ hub.deleteStream(streamId, function(err, data) { ## History - 1.5.3 - - Use saveAs in hlsPlaybackUrls + - Use saveAs in hlsPlaybackUrls, *need async function* - 1.5.2 - Update `Stream`'s `hosts` - Add `startFrom` in `Stream status`