rust-mobile/ndk

AMediaExtractor and MediaCodec

ruichaowang opened this issue ยท 4 comments

Dear Experts,

I hope this message finds you well. I am currently encountering a couple of issues related to the usage of AMediaExtractor and MediaCodec and seeking for your guidance.

The first question is regarding the "Safe abstraction of the AMediaExtractor". I'm wondering if there is a specific reason as to why this does not exist? Are there perhaps alternative methods that could act as a suitable replacement?

The second question revolves around the running modes of MediaCodec. I found that MediaCodec operates normally in synchronous mode but not in asynchronous mode. Could you kindly guide me as where I might locate detailed usage documentation related to these modes?

I would really appreciate any help or insights you could provide on these topics.

Thank you very much for your time and assistance.

Best regards,

The first question is regarding the "Safe abstraction of the AMediaExtractor". I'm wondering if there is a specific reason as to why this does not exist? Are there perhaps alternative methods that could act as a suitable replacement?

No reason, other than "it hasn't been built yet". And most likely no-one dares to submit one if you look at my track record for being pedantic and complete in my own additions about new bindings in recent PRs.

The second question revolves around the running modes of MediaCodec. I found that MediaCodec operates normally in synchronous mode but not in asynchronous mode. Could you kindly guide me as where I might locate detailed usage documentation related to these modes?

Asynchronous notifications were contributed in #410 and should be available in the 0.8.0-beta.0 release. This should all be promoted to stable later this week.
Not sure if that's enough for "asynchronous mode" as I have zero experience with AMediaCodec. If necessary, @spencercw or @zarik5 might help you out? Looks like that's all that's needed.

Fwiw the bindings look trivial/minimal enough that I might as well PR them if I get to sit down comfortably for an hour or so :). But for the time being you can use the raw bindings from ndk-sys as a temporary "workaround".

The problem with AMediaExtractor is that it seems to require a seekable source, which mine isn't. I have full control over the input so it was easier to just manually construct the AMediaFormat with the required parameters. If you need something that works more generally then getting AMediaExtractor to work is probably the best option. Failing that you may be able to use something like ffmpeg to extract the metadata required to build the AMediaFormat.

If you haven't seen it already, the Java MediaCodec documentation is much more detailed than the NDK documentation, and the API is quite similar.

Reopening this to track adding bindings for AMediaExtractor, which is now almost done on a local branch.