This commit is contained in:
wenyifan 2023-01-28 17:50:46 +08:00
parent 881037a195
commit 8472b29247
2 changed files with 28 additions and 35 deletions

View File

@ -21,15 +21,18 @@
## 参数
```javascript
//自动快进
evanEnv.enableAutoForward = true
//快进抓取
jsMedia.setSpeed(10);
//完成后自动下载
evanEnv.enableAutoDownload = true
jsMedia.enableAutoDownload = true;
//手工触发下载
jsMedia.download();
```
## FFmpeg合并示例
```shell
ffmpeg -i mediasource_0_0_0.mp4 -i mediasource_0_1_0.mp4 -c copy -bsf:a aac_adtstoasc out.mp4
ffmpeg -i audio.mp4 -acodec copy audio.aac
ffmpeg -i audio.aac -i video.mp4 -c copy -bsf:a aac_adtstoasc out.mp4
```
## 大文件分段需要先文件合并
@ -37,9 +40,5 @@ ffmpeg -i mediasource_0_0_0.mp4 -i mediasource_0_1_0.mp4 -c copy -bsf:a aac_adts
copy /b mediasource_0_0_*.mp4 out.mp4
```
## 常见问题
- 合并后声音播放不正常:由于部分网站使用了HE-AAC v2(AAC+SBR+PS)作为音频编码,大部分播放器还不支持此音频流格式,故声音不正常,使用Windows自带的视频播放器播放正常
## 特别说明
- 仅限内部交流使用,请勿用于非法用途

View File

@ -12,14 +12,13 @@
// @grant none
// ==/UserScript==
evanEnv = new Object();
evanEnv.mediaSources = [];
evanEnv.enableAutoForward = true;
evanEnv.enableAutoDownload = true;
jsMedia = new Object();
jsMedia.mediaSources = [];
jsMedia.enableAutoDownload = true;
(function () {
evanEnv.videos = document.getElementsByTagName('video');
evanEnv.downloadRawData = function (bufferList, fileName = 'out', ext = '.mp4') {
jsMedia.videos = document.getElementsByTagName('video');
jsMedia.downloadRawData = function (bufferList, fileName = 'out', ext = '.mp4') {
var buffList = new Array();
var totalLength = 0;
@ -59,36 +58,42 @@ evanEnv.enableAutoDownload = true;
};
evanEnv.download = function () {
for (var i = 0; i < evanEnv.mediaSources.length; i++) {
var currentItem = evanEnv.mediaSources[i];
jsMedia.download = function () {
for (var i = 0; i < jsMedia.mediaSources.length; i++) {
var currentItem = jsMedia.mediaSources[i];
if (currentItem.downloaded == undefined || currentItem.downloaded == false) {
for (var x = 0; x < currentItem.rawSources.length; x++) {
evanEnv.downloadRawData(currentItem.rawSources[x], 'mediasource_' + i + '_' + x);
jsMedia.downloadRawData(currentItem.rawSources[x], 'mediasource_' + i + '_' + x);
}
}
currentItem.downloaded = true;
}
};
evanEnv.downloadMediaSource = function (mediaSource) {
jsMedia.downloadMediaSource = function (mediaSource) {
for (var x = 0; x < mediaSource.rawSources.length; x++) {
evanEnv.downloadRawData(mediaSource.rawSources[x], 'mediasource_' + x);
jsMedia.downloadRawData(mediaSource.rawSources[x], 'mediasource_' + x);
mediaSource.downloaded = true;
}
};
jsMedia.setSpeed = function (speed) {
for (let i = 0, length = jsMedia.videos.length; i < length; i++) {
jsMedia.videos[i].playbackRate = 10;
}
};
var proxy_addSourceBuffer = MediaSource.prototype.addSourceBuffer;
MediaSource.prototype.addSourceBuffer = function (mimeType) {
var mediaSourceThis = this;
evanEnv.mediaSources.push(this);
jsMedia.mediaSources.push(this);
this.lastPos = 0;
if (evanEnv.enableAutoDownload) {
if (jsMedia.enableAutoDownload) {
this.onsourceended = function () {
evanEnv.download();
jsMedia.download();
};
this.onsourceclose = function () {
evanEnv.downloadMediaSource(this);
jsMedia.downloadMediaSource(this);
};
}
@ -100,17 +105,6 @@ evanEnv.enableAutoDownload = true;
var buffList = [];
this.rawSources.push(buffList);
retSourceBuffer.rawData = buffList;
if (evanEnv.enableAutoForward) {
retSourceBuffer.onupdate = function () {
if (this.buffered != this.buffered.length > 0) {
var endPos = this.buffered.end(0);
if (endPos > 5 && endPos - mediaSourceThis.lastPos > 25) {
evanEnv.videos[0].currentTime = endPos - 3;
mediaSourceThis.lastPos = evanEnv.videos[0].currentTime;
}
}
};
}
return retSourceBuffer;
};
var proxy_appendBuffer = SourceBuffer.prototype.appendBuffer;