Note that there are some explanatory texts on larger screens.

plurals
  1. PODecode AAC to PCM with ffmpeg on android
    primarykey
    data
    text
    <p>I have built ffmpeg 0.8.12 (love) with the android NDK (r8c) on ubuntu. I then use the generated library in another android application through JNI.</p> <p>Essentially what I want to do is pass a byte stream from java to my c jni function and use ffmpeg to decode it into a PCM audio buffer which will then be passed back to java to be played using Android's AudioTrack. I can successfully pass the buffer through to jni (have checked the values) and ffmpeg seems to initialise correctly, but when it tries to decode the first frame, it throws an error in the aac_decode_frame_int method in aacdec.c "channel element 0.0 is not allocated". The aac file plays fine and is valid.</p> <p>Here is my jni code to do the decoding</p> <pre><code>jint Java_com_example_testffmpeg_MainActivity_decodeAacBytes(JNIEnv * env, jobject this, jbyteArray input, jint numBytes) { //copy bytes from java jbyte* bufferPtr = (*env)-&gt;GetByteArrayElements(env, input, NULL); uint8_t inputBytes[numBytes + FF_INPUT_BUFFER_PADDING_SIZE]; memset(inputBytes, 0, numBytes + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(inputBytes, bufferPtr, numBytes); (*env)-&gt;ReleaseByteArrayElements(env, input, bufferPtr, 0); av_register_all(); AVCodec *codec = avcodec_find_decoder(CODEC_ID_AAC); if (codec == NULL) { LOGE("Cant find AAC codec\n"); return 0; } LOGI("AAC codec found\n"); AVCodecContext *avCtx = avcodec_alloc_context(); if (avCtx == NULL) { LOGE("Could not allocate codec context\n"); return 0; } LOGI("codec context allocated\n"); if (avcodec_open2(avCtx, codec, NULL) &lt; 0) { LOGE("Could not open codec\n"); return 0; } LOGI("AAC codec opened"); //the input buffer AVPacket avPacket; av_init_packet(&amp;avPacket); LOGI("AVPacket initialised\n"); avPacket.size = numBytes; //input buffer size avPacket.data = inputBytes; // the input buffer int outSize; int len; uint8_t *outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); while (avPacket.size &gt; 0) { outSize = AVCODEC_MAX_AUDIO_FRAME_SIZE; len = avcodec_decode_audio3(avCtx, (short *) outbuf, &amp;outSize, &amp;avPacket); if (len &lt; 0) { LOGE("Error while decoding\n"); return 0; } if (outSize &gt; 0) { LOGI("Decoded some stuff\n"); } avPacket.size -= len; avPacket.data += len; } LOGI("Freeing memory\n"); av_free_packet(&amp;avPacket); avcodec_close(avCtx); av_free(avCtx); return 0; } </code></pre> <p>The problem occurs in the call to avcodec_decode_audio3, when the decoding first occurs. I have stepped through the ffmpeg code, but can't find the problem. Any help would be greatly appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload