persepolisdm / persepolis

Persepolis Download Manager is a GUI for aria2.
https://persepolisdm.github.io
GNU General Public License v3.0
6.12k stars 647 forks source link

Video downloads are broken on youtube #940

Closed iFreilicht closed 3 months ago

iFreilicht commented 3 months ago

System Details:

Issue Description and steps to reproduce: The first part of the download seems to work fine, but the video part is downloaded within 1 second, while the audio part takes much longer, and muxing with ffmpeg fails with the following error (taken from /Library/Application Support/persepolis_download_manager):

Persepolis - ERROR - ffmpeg error: Not detecting m3u8/hls with non standard extension and non standard mime type
    Last message repeated 4 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x122e0e170] moov atom not found
[in#0 @ 0x122e0ddc0] Error opening input: Invalid data found when processing input

This is caused by the build script in https://github.com/persepolisdm/mac-package-build downloading ffmpeg without pinning a version. As ffmpeg has released version 6 a while ago, which contains this commit, m3u8 is not a standard extension for HLS files anymore.

The solution would be to pass -allowed_extensions ALL to ffmpeg. Alternatively, bundling ffmpeg 5 also works.

I fixed that and tried again, which caused the following error:

Persepolis - ERROR - ffmpeg error: [https @ 0x12801f400] Protocol 'https' not on whitelist 'file,crypto,data'!
[hls @ 0x127704360] Error when loading first segment 'https://rr2---sn-h0jelnez.googlevideo.com/videoplayback/id/50d0fdf004ce3f46/itag/616/source/youtube/expire/1709415834/ei/OknjZe6dMKiFi9oP96uK0Ac/ip/2003:fd:f03:f900:b89b:6ece:63b3:bb48/requiressl/yes/ratebypass/yes/pfa/1/wft/1/sgovp/clen%3D20127089%3Bdur%3D66.107%3Bgir%3Dyes%3Bitag%3D356%3Blmt%3D1681767011083507/rqh/1/hls_chunk_host/rr2---sn-h0jelnez.googlevideo.com/xpc/EgVo2aDSNQ%3D%3D/mh/km/mm/31,26/mn/sn-h0jelnez,sn-4g5ednsz/ms/au,onr/mv/m/mvi/2/pl/37/initcwndbps/1566250/vprv/1/playlist_type/DVR/txp/5532434/mt/1709393845/fvip/5/keepalive/yes/fexp/24007246/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,pfa,wft,sgovp,rqh,xpc,vprv,playlist_type/sig/AJfQdSswRQIgQnwxP63uQIw5PySkxwvdBalex3s4bJdyIGnO2NQXOZ8CIQDtZ-g_1V5va33cNGrwydTrpdow3nb6kC-ntOf8jMatXg%3D%3D/lsparams/hls_chunk_host,mh,mm,mn,ms,mv,mvi,pl,initcwndbps/lsig/APTiJQcwRQIgCz_z3UFoShtVx-DZ0yC6_PHbOHALjErKL44W1omWkN8CIQCWaukyNU28YfQSiJ6YieRe3w_2QR1ciAuezsqaj2pS6Q%3D%3D/playlist/index.m3u8/govp/slices%3D0-1027479/gosq/0/file/seg.ts'

This can (in theory) be fixed by passing -protocol_whitelist file,https,tcp,tls to ffmpeg. However, it doesn't actually work. While it makes the download finish, the resulting file's video stream is invalid:

Screenshot 2024-03-02 at 18 01 05

But the file can be played back, and I can hear the audio:

Screenshot 2024-03-02 at 18 01 27

I dug a bit further into the code, and found that Persepolis actually doesn't use yt-dlp for downloading videos, only for listing the available resolutions and audio formats! The actual download is then done with aria2, but the video format is only a m3u8 (or HLS) playlist, which means it isn't actually downloaded at first. Only when muxing, ffmpeg will try to stream the playlist and silently fail, causing the broken video stream.


At this point, I gave up on fixing the issue myself. Trying to use ffmpeg to download the youtube video streams correctly is very challenging, that's exactly why yt-dlp exists.

So the proper fix would be to download videos with yt-dlp internally, not with aria2, but AFAICT, this would require some major changes to be compatible with the current GUI, and I don't have time right now to make that happen.

kiahamedi commented 3 months ago

Hi dear @iFreilicht

Thanks for your bug report, yes we had some inconsistencies in the previous version that were fixed in version ‍4.0.1. I request you to download the new version from Releasetag 4.0.1 for Mac and test again! Also, using VLC instead of Quicktime on Mac is a more suitable suggestion

Kia Hamedi

iFreilicht commented 3 months ago

Indeed, this works perfectly now, thank you!