Momo707577045 / m3u8-downloader

m3u8 视频在线提取工具
5.97k stars 1.15k forks source link

10小时视频下载,因内存不足快下完时页面崩溃 #27

Closed xiaoshui05 closed 2 years ago

xiaoshui05 commented 3 years ago

视频10小时,总共14.8g,电脑16g内存,快下完的时候页面崩溃。需要考虑做一下分割

尝试实现了一下,不够优雅,不好意思提pull request。每1000个保存一次对应文件是1.7g(ts格式)。

                // 添加了两个变量 this.downloadFinish(已经保存到本地的数量) this.downloadLocal(是否正在保存文件到本地)

                // 处理 ts 片段,AES 解密、mp4 转码
                dealTS(file, index, callback) {
                    const data = this.aesConf.uri ? this.aesDecrypt(file, index) : file
                    this.conversionMp4(data, index, (afterData) => { // mp4 转码
                        this.mediaFileList[index] = afterData // 判断文件是否需要解密
                        this.finishList[index].status = 'finish'
                        this.finishNum++
                            if (this.finishNum === this.tsUrlList.length) {
                                //this.downloadFile(this.mediaFileList, this.formatTime(this.beginTime, 'YYYY_MM_DD hh_mm_ss'))
                                const downloadLocalData = [];
                                for (i = 0; i < this.finishNum - this.downloadFinish; i++) {
                                    downloadLocalData[i] = this.mediaFileList[this.downloadFinish + i]
                                    this.mediaFileList[this.downloadFinish + i] = 0;
                                }
                                this.downloadFile(downloadLocalData, this.formatTime(new Date(), 'YYYY_MM_DD hh_mm_ss'))
                            } else if (this.finishNum > this.downloadFinish + 2000 && this.downloadLocal === false) {
                            this.downloadLocal = true;
                            const downloadLocalData = [];
                            for (i = 0; i < 1000; i++) {
                                downloadLocalData[i] = this.mediaFileList[this.downloadFinish + i]
                                this.mediaFileList[this.downloadFinish + i] = 0;
                            }
                            this.downloadFile(downloadLocalData, this.formatTime(new Date(), 'YYYY_MM_DD hh_mm_ss'))
                            downloadLocalData = [];
                            this.downloadLocal = false;
                            this.downloadFinish += 1000;
                        }
                        callback && callback()
                    })
                },
Momo707577045 commented 3 years ago

好的,好建议,感谢你的留言,我工作忙完思路一下

Momo707577045 commented 3 years ago

你可以拷一份代码,自己先实现着,代码量不多,应该不会太难

Momo707577045 commented 3 years ago

再次响应各位老板要求,已添加视频特定片段下载功能,解决大视频文件内存不够问题。

Momo707577045 commented 2 years ago

已优化实现方式,使用流式下载,边下载边保存,彻底解决内存不足问题