-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
205 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict'; | ||
|
||
var FFmpeg = require('@ffmpeg/ffmpeg'); | ||
var ffmpeg = require('@ffmpeg/ffmpeg'); | ||
var util = require('@ffmpeg/util'); | ||
|
||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
|
@@ -19,18 +20,6 @@ PERFORMANCE OF THIS SOFTWARE. | |
/* global Reflect, Promise */ | ||
|
||
|
||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
|
||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
|
@@ -884,7 +873,6 @@ var aesJs = {exports: {}}; | |
var aesJsExports = aesJs.exports; | ||
var aesjs = /*@__PURE__*/getDefaultExportFromCjs(aesJsExports); | ||
|
||
var createFFmpeg = FFmpeg.createFFmpeg, fetchFile = FFmpeg.fetchFile; | ||
var TaskType; | ||
(function (TaskType) { | ||
TaskType[TaskType["loadFFmeg"] = 0] = "loadFFmeg"; | ||
|
@@ -903,11 +891,11 @@ function parseUrl(url, path) { | |
} | ||
var Hls2Mp4 = /** @class */ (function () { | ||
function Hls2Mp4(_a, onProgress) { | ||
var _b = _a.maxRetry, maxRetry = _b === void 0 ? 3 : _b, _c = _a.tsDownloadConcurrency, tsDownloadConcurrency = _c === void 0 ? 10 : _c, options = __rest(_a, ["maxRetry", "tsDownloadConcurrency"]); | ||
var _b = _a.maxRetry, maxRetry = _b === void 0 ? 3 : _b, _c = _a.tsDownloadConcurrency, tsDownloadConcurrency = _c === void 0 ? 10 : _c; | ||
this.loadRetryTime = 0; | ||
this.totalSegments = 0; | ||
this.savedSegments = 0; | ||
this.instance = createFFmpeg(options); | ||
this.ffmpeg = new ffmpeg.FFmpeg(); | ||
this.maxRetry = maxRetry; | ||
this.onProgress = onProgress; | ||
this.tsDownloadConcurrency = tsDownloadConcurrency; | ||
|
@@ -952,7 +940,7 @@ var Hls2Mp4 = /** @class */ (function () { | |
case 1: | ||
playList = _a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 2: return [4 /*yield*/, fetchFile(url).then(function (data) { return aesjs.utils.utf8.fromBytes(data); })]; | ||
case 2: return [4 /*yield*/, util.fetchFile(url).then(function (data) { return aesjs.utils.utf8.fromBytes(data); })]; | ||
case 3: | ||
playList = _a.sent(); | ||
_a.label = 4; | ||
|
@@ -996,7 +984,7 @@ var Hls2Mp4 = /** @class */ (function () { | |
var _b, done, data, fileName; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4 /*yield*/, this.loopLoadFile(function () { return fetchFile(url); })]; | ||
case 0: return [4 /*yield*/, this.loopLoadFile(function () { return util.fetchFile(url); })]; | ||
case 1: | ||
_b = _c.sent(), done = _b.done, data = _b.data; | ||
if (done) { | ||
|
@@ -1023,7 +1011,7 @@ var Hls2Mp4 = /** @class */ (function () { | |
case 1: | ||
tsData = _c.sent(); | ||
buffer = key ? this.aesDecrypt(tsData, key, iv) : this.transformBuffer(tsData); | ||
this.instance.FS('writeFile', name, buffer); | ||
this.ffmpeg.writeFile(name, buffer); | ||
this.savedSegments += 1; | ||
(_b = this.onProgress) === null || _b === void 0 ? void 0 : _b.call(this, TaskType.downloadTs, this.savedSegments / this.totalSegments); | ||
return [2 /*return*/, { | ||
|
@@ -1163,7 +1151,7 @@ var Hls2Mp4 = /** @class */ (function () { | |
case 14: | ||
content = content.replace(keyTagMatchRegExp, ''); | ||
m3u8 = 'temp.m3u8'; | ||
this.instance.FS('writeFile', m3u8, content); | ||
this.ffmpeg.writeFile(m3u8, content); | ||
return [2 /*return*/, m3u8]; | ||
} | ||
}); | ||
|
@@ -1202,20 +1190,31 @@ var Hls2Mp4 = /** @class */ (function () { | |
Hls2Mp4.prototype.loadFFmpeg = function () { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var done; | ||
var _this = this; | ||
var baseUrl, coreURL, wasmURL, loaded; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
(_a = this.onProgress) === null || _a === void 0 ? void 0 : _a.call(this, TaskType.loadFFmeg, 0); | ||
return [4 /*yield*/, this.loopLoadFile(function () { return _this.instance.load(); })]; | ||
baseUrl = 'https://unpkg.com/@ffmpeg/[email protected]/dist/umd'; | ||
return [4 /*yield*/, util.toBlobURL("".concat(baseUrl, "/ffmpeg-core.js"), 'text/javascript')]; | ||
case 1: | ||
done = (_c.sent()).done; | ||
if (done) { | ||
(_b = this.onProgress) === null || _b === void 0 ? void 0 : _b.call(this, TaskType.loadFFmeg, done ? 1 : -1); | ||
coreURL = _c.sent(); | ||
return [4 /*yield*/, util.toBlobURL("".concat(baseUrl, "/ffmpeg-core.wasm"), 'application/wasm') | ||
// workerURL = workerURL ?? await toBlobURL(`${baseUrl}/ffmpeg-core.worker.js`, 'text/javascript') | ||
]; | ||
case 2: | ||
wasmURL = _c.sent(); | ||
return [4 /*yield*/, this.ffmpeg.load({ | ||
coreURL: coreURL, | ||
wasmURL: wasmURL | ||
})]; | ||
case 3: | ||
loaded = _c.sent(); | ||
if (loaded) { | ||
(_b = this.onProgress) === null || _b === void 0 ? void 0 : _b.call(this, TaskType.loadFFmeg, 1); | ||
} | ||
else { | ||
throw new Error('FFmpeg load failed'); | ||
return [2 /*return*/, this.loadFFmpeg()]; | ||
} | ||
return [2 /*return*/]; | ||
} | ||
|
@@ -1235,13 +1234,15 @@ var Hls2Mp4 = /** @class */ (function () { | |
case 2: | ||
m3u8 = _c.sent(); | ||
(_a = this.onProgress) === null || _a === void 0 ? void 0 : _a.call(this, TaskType.mergeTs, 0); | ||
return [4 /*yield*/, this.instance.run('-i', m3u8, '-c', 'copy', 'temp.mp4', '-loglevel', 'debug')]; | ||
return [4 /*yield*/, this.ffmpeg.exec(['-i', m3u8, '-c', 'copy', 'temp.mp4', '-loglevel', 'debug'])]; | ||
case 3: | ||
_c.sent(); | ||
data = this.instance.FS('readFile', 'temp.mp4'); | ||
this.instance.exit(); | ||
return [4 /*yield*/, this.ffmpeg.readFile('temp.mp4')]; | ||
case 4: | ||
data = _c.sent(); | ||
this.ffmpeg.terminate(); | ||
(_b = this.onProgress) === null || _b === void 0 ? void 0 : _b.call(this, TaskType.mergeTs, 1); | ||
return [2 /*return*/, data.buffer]; | ||
return [2 /*return*/, data]; | ||
} | ||
}); | ||
}); | ||
|
@@ -1254,7 +1255,7 @@ var Hls2Mp4 = /** @class */ (function () { | |
anchor.click(); | ||
setTimeout(function () { return URL.revokeObjectURL(objectUrl); }, 100); | ||
}; | ||
Hls2Mp4.version = '1.1.9'; | ||
Hls2Mp4.version = '1.2.0'; | ||
Hls2Mp4.TaskType = TaskType; | ||
return Hls2Mp4; | ||
}()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var Hls2Mp4 = (function (FFmpeg) { | ||
var Hls2Mp4 = (function (ffmpeg, util) { | ||
'use strict'; | ||
|
||
/****************************************************************************** | ||
|
@@ -18,18 +18,6 @@ var Hls2Mp4 = (function (FFmpeg) { | |
/* global Reflect, Promise */ | ||
|
||
|
||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
|
||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
|
@@ -883,7 +871,6 @@ var Hls2Mp4 = (function (FFmpeg) { | |
var aesJsExports = aesJs.exports; | ||
var aesjs = /*@__PURE__*/getDefaultExportFromCjs(aesJsExports); | ||
|
||
var createFFmpeg = FFmpeg.createFFmpeg, fetchFile = FFmpeg.fetchFile; | ||
var TaskType; | ||
(function (TaskType) { | ||
TaskType[TaskType["loadFFmeg"] = 0] = "loadFFmeg"; | ||
|
@@ -902,11 +889,11 @@ var Hls2Mp4 = (function (FFmpeg) { | |
} | ||
var Hls2Mp4 = /** @class */ (function () { | ||
function Hls2Mp4(_a, onProgress) { | ||
var _b = _a.maxRetry, maxRetry = _b === void 0 ? 3 : _b, _c = _a.tsDownloadConcurrency, tsDownloadConcurrency = _c === void 0 ? 10 : _c, options = __rest(_a, ["maxRetry", "tsDownloadConcurrency"]); | ||
var _b = _a.maxRetry, maxRetry = _b === void 0 ? 3 : _b, _c = _a.tsDownloadConcurrency, tsDownloadConcurrency = _c === void 0 ? 10 : _c; | ||
this.loadRetryTime = 0; | ||
this.totalSegments = 0; | ||
this.savedSegments = 0; | ||
this.instance = createFFmpeg(options); | ||
this.ffmpeg = new ffmpeg.FFmpeg(); | ||
this.maxRetry = maxRetry; | ||
this.onProgress = onProgress; | ||
this.tsDownloadConcurrency = tsDownloadConcurrency; | ||
|
@@ -951,7 +938,7 @@ var Hls2Mp4 = (function (FFmpeg) { | |
case 1: | ||
playList = _a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 2: return [4 /*yield*/, fetchFile(url).then(function (data) { return aesjs.utils.utf8.fromBytes(data); })]; | ||
case 2: return [4 /*yield*/, util.fetchFile(url).then(function (data) { return aesjs.utils.utf8.fromBytes(data); })]; | ||
case 3: | ||
playList = _a.sent(); | ||
_a.label = 4; | ||
|
@@ -995,7 +982,7 @@ var Hls2Mp4 = (function (FFmpeg) { | |
var _b, done, data, fileName; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4 /*yield*/, this.loopLoadFile(function () { return fetchFile(url); })]; | ||
case 0: return [4 /*yield*/, this.loopLoadFile(function () { return util.fetchFile(url); })]; | ||
case 1: | ||
_b = _c.sent(), done = _b.done, data = _b.data; | ||
if (done) { | ||
|
@@ -1022,7 +1009,7 @@ var Hls2Mp4 = (function (FFmpeg) { | |
case 1: | ||
tsData = _c.sent(); | ||
buffer = key ? this.aesDecrypt(tsData, key, iv) : this.transformBuffer(tsData); | ||
this.instance.FS('writeFile', name, buffer); | ||
this.ffmpeg.writeFile(name, buffer); | ||
this.savedSegments += 1; | ||
(_b = this.onProgress) === null || _b === void 0 ? void 0 : _b.call(this, TaskType.downloadTs, this.savedSegments / this.totalSegments); | ||
return [2 /*return*/, { | ||
|
@@ -1162,7 +1149,7 @@ var Hls2Mp4 = (function (FFmpeg) { | |
case 14: | ||
content = content.replace(keyTagMatchRegExp, ''); | ||
m3u8 = 'temp.m3u8'; | ||
this.instance.FS('writeFile', m3u8, content); | ||
this.ffmpeg.writeFile(m3u8, content); | ||
return [2 /*return*/, m3u8]; | ||
} | ||
}); | ||
|
@@ -1201,20 +1188,31 @@ var Hls2Mp4 = (function (FFmpeg) { | |
Hls2Mp4.prototype.loadFFmpeg = function () { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var done; | ||
var _this = this; | ||
var baseUrl, coreURL, wasmURL, loaded; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
(_a = this.onProgress) === null || _a === void 0 ? void 0 : _a.call(this, TaskType.loadFFmeg, 0); | ||
return [4 /*yield*/, this.loopLoadFile(function () { return _this.instance.load(); })]; | ||
baseUrl = 'https://unpkg.com/@ffmpeg/[email protected]/dist/umd'; | ||
return [4 /*yield*/, util.toBlobURL("".concat(baseUrl, "/ffmpeg-core.js"), 'text/javascript')]; | ||
case 1: | ||
done = (_c.sent()).done; | ||
if (done) { | ||
(_b = this.onProgress) === null || _b === void 0 ? void 0 : _b.call(this, TaskType.loadFFmeg, done ? 1 : -1); | ||
coreURL = _c.sent(); | ||
return [4 /*yield*/, util.toBlobURL("".concat(baseUrl, "/ffmpeg-core.wasm"), 'application/wasm') | ||
// workerURL = workerURL ?? await toBlobURL(`${baseUrl}/ffmpeg-core.worker.js`, 'text/javascript') | ||
]; | ||
case 2: | ||
wasmURL = _c.sent(); | ||
return [4 /*yield*/, this.ffmpeg.load({ | ||
coreURL: coreURL, | ||
wasmURL: wasmURL | ||
})]; | ||
case 3: | ||
loaded = _c.sent(); | ||
if (loaded) { | ||
(_b = this.onProgress) === null || _b === void 0 ? void 0 : _b.call(this, TaskType.loadFFmeg, 1); | ||
} | ||
else { | ||
throw new Error('FFmpeg load failed'); | ||
return [2 /*return*/, this.loadFFmpeg()]; | ||
} | ||
return [2 /*return*/]; | ||
} | ||
|
@@ -1234,13 +1232,15 @@ var Hls2Mp4 = (function (FFmpeg) { | |
case 2: | ||
m3u8 = _c.sent(); | ||
(_a = this.onProgress) === null || _a === void 0 ? void 0 : _a.call(this, TaskType.mergeTs, 0); | ||
return [4 /*yield*/, this.instance.run('-i', m3u8, '-c', 'copy', 'temp.mp4', '-loglevel', 'debug')]; | ||
return [4 /*yield*/, this.ffmpeg.exec(['-i', m3u8, '-c', 'copy', 'temp.mp4', '-loglevel', 'debug'])]; | ||
case 3: | ||
_c.sent(); | ||
data = this.instance.FS('readFile', 'temp.mp4'); | ||
this.instance.exit(); | ||
return [4 /*yield*/, this.ffmpeg.readFile('temp.mp4')]; | ||
case 4: | ||
data = _c.sent(); | ||
this.ffmpeg.terminate(); | ||
(_b = this.onProgress) === null || _b === void 0 ? void 0 : _b.call(this, TaskType.mergeTs, 1); | ||
return [2 /*return*/, data.buffer]; | ||
return [2 /*return*/, data]; | ||
} | ||
}); | ||
}); | ||
|
@@ -1253,11 +1253,11 @@ var Hls2Mp4 = (function (FFmpeg) { | |
anchor.click(); | ||
setTimeout(function () { return URL.revokeObjectURL(objectUrl); }, 100); | ||
}; | ||
Hls2Mp4.version = '1.1.9'; | ||
Hls2Mp4.version = '1.2.0'; | ||
Hls2Mp4.TaskType = TaskType; | ||
return Hls2Mp4; | ||
}()); | ||
|
||
return Hls2Mp4; | ||
|
||
})(FFmpeg); | ||
})(FFmpeg, util); |
Oops, something went wrong.