How to generate the AAC ADTS elementary stream with Android MediaCodec

I finally generated AAC files that are playable on both the Android device and the Windows host computer. I am posting my solution here, hoping it could help others. First, my previous assumption that the Android MediaCodec encoder generates the elementary AAC stream was not accurate. The MediaCodec encoder generates the raw AAC stream. That’s … Read more

PCM -> AAC (Encoder) -> PCM(Decoder) in real-time with correct optimization

After testing this is what I came up with from modifying your code: package com.example.app; import android.app.Activity; import android.media.AudioManager; import android.media.MediaCodecInfo; import android.media.MediaFormat; import android.os.Bundle; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.AudioTrack; import android.media.MediaCodec; import android.media.MediaRecorder.AudioSource; import android.util.Log; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketAddress; import java.net.SocketException; import java.nio.ByteBuffer; public class MainActivity extends … Read more

How to reduce latency in MediaCodec video/avc decoding

I think you’re seeing some effects unique to the first frame. I repeated your experiment, with the further addition of forcing doRender = false around line 244 to avoid the sleep calls used to manage the output frame rate. I see: 01-29 14:05:36.552 9115 9224 I Grafika : queueInputBuffer index/pts, 2,0 01-29 14:05:36.562 9115 9224 … Read more