Last-Order / Minyami

A lovely video downloader for HLS videos
GNU General Public License v3.0
561 stars 37 forks source link

以更优雅的方式处理直播流(with "--live" option)中断场景 #65

Closed CosmosJunk closed 3 years ago

CosmosJunk commented 3 years ago

Basic Infomation

在试用录制showroom直播的时候注意到,如果使用minyami无论是Win或者Ubuntu环境下,直播流自己中断后,minyami会以比较“粗暴”的方式中断,请问可以仅针对"--live"模式下的中止处理进行细化么?

CMD: minyami -d "https://hls-origin210.showroom-cdn.com/liveedge/somepath/chunklist_somepath2.m3u8" --output "Target_SHOWROOM.ts" LOG:

[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][WARN] Site is not supported by Minyami Core. Try common parser.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Proccessing media_somepath2_5989.ts finished. (1 / unknown | Avg Speed: 1.00 chunks/s or 1.81x)  
[MINYAMI][INFO] Proccessing media_somepath2_5987.ts finished. (2 / unknown | Avg Speed: 2.00 chunks/s or 3.61x)  
[MINYAMI][INFO] Proccessing media_somepath2_5986.ts finished. (3 / unknown | Avg Speed: 3.00 chunks/s or 5.42x)  
[MINYAMI][INFO] Proccessing media_somepath2_5990.ts finished. (4 / unknown | Avg Speed: 4.00 chunks/s or 7.23x)  
[MINYAMI][INFO] Proccessing media_somepath2_5988.ts finished. (5 / unknown | Avg Speed: 2.50 chunks/s or 4.52x)  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Proccessing media_somepath2_5991.ts finished. (6 / unknown | Avg Speed: 1.00 chunks/s or 1.81x)  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Proccessing media_somepath2_5992.ts finished. (7 / unknown | Avg Speed: 0.70 chunks/s or 1.26x)  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Proccessing media_bsomepath2_5993.ts finished. (8 / unknown | Avg Speed: 0.73 chunks/s or 1.31x)  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
........................  
[MINYAMI][INFO] Proccessing media_somepath2_7870.ts finished. (1676 / unknown | Avg Speed: 0.50 chunks/s or 0.90x)  
[MINYAMI][INFO] Proccessing media_somepath2_7871.ts finished. (1677 / unknown | Avg Speed: 0.50 chunks/s or 0.90x)  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][INFO] M3U8 file fetched.  
[MINYAMI][INFO] Start fetching M3U8 file.  
[MINYAMI][WARN] Fail to fetch M3U8 file: [404 Not Found]  
[MINYAMI][WARN] If you are downloading a live stream, this may result in a broken output video.  
[MINYAMI][INFO] Try again.  
[MINYAMI][WARN] Fail to fetch M3U8 file: [404 Not Found]  
[MINYAMI][WARN] If you are downloading a live stream, this may result in a broken output video.  
[MINYAMI][INFO] Try again.  
[MINYAMI][WARN] Fail to fetch M3U8 file: [404 Not Found]  
[MINYAMI][WARN] If you are downloading a live stream, this may result in a broken output video.  
[MINYAMI][INFO] Try again.  
[MINYAMI][WARN] Fail to fetch M3U8 file: [404 Not Found]  
[MINYAMI][WARN] If you are downloading a live stream, this may result in a broken output video.  
[MINYAMI][WARN] Max retries exceeded. Abort.  
Error: Max retries exceeded.  
    at Object.<anonymous> (/usr/local/lib/node_modules/minyami/dist/utils/m3u8.js:45:31)  
    at Generator.throw (<anonymous>)  
    at rejected (/usr/local/lib/node_modules/minyami/dist/utils/m3u8.js:6:65)  
    at <anonymous>  
    at process._tickCallback (internal/process/next_tick.js:188:7)  
[MINYAMI][ERROR] Aborted due to critical error.

RESULT: The streaming is ended here, but Minyami is still trying to fetch and update the m3u8 file (for the showroom case, at least), aborts after max retries finally. I still have all those *.ts segments grabbed under the corresponding tmp(Win/Ubuntu) folder, just no post-processing merging or other possible handlings.


In contrast, the "ffmpeg" command using the exact same m3u8 sniffed by Minyami Chrome-Extension is more elegantly handled.

CMD: ffmpeg -i "https://hls-origin210.showroom-cdn.com/liveedge/somepath/chunklist_somepath2.m3u8" -c copy Target_SHOWROOM_FFMPEG.ts RESULT: Live stream is muxed to the target file successfully.


Would be grateful for a more complete handle here. Thank you!

Last-Order commented 3 years ago

其实原因是这些网站没有根据HLS规范在直播结束后返回列表结束标记。

可以这么做,当m3u8遇到4xx或者5xx的时候认为是直播流结束开始合并,如果是纯网络问题就当失败。

不过这看上去是一个行为的breaking change,可能得提升一个大版本。

Last-Order commented 3 years ago

可以试一下4.0.0版本,4.0.0版本这种情况会结束录制。