ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Support ape audio format

Open tangmingscau opened this issue 7 years ago • 19 comments

Why not support ape audio format? Ape format is a very important lossless format in the audio playing market. I know that supporting ape format is a necessary job.

tangmingscau avatar Jan 25 '18 07:01 tangmingscau

It looks like ffmpeg has a decoder for this format, so it might be easy to add support via the ffmpeg extension. Please could you provide some sample media?

andrewlewis avatar Jan 25 '18 08:01 andrewlewis

One caveat: although adding support for decoding via ffmpeg might be easy, if the container format is not one we support already then it's probably going to be a lot of work.

andrewlewis avatar Jan 25 '18 08:01 andrewlewis

Through this link http://google.github.io/ExoPlayer/supported-formats.html, this ffmpeg extra extended format does not contain ape, I looked up some information, ffmpeg does not contain the ape format, the format is monkey audio, I need to go to the additional extension of the monkey audio, this seems to be a lot of work. Is my idea right?

tangmingscau avatar Jan 25 '18 08:01 tangmingscau

I think the two steps required to add support are: implementing an extractor for the format, as it looks like Monkey Audio does have its own container, then updating the ffmpeg extension to expose its libavcodec/apedec.c decoder, which should be easy. It's unlikely we will get round to this soon but please feel free to send a pull request.

andrewlewis avatar Jan 25 '18 09:01 andrewlewis

Thanks for your patience, I will try to support the ape format, but my opinion is that ExoPlayer should support the ape format

tangmingscau avatar Jan 25 '18 09:01 tangmingscau

I'm trying to support ape, and now I have a weird problem, naming ffmpeg has included ape format (the value of true at FfmpegLibrary.ffmpegHasDecoder ("ape"), but when executing ffmpegInitialize, the initialization fails, there is a failed Log, you can give some Do you give me an opinion?

04-11 10:11:37.962 5752-5871/com.xiaopeng.musicradio D/FfmpegLibrary: codecName= ape hasDecoder=true
04-11 10:11:37.962 5752-5871/com.xiaopeng.musicradio D/FfmpegLibrary: codecName= ape hasDecoder=true
04-11 10:11:37.962 5752-5752/com.xiaopeng.musicradio D/MediaPlayerModel: [ main,null,onTracksChanged : 223 ] onTracksChanged: com.google.android.exoplayer2.source.TrackGroupArray@27eae99 trackSelections=com.google.android.exoplayer2.trackselection.TrackSelectionArray@ea29e339
04-11 10:11:37.972 5752-5752/com.xiaopeng.musicradio D/EventLogger: Tracks [
04-11 10:11:37.972 5752-5752/com.xiaopeng.musicradio D/EventLogger:   Renderer:2 [
04-11 10:11:37.972 5752-5752/com.xiaopeng.musicradio D/EventLogger:     Group:0, adaptive_supported=N/A [
04-11 10:11:37.972 5752-5752/com.xiaopeng.musicradio D/EventLogger:       [X] Track:0, id=null, mimeType=audio/ape, channels=2, sample_rate=44100, supported=YES
04-11 10:11:37.972 5752-5752/com.xiaopeng.musicradio D/EventLogger:     ]
04-11 10:11:37.972 5752-5752/com.xiaopeng.musicradio D/EventLogger:   ]
04-11 10:11:37.972 5752-5752/com.xiaopeng.musicradio D/EventLogger: ]
04-11 10:11:38.012 5752-5874/com.xiaopeng.musicradio D/dalvikvm: GC_FOR_ALLOC freed 1873K, 18% free 9212K/11140K, paused 40ms, total 40ms
04-11 10:11:38.012 5752-5752/com.xiaopeng.musicradio D/EventLogger: audioEnabled [0.22]
04-11 10:11:38.012 5752-5871/com.xiaopeng.musicradio E/ffmpeg_jni: Error in avcodec_open2: Invalid argument
04-11 10:11:38.052 5752-5874/com.xiaopeng.musicradio D/dalvikvm: GC_FOR_ALLOC freed 1761K, 24% free 9273K/12084K, paused 33ms, total 33ms
04-11 10:11:38.052 5752-5871/com.xiaopeng.musicradio E/ExoPlayerImplInternal: Renderer error.
                                                                              com.google.android.exoplayer2.ExoPlaybackException
                                                                                  at com.google.android.exoplayer2.audio.SimpleDecoderAudioRenderer.maybeInitDecoder(SimpleDecoderAudioRenderer.java:572)
                                                                                  at com.google.android.exoplayer2.audio.SimpleDecoderAudioRenderer.onInputFormatChanged(SimpleDecoderAudioRenderer.java:618)
                                                                                  at com.google.android.exoplayer2.audio.SimpleDecoderAudioRenderer.render(SimpleDecoderAudioRenderer.java:230)
                                                                                  at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:560)
                                                                                  at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:306)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                                  at android.os.Looper.loop(Looper.java:136)
                                                                                  at android.os.HandlerThread.run(HandlerThread.java:61)
                                                                               Caused by: com.google.android.exoplayer2.ext.ffmpeg.FfmpegDecoderException: Initialization failed.
                                                                                  at com.google.android.exoplayer2.ext.ffmpeg.FfmpegDecoder.<init>(FfmpegDecoder.java:62)
                                                                                  at com.google.android.exoplayer2.ext.ffmpeg.FfmpegAudioRenderer.createDecoder(FfmpegAudioRenderer.java:106)
                                                                                  at com.google.android.exoplayer2.ext.ffmpeg.FfmpegAudioRenderer.createDecoder(FfmpegAudioRenderer.java:35)
                                                                                  at com.google.android.exoplayer2.audio.SimpleDecoderAudioRenderer.maybeInitDecoder(SimpleDecoderAudioRenderer.java:565)
                                                                                  at com.google.android.exoplayer2.audio.SimpleDecoderAudioRenderer.onInputFormatChanged(SimpleDecoderAudioRenderer.java:618) 
                                                                                  at com.google.android.exoplayer2.audio.SimpleDecoderAudioRenderer.render(SimpleDecoderAudioRenderer.java:230) 
                                                                                  at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:560) 
                                                                                  at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:306) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:98) 
                                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                                  at android.os.HandlerThread.run(HandlerThread.java:61)

tangmingscau avatar Apr 11 '18 02:04 tangmingscau

The relevant log line is E/ffmpeg_jni: Error in avcodec_open2: Invalid argument. I suggest looking through the code for that function in libavcodec/utils.c and perhaps adding some more logging to diagnose the cause of the failure.

andrewlewis avatar Apr 11 '18 05:04 andrewlewis

When is the APE format supported?

3-BodyCoding avatar Jan 17 '20 07:01 3-BodyCoding

This issue is marked low priority. We don't have any plans to add support at the moment.

andrewlewis avatar Jan 17 '20 11:01 andrewlewis

Thanks for your patience, I will try to support the ape format, but my opinion is that ExoPlayer should support the ape format

Hi,have you implemented support for ape format ?could you provide a demo? thanks

ZhangHui0608 avatar Dec 01 '20 01:12 ZhangHui0608

This is Matt Ashland, the author of Monkey's Audio. Just know I would love to see Exo add APE support. The APE SDK builds on Android, but doing it with ffmpeg would be great too. Please write mail at monkeysaudio dot com if you want any help. Thanks.

MattAshland avatar Dec 02 '20 15:12 MattAshland

@tangmingscau Hi, Have you find solution for ape format yet?

zengqiang24 avatar Jan 20 '21 03:01 zengqiang24

Last post was almost a year ago. I would still love to see an APE plugin. Like I said, the APE SDK builds on Android (we do this at JRiver). I'm happy to help if needed. I'm mail at monkeysaudio dot com. Thanks.

MattAshland avatar Oct 01 '21 19:10 MattAshland

how to support ape with ffmpeg? please help me

firsthubgit avatar Jun 15 '22 06:06 firsthubgit

Hi there,

APE is supported by FFMpeg.

Here are a couple links:

https://askubuntu.com/questions/376684/how-to-use-ffmpeg-to-convert-ape-to-mp3

https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/ape.c

Cheers, Matt

MattAshland avatar Jun 15 '22 10:06 MattAshland

Hi there,

APE is supported by FFMpeg.

Here are a couple links:

https://askubuntu.com/questions/376684/how-to-use-ffmpeg-to-convert-ape-to-mp3

https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/ape.c

Cheers, Matt

How to make exoplayer support ape? my music player use the exoplayer to play music~~~

firsthubgit avatar Jun 15 '22 14:06 firsthubgit

That's what I'm asking for here. The APE format has been around for over 20 years and compresses better than any alternative. The APE SDK builds fine on Android. I just need someone to connect the dots.

MattAshland avatar Jun 15 '22 14:06 MattAshland

Hi there,

APE is supported by FFMpeg.

Here are a couple links:

https://askubuntu.com/questions/376684/how-to-use-ffmpeg-to-convert-ape-to-mp3

https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/ape.c

Cheers, Matt

Hi Matt,

I developed a new ApeExtractor for ExoPlayer, and proved that it works with media3-lib-decoder-ffmpeg.

I'm currently facing an issue with the APE frame size. My question is: Should I split the APE frame data stored in the file into smaller pieces? Is it possible to split it?

I see that the frame data block is stored in little-endian order and is 4-byte aligned with offset information. It also includes a CRC checksum value and a block count.

The total data bytes in a single frame seem too large for both the input buffer and the output render buffer. For version 3950, the sample blocks can reach up to 73728 * 4 per frame, meaning the raw output size is approximately 1,179,648 bytes for 16-bit stereo audio. Given a compression ratio of about 2.0, the encoded input size is roughly half of that.

If splitting the frame data isn't feasible, we might need to consider increasing the ExoPlayer buffer size as a workaround. However, that feels a bit hacky. We should probably explore more elegant options if possible.

Cheers, Will

shenwill avatar Feb 28 '25 04:02 shenwill

Thanks! That's great news!

APE frame size can be kind of large, especially at higher compression levels because that helps compression.

This is the code for blocks per frame: // initialize (creates the base classes) m_nBlocksPerFrame = 73728; if (nCompressionLevel == APE_COMPRESSION_LEVEL_EXTRA_HIGH) m_nBlocksPerFrame *= 4; else if (nCompressionLevel == APE_COMPRESSION_LEVEL_INSANE) m_nBlocksPerFrame *= 16;

Everything really wants to work a block at a time.

Could you extract to a working buffer that you keep yourself then copy out of that into the ExoPlayer buffer?

Does anybody else have any other ideas?

Thanks!

MattAshland avatar Feb 28 '25 09:02 MattAshland