修复大文件无法下载的问题

This commit is contained in:
wenyifan 2022-12-11 23:50:40 +08:00
parent ffb367ae3e
commit 401a6c2286
2 changed files with 36 additions and 18 deletions

View File

@ -28,9 +28,12 @@ evanEnv.enableAutoDownload = true
## FFmpeg合并示例 ## FFmpeg合并示例
```shell ```shell
ffmpeg -i mediasource_0_0.mp4 -i mediasource_0_1.mp4 -c copy -bsf:a aac_adtstoasc out.mp4 ffmpeg -i mediasource_0_0_0.mp4 -i mediasource_0_1_0.mp4 -c copy -bsf:a aac_adtstoasc out.mp4
``` ```
## 大文件分段需要先文件合并
copy /b mediasource_0_0_*.mp4 out.mp4
## 常见问题 ## 常见问题
- 合并后声音播放不正常:由于部分网站使用了HE-AAC v2(AAC+SBR+PS)作为音频编码,大部分播放器还不支持此音频流格式,故声音不正常,使用Windows自带的视频播放器播放正常 - 合并后声音播放不正常:由于部分网站使用了HE-AAC v2(AAC+SBR+PS)作为音频编码,大部分播放器还不支持此音频流格式,故声音不正常,使用Windows自带的视频播放器播放正常

View File

@ -19,29 +19,44 @@ evanEnv.enableAutoDownload = true;
(function () { (function () {
evanEnv.videos = document.getElementsByTagName('video'); evanEnv.videos = document.getElementsByTagName('video');
evanEnv.buildArrayBuffer = function (bufferList) { evanEnv.downloadRawData = function (bufferList, fileName = 'out', ext = '.mp4') {
var buffList = new Array();
var totalLength = 0; var totalLength = 0;
for (var i = 0; i < bufferList.length; i++) { for (var i = 0; i < bufferList.length; i++) {
totalLength += bufferList[i].byteLength; totalLength += bufferList[i].byteLength;
if (totalLength > 1073741824 || i == bufferList.length - 1) {
buffList.push(new Uint8Array(totalLength));
totalLength = 0;
}
} }
var tmp = new Uint8Array(totalLength);
var lastLength = 0; var lastLength = 0;
var part = 0;
for (var ix = 0; ix < bufferList.length; ix++) { for (var ix = 0; ix < bufferList.length; ix++) {
tmp.set(new Uint8Array(bufferList[ix]), lastLength); //10485760
//1073741824
buffList[part].set(new Uint8Array(bufferList[ix]), lastLength);
lastLength += bufferList[ix].byteLength; lastLength += bufferList[ix].byteLength;
if (lastLength > 1073741824) {
part++;
lastLength = 0
}
} }
return tmp.buffer;
}; for (var iz = 0; iz < buffList.length; iz++) {
evanEnv.downloadRawData = function (bufferList, fileName = 'out.mp4') { var buff = buffList[iz];
var buff = evanEnv.buildArrayBuffer(bufferList); let url = window.URL.createObjectURL(new Blob([buff], { type: "arraybuffer" }))
let url = window.URL.createObjectURL(new Blob([buff], {type: "arraybuffer"})) const link = document.createElement('a');
const link = document.createElement('a'); link.style.display = 'none';
link.style.display = 'none'; link.href = url;
link.href = url; link.setAttribute('download', fileName + "_" + iz + ext);
link.setAttribute('download', fileName); document.body.appendChild(link);
document.body.appendChild(link); link.click();
link.click(); document.body.removeChild(link);
document.body.removeChild(link); }
}; };
evanEnv.download = function () { evanEnv.download = function () {
@ -49,7 +64,7 @@ evanEnv.enableAutoDownload = true;
var currentItem = evanEnv.mediaSources[i]; var currentItem = evanEnv.mediaSources[i];
if (currentItem.downloaded == undefined || currentItem.downloaded == false) { if (currentItem.downloaded == undefined || currentItem.downloaded == false) {
for (var x = 0; x < currentItem.rawSources.length; x++) { for (var x = 0; x < currentItem.rawSources.length; x++) {
evanEnv.downloadRawData(currentItem.rawSources[x], 'mediasource_' + i + '_' + x + '.mp4'); evanEnv.downloadRawData(currentItem.rawSources[x], 'mediasource_' + i + '_' + x);
} }
} }
currentItem.downloaded = true; currentItem.downloaded = true;
@ -57,7 +72,7 @@ evanEnv.enableAutoDownload = true;
}; };
evanEnv.downloadMediaSource = function (mediaSource) { evanEnv.downloadMediaSource = function (mediaSource) {
for (var x = 0; x < mediaSource.rawSources.length; x++) { for (var x = 0; x < mediaSource.rawSources.length; x++) {
evanEnv.downloadRawData(mediaSource.rawSources[x], 'mediasource_' + x + '.mp4'); evanEnv.downloadRawData(mediaSource.rawSources[x], 'mediasource_' + x);
mediaSource.downloaded = true; mediaSource.downloaded = true;
} }
}; };