tumtumtum / StreamingKit

A fast and extensible gapless AudioPlayer/AudioStreamer for OSX and iOS (iPhone, iPad)
Other
2.42k stars 525 forks source link

M4A files over 5 minutes do not play #310

Open alexfoxy opened 7 years ago

alexfoxy commented 7 years ago

Hey,

I'm having an issue playing M4A files with StreakingKit. I can play M4A files under 5 minutes but any that exceed that length result in an an unexpected error (code 2) and do not play back.

I've read about M4A needing to be optimised for streaming, is this the issue with the larger files? If so how do you do so?

Thanks, Alex

abdultcb commented 7 years ago

I am having the same issue but with CAF files. I am exporting songs from iPod Library and then playing these songs. need your help

kuntal33 commented 7 years ago

Did you guys find any solution? I am having same issue.

alexfoxy commented 7 years ago

Unfortunately I just used another solution!

kuntal33 commented 7 years ago

It would be great help if you provide me another solution that you used. Thanks in advance

harshalrj25 commented 7 years ago

I'm having the same issue while playing M4A files with StreakingKit. I can play M4A files under 5 minutes but any that exceed that length do not play back.

newbdez33 commented 7 years ago

Any update here?

doriansgithub commented 7 years ago

I believe the issue has something to do with the encoding. If you brought in a CD with Lossless (I use XLD), then used the autoConvert to 256 in iTunes, the player won't be able to play tunes with approx. over 5:30. I'm reloading my entire collection into iTunes at full AIFF resolution, and then using the autoConvert to 256 for the portables. If that doesn't work, then we'll have to figure out what the issue is.

doriansgithub commented 7 years ago

I'm starting with my favorite band: Aerosmith, and I'm almost done, so I'll update shortly.

doriansgithub commented 7 years ago

Sorry to say, but that doesn't work! I'll try encoding with AudiConverter Lite, but this is not good enough, as users will be forced to download extra software to their machine. Most people barely know how to turn on their machines, let alone understand that there are issues with "Encoding", like what is that?

doriansgithub commented 7 years ago

They do play at full AIFF with no downsampling. So the issue is reading m4a files. I don't use mp3s, or wav so I can't speak for that.

doriansgithub commented 7 years ago

It seems to work with AudioConverterPro but's $6.99 and i don't want to put my customers thru that, so I hope there is another way to fix this.

iDevelopper commented 7 years ago

Why don't you use the AAC encoder directly when you import your CD?

doriansgithub commented 7 years ago

I'll try that, but ideally, I like to have the pure cd quality in iTunes so that I can hear that if wanted to.

Sent from my iPhone

On Jun 22, 2017, at 12:50 AM, Patrick notifications@github.com wrote:

Why don't you use the AAC encoder directly when you import your CD?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

iDevelopper commented 7 years ago

I realize that when I synchronise my iPhone with iTunes, I have this message when iTunes try to copy your file to the device:

2017-06-23_12-01-22

doriansgithub commented 7 years ago

It might be a lossless file. Try converting to aac 256.

Sent from my iPhone

On Jun 23, 2017, at 3:10 AM, Patrick notifications@github.com wrote:

I realize that when I synchronise my iPhone with iTunes, I have this message when iTunes try to copy your file to the device:

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

iDevelopper commented 7 years ago

Yes but what is your issue exactly? What is the audio file you try to play with streamingKit?

doriansgithub commented 7 years ago

Every file in my phone over 5:30 mins won't play. It skips over it.

Sent from my iPhone

On Jun 23, 2017, at 7:13 AM, Patrick notifications@github.com wrote:

Yes but what is your issue exactly? What is the audio file you try to play with streamingKit?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

doriansgithub commented 7 years ago

Sorry, unless it's uncompressed (aiff), then it plays any length.

Sent from my iPhone

On Jun 23, 2017, at 7:13 AM, Patrick notifications@github.com wrote:

Yes but what is your issue exactly? What is the audio file you try to play with streamingKit?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

iDevelopper commented 7 years ago

I understand but what do you want exactly to work?

doriansgithub commented 7 years ago

It should play m4a files of any size that were compressed by iTunes. I haven't tried compressing the files when bringing them in to iTunes. But I rather have aiff files in iTunes and compressing them only when syncing to the portables.

Sent from my iPhone

On Jun 23, 2017, at 7:47 AM, Patrick notifications@github.com wrote:

I understand but what do you want exactly to work?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

iDevelopper commented 7 years ago

But lossless is not compressed!

doriansgithub commented 7 years ago

I believe Apple doesn't allow lossless on their portables. I am able to load lossless in iTunes, but to load it into a device it needs to be aiff, MP3 or m4a.

Sent from my iPhone

On Jun 23, 2017, at 8:14 AM, Patrick notifications@github.com wrote:

But lossless is not compressed!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

mitchdowney commented 7 years ago

I also cannot play any M4A audio files :(

doriansgithub commented 7 years ago

And we still can't play m4a files that are greater than 5:30 in length, unless it's compressed by a 3rd party.

doriansgithub commented 7 years ago

You should be able to play m4a. What length is the file?

mitchdowney commented 7 years ago

The file is over an hour and unoptimized. Maybe remote streaming playback of the file is failing because of this old issue?

Here is the m4a file that is failing to load:

http://media.blubrry.com/jordanbpeterson/content.blubrry.com/jordanbpeterson/20_-_Ideology_Logos_and_Belief.m4a

I don't have control over the content so I can't optimize it.

patrickjquinn commented 7 years ago

It’s a 2 year old issue and Im still struggling with basically this problem, perhaps it’s time we took it into our own hands and figured out a better way to handle remote m4a streams (Or m4a at all) given that m4a has officially replaced mp3 as the dominant audio format (or so I’ve read)

On 21 Aug 2017, 06:44 +0100, Mitch Downey notifications@github.com, wrote:

The file is over an hour and unoptimized. Maybe remote streaming playback of the file is failing because of this old issue? Here is the m4a file that is failing to load: http://media.blubrry.com/jordanbpeterson/content.blubrry.com/jordanbpeterson/20_-_Ideology_Logos_and_Belief.m4a — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

doriansgithub commented 7 years ago

Yes, but how? I'm not good enough to tackle low level code. I can't see this being that difficult for Tum, since he was able to accomplish the entire project. I think he should set up a donation format, so that he gets motivated.

patrickjquinn commented 7 years ago

Like any good community effort we dig into the code (its just Objective-C, how scary can it be) and report our findings and then formulate a plan of attack re: fixing it. From what I gather there is an AVExportSession run over the stream as it enters the buffer (something to that effect) and i'd imagine it relies on the header to re-encode the stream. That is where the problem probably lies. https://mailtrack.io/ Sent with Mailtrack https://mailtrack.io/install?source=signature&lang=en&referral=patrick.jm.quinn@gmail.com&idSignature=22

On Mon, Aug 21, 2017 at 3:40 PM, Dorian Mattar notifications@github.com wrote:

Yes, but how? I'm not good enough to tackle low level code. I can't see this being that difficult for Tum, since he was able to accomplish the entire project. I think he should set up a donation format, so that he gets motivated.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tumtumtum/StreamingKit/issues/310#issuecomment-323760419, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvC6h6sDhY9ngd5KjD6G7sqZKga_0nhks5saZbPgaJpZM4KrCd4 .

mitchdowney commented 7 years ago

@patrickjquinn I would love to help resolve this but unfortunately I have only Swift experience (~2 years). I'm motivated to help but would need some direction on how I could be useful.

I'd be willing to donate to get this issue resolved, if that would help.

Unfortunately @tumtumtum I like others will need to switch to FreeStreamer if we can't resolve this.

Update: Actually this SO post claims FreeStreamer has the same problem. It seems that both libraries can support optimized m4a files (I think?) but not non-optimized m4a files.


FWIW these open issues appear to be duplicates to me:

84

89

171

240

If we should close or combine them somehow let me know.

mitchdowney commented 7 years ago

I have only tested my issue with unoptimized m4a files over an hour long (sample). I haven't tested with optimized shorter files yet.

Goal: Support streaming unoptimized m4a files, and seeking to time in that file on load.

How difficult would this be to fix completely? Is it even fixable since they are unoptimized files?

How difficult would it be to write a fallback for this use case? Like detect if an unoptimized m4a file is streaming, and if it is, then load that file through an alternate player? I'm sure we'd lose most or all of the benefits of using StreamingKit, but it'd be much better than no support whatsoever.

doriansgithub commented 7 years ago

What is optimized?

mitchdowney commented 7 years ago

When I run afinfo on the file from the sample link above, I see the following output. Note 6 lines from the bottom where it says "not optimized":

File:           /Users/asdf/desktop/24_-_The_Psychology_of_the_Flood.m4a
File type ID:   m4af
Num Tracks:     1
----
Data format:     2 ch,  44100 Hz, 'aac ' (0x00000000) 0 bits/channel, 0 bytes/packet, 1024 frames/packet, 0 bytes/frame
Channel layout: Stereo (L R)
estimated duration: 9423.624989 sec
audio bytes: 150778818
audio packets: 405844
bit rate: 127999 bits per second
packet size upper bound: 727
maximum packet size: 727
audio data file offset: 57344
not optimized
audio 415581862 valid frames + 2112 priming + 282 remainder = 415584256
format list:
[ 0] format:      2 ch,  44100 Hz, 'aac ' (0x00000000) 0 bits/channel, 0 bytes/packet, 1024 frames/packet, 0 bytes/frame
Channel layout: Stereo (L R)
----

I wonder if this m4a file were optimized if it would load and seek correctly? Or if the issue affects all m4a files over 5:30 long regardless of optimization?


I haven't heard of m4a optimization before now, but here's someone's answer from a [message board]():

It removes all free atoms and puts moov and tags before actual data. It'll make the files smaller if there is some unused space. There might be also some programs which won't read the tag if it's located after the actual data. – Florian

That's all I know right now. I don't have the rights to optimize the files, so I'll need some kind of ability to stream non-optimized m4a files with StreamingKit.

Here's some info on what moov and atoms are:

For example a moov atom is a parent atom with no content except other atoms. mdat atoms carry the raw audio/visual stream & so have lots of content - typically the largest portion of the file. If a file is not written properly or is non-conforming, the file will either not play or become untouchable by other mpeg-4 utilities.

doriansgithub commented 7 years ago

I searched and found the same info. Other non-streaming libraries like AudioKit and Novocaine, read these files without issue. So it has to be something to do with the streaming portion of the player. We are going to implement Novocaine for the local files and use strreamkit for streaming. We obviously would rather just have streamkit, but not being able to play songs from iTunes is a game killer.

doriansgithub commented 7 years ago

Just remembered, that as per patrickjquinn, I used Audio Converter Lite, and the player plays the resulting m4a songs over 5:30, so maybe we can look into the difference between the encoding between iTunes and this converter. Also maybe look at how novocaine is treating these files.

mitchdowney commented 7 years ago

Does anyone have a link to an m4a file over 5:30 long that StreamingKit can stream successfully?

doriansgithub commented 7 years ago

Download Audio Converter light.

iDevelopper commented 7 years ago

Sorry but it is me that recommended using Audio Converter Light.

Never mind!

Does anyone have a link to an m4a file LOWER 5:30 long that StreamingKit can stream successfully?

iDevelopper commented 7 years ago

Because StreamingKit works well with some m4a when there are in local but the same file from a server does not work! It is not relative to the size or longer!

patrickjquinn commented 7 years ago

No it’s nothing to do with the size of the file, it’s down to it’s encoding, what’s in the header and how the AVAudioSesson processes it in real time. If you can get your hand on one of the YouTube m4a files you can breakpoint this issue.

On 25 Aug 2017, 17:47 +0100, Patrick notifications@github.com, wrote:

Because StreamingKit works well with some m4a when there are in local but the same file from a server don't work! It is not relative to the size or longer! — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

doriansgithub commented 7 years ago

Oops, yes, you are right, it was you that recommended AudioConverter Light, I confused patrick with you. :(

Patrick, if the size of the file has nothing to do with it, why does it play anything under 5:30?

iDevelopper commented 7 years ago

Hi @doriansgithub ,

Can you give me a link to a file that works, please? Because when I put some files to dropbox, they don't play but the same files play locally!

doriansgithub commented 7 years ago

I can't get anything to play that is over 5:31, even after using Audio Converter Lite. The only way for me to play anything over 5:31, is in the original AIFF format. This works even if the file was originally a LossLess, converted to AIFF using Audio Converter Lite.

Mp3 over 5:31, will not play.
Purchased AAC from Apple over 5:31, will not play. I also can't play Lossless at all, which I thought I couldn't get onto the phone, but I can. Apple Music player can play all of the above.

I was going to say that it can't play anything compressed, but it can't play lossless either. It can't play lossless no matter what the length of the file is.

doriansgithub commented 7 years ago

This is what I get, I'm sure everyone else is getting the same, but I'll post it anyways.

2017-08-26 10:20:38.442040-0700 Musically[918:193200] didFinishBuffering: ipod-library://item/item.m4a?id=422125328949642500 2017-08-26 10:20:38.482391-0700 Musically[918:193200] Requeuing: ipod-library://item/item.m4a?id=422125328949642500 2017-08-26 10:20:39.416581-0700 Musically[918:193466] setCurrentlyReadingEntry:andStartPlaying:clearQueue: ipod-library://item/item.m4a?id=422125328949642500 2017-08-26 10:20:39.446686-0700 Musically[918:193831] processFinishPlayingIfAnyAndPlayingNext:withNext: Finished: ipod-library://item/item.m4a?id=422125328949642500, Next: ipod-library://item/item.m4a?id=422125328949642500, buffering.count=0,upcoming.count=0 2017-08-26 10:20:39.457476-0700 Musically[918:193200] State = 5 2017-08-26 10:20:39.457699-0700 Musically[918:193200] Finished: QueueID 2017-08-26 10:20:39.512627-0700 Musically[918:193200] Started: QueueID 2017-08-26 10:20:39.515017-0700 Musically[918:193200] State = 32 2017-08-26 10:20:39.516207-0700 Musically[918:193200] Error = 4 2017-08-26 10:20:39.949266-0700 Musically[918:193200] Error = 4 2017-08-26 10:20:39.949514-0700 Musically[918:193200] Error = 4

iDevelopper commented 7 years ago

You can't play some item from iPod Library directly. You have to use AVAssetExportSession first.

iDevelopper commented 7 years ago

@doriansgithub ,

I don't understand what you want to do exactly. Play some audios from remote url, local url or from iPod Library.

Try this sample (Please open the xcworkspace and not the xcodeproj file):

STKSample.zip

I have all the cases in it (local, remote, iTunes Library), with files (mp3, m4a) over 5:30 min or lower, purchased on iTunes or imported from a CD.

All is right...

For this sample, I did not use Audio Converter Lite.

Hope it helps!

doriansgithub commented 7 years ago

Ok, I'll check that out, and so should everyone else, since they are all having the same issue. This might then might be a non-issue and just an error on everyones implementation. I'll get back when we get this going. Thanks Patrick!!

doriansgithub commented 7 years ago

I implemented AVAssetExportSession and then play exported file. I have this error: STKAudioPlayerErrorStreamParseBytesFailed.

Songs over 5:30 export to Caches folder on Phone, but it still doesn't play.

doriansgithub commented 7 years ago

I added this song to the Sample Project and it will not play. simulator screen shot sep 14 2017 1 15 29 pm

screenshot from iphone

Here is the file:

https://www.sendspace.com/file/gtc8z5

iDevelopper commented 7 years ago

It is not a duration problem as in the sample there are some songs over 5:30 who plays!