jmshrv / finamp

A Jellyfin music client for mobile
Mozilla Public License 2.0
2k stars 130 forks source link

redesign-beta: Gap between tracks when transcoding #861

Open atomheartother opened 2 months ago

atomheartother commented 2 months ago

Finamp is usually a gapless audio player but with transcoding on there is a tiny gap between tracks. This is audible between any two tracks meant to be gapless.

Downloading the album or switching to direct play fixes the issue.

Android version: 14 Device: Samsung Z Flip 5

Chaphasilor commented 2 months ago

Are you talking about transcoded streaming or transcoded downloading? Finamp can only stream AAC, as stated in the settings:

Screenshot_20240904-180130.png

Or are you streaming OPUS files without transcoding enabled?

atomheartother commented 2 months ago

You appear to be correct, I may have misidentified what's causing the gap on my device, I was tweaking a few settings - let me try again later and update this ticket. But I'm 100% sure there's a bug here - I'm so not used to gaps from using finamp daily that I physically jumped when the tracks didn't line up perfectly 🤭 will update.

atomheartother commented 2 months ago

So the error I made was testing with the same album twice - clearly the next track had been buffered.

The actual bug is just that there is a gap between tracks when transcoding, period. Direct play and downloading the album both fix the issue, but transcoding always causes a gap between tracks.

atomheartother commented 2 months ago

I've edited the description and my original post to reflect the actual issue :)

One thing to note: all the tracks I tested this in were in FLAC on the server so it is possible the issue is that FLAC is gapless but not AAC.

Chaphasilor commented 2 months ago

Could you try to extract the transcoded AAC files from the server's transcodes directory and check if those are gapless (i.e. by playing them with a regular gapless player). Maybe Jellyfin/ffmpeg adds some silence to the tracks when transcoding them?

Also, can you try downloading in different codecs? You can try AAC, MP3 and OPUS as transcoding codecs. Do they all show the same behavior when downloaded (working gapless playback)?

atomheartother commented 2 months ago

I ran a bunch of tests! I used the first 2 tracks of the album Nonagon Infinity, the entire purpose of the album is to be gapless so it's pretty blatant when there are gaps.

Could you try to extract the transcoded AAC files from the server's transcodes directory and check if those are gapless (i.e. by playing them with a regular gapless player). Maybe Jellyfin/ffmpeg adds some silence to the tracks when transcoding them?

First I downloaded the tracks in FLAC locally and read them with mpv, and, good news, the tracks played seamlessly with mpv. So, we have our control.

I then tried to use Finamp and to ask it to transcode the tracks, however it seems Jellyfin didn't really generate .aac file so much as it generated .m3u8 files and a plethora of .ts files, which i assume are used to break up transcoding into chunks. I decided against trying to look into making that work locally, it sounds like a pain.

I was curious so I asked my trusty Feishin, which I know to be a gapless desktop audio player, and I asked it to get the tracks transcoded to AAC 320kbps. In this case Jellyfin did generate .aac files! I let both files play completely with Feishin to make sure transcoding was complete, and while playing in Feishin the transition was gapless. I tried this again 3 or 4 times, and yes, somehow Feishin plays these .aac gaplessly.

I then downloaded both .aac tracks, played them locally with mpv, there were gaps (though I did also find an issue for playing AAC gaplessly in mpv so really at this point what is even real anymore?).

I also left the Finamp beta and tried playing the files by transcoding using Finamp's current main branch. Jellyfin, again, showed .m3u8 and .ts output files, and sure enough, there was an audible gap when the files played in finamp, so I guess this isn't a beta bug? I thought for sure Finamp used to be gapless when transcoding but I might be wrong, do you guys not expect gapless playback to be a feature when transcoding? If not, is it possible that when switching to the beta, transcoding was suddenly enabled for me? Because that would explain me feeling like switching to the beta suddenly added gaps.

Also, can you try dowbloading in different codecs? You can try AAC, MP3 and OPUS as transcoding codecs. Do they all show the same behavior when downloaded (working gapless playback)?

Finamp beta v0.9.9 - Transcoding (AAC): Gap Finamp beta v0.9.9 - Downloaded, no transcode (FLAC): Gapless playback Finamp beta v0.9.9 - Downloaded, AAC: Gap, same length as transcoding Finamp beta v0.9.9 - Downloaded, OPUS: Gap, smaller than in AAC Finamp beta v0.9.9 - Downloaded, mp3: Gap, smaller than AAC

Anyway, if it's not expected that files should be gapless when transcoding with Finamp then i supposed this should be closed as "not a bug". It certainly is not a beta bug, but I thought for sure that years ago, when I switched to finamp, I did test gapless transcoded playback and it worked just fine. But maybe it was all a dream ; if so just close this ticket please. If not, it may be my device, I did change phones in that time.

Chaphasilor commented 2 months ago

Finamp should be gapless in all cases, so this is a bug. I'm just not sure what the cause is.

Can you try another local gapless player that works with AAC? And then requesting a transcode in Feishin, extracting the aac files, testing for gapless, then clearing the transcode directory, downloading the files as transcoded aac in Finamp, again extracting them from the transcode directory, and seeing if there's any difference?

You could also try a gapless local player on your phone, to make sure that's not part of the issue.

midwesternrodent commented 1 month ago

This is a bit of a long shot, but this sounds very similar to the issues I'm encountering in #857 just isolated to the end / beginning of the track. I'm wondering if this is less of a "gap" between songs, and more of a corrupted transcode file at the beginning and / or end of a song.

Could you share your transcoding logs for two of the songs where you see a gap in the audio? The transcode logs would be at /var/log/jellyfin on your server unless you've changed the default.