Yahweasel / libav.js

This is a compilation of the libraries associated with handling audio and video in ffmpeg—libavformat, libavcodec, libavfilter, libavutil, libswresample, and libswscale—for emscripten, and thus the web.
291 stars 18 forks source link

AAC Fixed support #2

Closed BobbyShoe closed 3 years ago

BobbyShoe commented 3 years ago

@Yahweasel thank you for the pre-built files. They are really close to working for me. I am running into one issue now. It looks like the aac_fixed decoder is not included in any of the variant builds. Any chance that could be added, or is already in one and I missed it?

Basically calling libav.avcodec_find_decoder_by_name("aac_fixed")

will not return a codec.

Interestingly libav.avcodec_find_decoder(86018)

86018 corresponds to AVCodecID.AV_CODEC_ID_AAC

will return a codec, however it does not really work. You can only send in one packet all calls to get a frame return an EOF message as do all subsequent calls to add a packet.

Thanks, Bobby

Yahweasel commented 3 years ago

The configs don't have aac_fixed, only aac. However, upon examination, indeed, it doesn't seem willing to decode (my tests happen not to cover that case, since my actual use is concerned with encoding AAC, not decoding AAC, but I'll add a test for it). I'll investigate.

Yahweasel commented 3 years ago

Aha, never mind: AAC decoding works fine, it's just a codec that needs codecpar to decode properly. You'll either need to build a codecpar or get one from your demuxer.

BobbyShoe commented 3 years ago

Do you mean setting the values on the context? I had modified the test-decode-audio.js test to try decoding aac. I am setting context settings like this to provide decode information.

libav.AVCodecContext_sample_rate_s(c, 48000); libav.AVCodecContext_sample_fmt_s(c, 8); libav.AVCodecContext_channels_s(c, 2);

I have this similar logic decoding the same stream in a C# project using the same calls.

BobbyShoe commented 3 years ago

If it helps here is the simple test I am using. I am looking for the aac file in c:\Temp in the test. You can easily move that around if needed.

test-decode-audio-aac.zip

Yahweasel commented 3 years ago

You say that similar code works in a C# version? The problem, as far as I'm aware, isn't the decoder, but the (lack of) demuxer: .aac files have a header before the raw AAC data, so they do require a demuxing step to be read correctly, or at least for the header to be stripped off. None of the variants support demuxing .aac files, only .m4a/.mp4 files.

BobbyShoe commented 3 years ago

I tried again with an m4a file (attached in zip), I also fixed HTML file to go back to "default" variant. I am still getting the EOF error message as soon as I try get a frame out. Does this file work in any of your tests?

test-decode-audio-aac_withm4a.zip

Thanks for the help.

Yahweasel commented 3 years ago

It works fine with, e.g., test-demuxing-aac-simple.js (the test I just added for demuxing + decoding AAC). The issue with your code is that it's not demuxing.

BobbyShoe commented 3 years ago

@Yahweasel can you share your new test? I tried modifying the opus demuxing test, but it did not work with an AAC file. Thanks.

Yahweasel commented 3 years ago

Argh, I added it but forgot to git push @_@. Here it is: https://github.com/Yahweasel/libav.js/blob/master/tests/test-demuxing-aac-simple.js

BobbyShoe commented 3 years ago

@Yahweasel thank you for the test sample. Using the test case as a guide, I eventually found the main source of all of my problems. I did not await the ff_set_packet function call in an async method, so my buffer was not actually being set on the packet.