thunder-app / thunder

Thunder - An open-source cross-platform Lemmy client for iOS and Android built with Flutter
https://thunderapp.dev
GNU Affero General Public License v3.0
745 stars 65 forks source link

MP4 Videos originating from catbox.moe not work #1442

Open DragonLee-X opened 3 weeks ago

DragonLee-X commented 3 weeks ago

Bug Description

Click on a catbox.moe linked video to watch it, the internal player pops up and buffers for 4 seconds, then gives an error. The error popup asks to play the file in the browser, if you click the arrow, the file plays fine in the external browser.

This is a new issue since the new mediaplayer introduced in 0.4.0

Expected Behaviour

Expect the video to play in the internal media player.

Steps to Reproduce

Open a linked video (mp4 format) by clicking on the thumbnail or the link.

New screen opens with the internal media player

Mediaplayer buffers for ~4 seconds then gives an error: Video Can't be played. Retry. Another error pops up saying "Failed to load video. Open link in browser?"

Click the arrow on the error-popup and the video opens and plays fine in the external browser.

Additional Context

Example lemmy post:

https://lemmy.world/post/6451438

The streamable source link works fine, the mirrors with mp4 videos do not.

App Version

0.4.0

Device

Samsung S23 Ultra

OS

(samsung) Android 14 latest updates

hjiangsu commented 2 weeks ago

Thanks for the bug report! Unfortunately, I'm unable to reproduce this issue. Can you confirm if this is still occurring?

Additionally, are you on a VPN? Sometimes, catbox doesn't play well with some VPNs and will fail to load content. I would also check to see if any of the following things apply to you under "Connectivity Issues" here: https://catbox.moe/faq.php

micahmo commented 2 weeks ago

I can reproduce this issue on my Android emulator.

It's the same error I've seen with other videos that river_player can't handle, which is Video player had error androidx.media3.exoplayer.ExoPlaybackException: Source error. Unfortunately it seems to be coming from ExoPlayer, which I guess river_player uses under the hood. I wonder if we need to consider options for a player that supports more codecs or something.

DragonLee-X commented 2 weeks ago

Thanks for the bug report! Unfortunately, I'm unable to reproduce this issue. Can you confirm if this is still occurring?

Yes it is still occurring.

Additionally, are you on a VPN? Sometimes, catbox doesn't play well with some VPNs and will fail to load content. I would also check to see if any of the following things apply to you under "Connectivity Issues" here: https://catbox.moe/faq.php

I am not behind a vpn, had one installed but disabled, I removed it to test and it is still occurring. (Plus the video works fine in both firefox and chrome browsers) Also tried under wifi and 5G connections, the issue persists.

I can reproduce this issue on my Android emulator.

It's the same error I've seen with other videos that river_player can't handle, which is Video player had error androidx.media3.exoplayer.ExoPlaybackException: Source error. Unfortunately it seems to be coming from ExoPlayer, which I guess river_player uses under the hood. I wonder if we need to consider options for a player that supports more codecs or something.

Ah, interesting. Seeing how (the same) MP4s from other sites seem to work in the thunder player, I assumed it must be related to how catbox.moe presents the mp4 file. I think I had an audio file from there that worked but can't find the link to test it.

hjiangsu commented 2 weeks ago

Ahh interesting, thanks for checking this @micahmo!

I wonder if we could do a test using the more general video_player plugin to see if the issue still occurs. video_player also uses ExoPlayer under the hood for Android, but it seems like it should support mp4s according to this: https://developer.android.com/media/media3/exoplayer/supported-formats#progressive-container

micahmo commented 2 weeks ago

I don't think the problem is necessarily mp4s, since others work (like this one).

Post: https://lemmy.ca/post/22997411 Video: https://thumbsnap.com/i/2F7oq5kp.mp4

Since mp4 is just a container, I think more likely there is a problem with the specific video or audio codec used by videos on catbox that ExoPlayer doesn't support. I'm afraid video_player wouldn't help, if it still uses ExoPlayer.

micahmo commented 2 weeks ago

I downloaded videos that don't and do play, and below is the respective info. They both appear to be using avc1 as the video codec, and AAC LC as the audio codec, so now I'm really not sure what the problem is. 😞

General
Format                         : MPEG-4
Format profile                 : Base Media
Codec ID                       : isom (isom/iso2/avc1/mp41)
File size                      : 3.68 MiB
Duration                       : 14 s 806 ms
Overall bit rate               : 2 084 kb/s
Frame rate                     : 60.000 FPS
Writing application            : Lavf58.76.100

Video
ID                             : 1
Format                         : AVC
Format/Info                    : Advanced Video Codec
Format profile                 : High@L3.1
Format settings                : CABAC / 4 Ref Frames
Format settings, CABAC         : Yes
Format settings, Reference fra : 4 frames
Codec ID                       : avc1
Codec ID/Info                  : Advanced Video Coding
Duration                       : 14 s 800 ms
Bit rate                       : 2 000 kb/s
Width                          : 848 pixels
Height                         : 480 pixels
Display aspect ratio           : 16:9
Frame rate mode                : Constant
Frame rate                     : 60.000 FPS
Color space                    : YUV
Chroma subsampling             : 4:2:0
Bit depth                      : 8 bits
Scan type                      : Progressive
Bits/(Pixel*Frame)             : 0.082
Stream size                    : 3.42 MiB (93%)
Writing library                : x264 core 155 r2917 0a84d98
Encoding settings              : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=4 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=20 / rc=abr / mbtree=1 / bitrate=2000 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Color range                    : Limited
Color primaries                : BT.601 PAL
Transfer characteristics       : BT.601
Codec configuration box        : avcC

Audio
ID                             : 2
Format                         : AAC LC
Format/Info                    : Advanced Audio Codec Low Complexity
Codec ID                       : mp4a-40-2
Duration                       : 14 s 806 ms
Source duration                : 14 s 829 ms
Source_Duration_LastFrame      : -9 ms
Bit rate mode                  : Constant
Bit rate                       : 132 kb/s
Channel(s)                     : 2 channels
Channel layout                 : L R
Sampling rate                  : 44.1 kHz
Frame rate                     : 43.066 FPS (1024 SPF)
Compression mode               : Lossy
Stream size                    : 239 KiB (6%)
Source stream size             : 240 KiB (6%)
Default                        : Yes
Alternate group                : 1
mdhd_Duration                  : 14805
General
Format                         : MPEG-4
Format profile                 : Base Media
Codec ID                       : isom (isom/iso2/avc1/mp41)
File size                      : 2.26 MiB
Duration                       : 23 s 197 ms
Overall bit rate               : 816 kb/s
Frame rate                     : 30.000 FPS
Writing application            : Lavf58.29.100

Video
ID                             : 1
Format                         : AVC
Format/Info                    : Advanced Video Codec
Format profile                 : Constrained Baseline@L3
Format settings                : 3 Ref Frames
Format settings, CABAC         : No
Format settings, Reference fra : 3 frames
Codec ID                       : avc1
Codec ID/Info                  : Advanced Video Coding
Duration                       : 23 s 167 ms
Bit rate                       : 779 kb/s
Width                          : 352 pixels
Height                         : 624 pixels
Display aspect ratio           : 0.564
Frame rate mode                : Constant
Frame rate                     : 30.000 FPS
Color space                    : YUV
Chroma subsampling             : 4:2:0
Bit depth                      : 8 bits
Scan type                      : Progressive
Bits/(Pixel*Frame)             : 0.118
Stream size                    : 2.15 MiB (95%)
Title                          : VideoHandle
Writing library                : x264 core 155 r2917 0a84d98
Encoding settings              : cabac=0 / ref=3 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=4 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Language                       : English
Codec configuration box        : avcC

Audio
ID                             : 2
Format                         : AAC LC
Format/Info                    : Advanced Audio Codec Low Complexity
Codec ID                       : mp4a-40-2
Duration                       : 23 s 197 ms
Bit rate mode                  : Constant
Bit rate                       : 31.3 kb/s
Channel(s)                     : 1 channel
Channel layout                 : M
Sampling rate                  : 44.1 kHz
Frame rate                     : 43.066 FPS (1024 SPF)
Compression mode               : Lossy
Stream size                    : 88.8 KiB (4%)
Title                          : SoundHandle
Language                       : English
Default                        : Yes
Alternate group                : 1
DragonLee-X commented 2 weeks ago

@micahmo

Ah thanks, was going to look into getting file infos as well but am a bit time contrained at the moment.

Your two files do have different video encoding profiles (high@l3.1/cabac 0 and Constrained Baseline@l3/cabac 1) perhaps there lies the error but I can only guess.

It still seems only stuff from catbox.moe is affected (on the thunder app only), other sources work fine for me.

hjiangsu commented 2 weeks ago

Since mp4 is just a container, I think more likely there is a problem with the specific video or audio codec used by videos on catbox that ExoPlayer doesn't support. I'm afraid video_player wouldn't help, if it still uses ExoPlayer.

I think it might still be worth a shot to see if the default video_player works with the catbox link - while both of them use ExoPlayer under the hood, the versions may differ between them (e.g., video_player could have a more recent version of ExoPlayer than river_player)

Update: I did a quick check, and it does seem like river_player is using an older version of ExoPlayer (river_player is using 1.1.1 while video_player is using 1.3.1)

river_player: https://github.com/RevEngine3r/river_player/blob/master/android/build.gradle video_player: https://github.com/flutter/packages/blob/main/packages/video_player/video_player_android/android/build.gradle

micahmo commented 2 weeks ago

Nice find!! Definitely worth a shot then!

hjiangsu commented 2 weeks ago

I just did a quick test and it seems like video_player handles the link properly. If this is the case, then it might just be better if we migrate over to using video_player (since its part of the official Flutter maintained packages)

https://github.com/thunder-app/thunder/assets/30667958/a600a2ba-71cb-4ebc-b398-377b705a31e4

The one downside is that we would have to create our own video controls (and perhaps figure out a way to handle full screen properly), but it seems like it should be feasible. Thoughts @micahmo?

micahmo commented 2 weeks ago

Nice find! If we invest some time into making our own controls, we can use the same player for YouTube videos, if we can use that other package you mentioned for extracting the URL.

hjiangsu commented 2 weeks ago

I did a bit more work on this, and have been able to add in some very basic controls (play/pause, scrubbing) into the video_player!

The WIP branch is here: https://github.com/thunder-app/thunder/tree/feature/migrate-video-player