Search code examples
androidaudioandroid-mediacodecmediamuxer

Issues encoding audio with Mediacodec and Motorola mobile


I have been able to implement a video/audio decoder and encoder. On my Samsung S3, everything works fine. Then I deployed into a Samsung, and I had some rotation issues I have fixed, but the final encoded video does not have audio. When I stop the mediamuxer I get the following log:

01-29 12:35:26.372 I/MPEG4Writer(23222): Received total/0-length (27/0) buffers and encoded 27 frames. - video
01-29 12:35:26.374 D/MPEG4Writer(23222): Stopping Audio track
01-29 12:35:26.376 I/MPEG4Writer(23222): Received total/0-length (4/82) buffers and encoded 4 frames. - audio
01-29 12:35:26.376 I/MPEG4Writer(23222): Audio track drift time: 0 us
01-29 12:35:26.377 D/MPEG4Writer(23222): Stopping Audio track source
01-29 12:35:26.377 D/MPEG4Writer(23222): Audio track stopped
01-29 12:35:26.377 D/MPEG4Writer(23222): Stopping Video track
01-29 12:35:26.377 D/MPEG4Writer(23222): Stopping Video track source
01-29 12:35:26.377 D/MPEG4Writer(23222): Video track stopped
01-29 12:35:26.378 D/MPEG4Writer(23222): Stopping Audio track
01-29 12:35:26.378 D/MPEG4Writer(23222): Duration from tracks range is [80000, 1772500] us
01-29 12:35:26.378 D/MPEG4Writer(23222): Stopping writer thread
01-29 12:35:26.379 D/MPEG4Writer(23222): 1 chunks are written in the last batch
01-29 12:35:26.380 D/MPEG4Writer(23222): Writer thread stopped
01-29 12:35:30.212 D/MPEG4Writer(23222): Stopping Video track
01-29 12:35:30.212 D/MPEG4Writer(23222): Stopping Audio track

I guess is something related to the 4/82 buffers and only 4 frames encoded. I have written into the muxer all the buffers I got from the decoder, which I think there are the 82 buffers. The presentationTime and flags are the same which I get from the decoder. As I said, this code works on my Samsung S3. Do you have any ideas which would be my issue? could it be the bitrate? thanks.


Solution

  • I have found that the byteBuffers in some cases got with Position=Limit, so, I had to set Position(info.Offset), Limit(info.Offset+info.Size), like it is in many examples (e.g grafika). Bescause of that, I had been encoding 0-length buffer, but only 4 with data. Without that, this was working fine in my Samsung but not in the Motorola mobile. thanks