I am transcoding videos based on the example given by Google (https://android.googlesource.com/platform/cts/+/master/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java)
Basically, transocding of MP4 files works, but on some phones I get some weird results. If for example I transcode a video with audio on an HTC One, the code won't give any errors but the file cannot play afterward on the phone. If I have a 10 seconds video it jumps to almost the last second and you only here some crackling noise. If you play the video with VLC the audio track is completely muted.
I did not alter the code in terms of encoding/decoding and the same code gives correct results on a Nexus 5 or MotoX for example.
Anybody having an idea why it might fail on that specific device?
Best regard and thank you, Florian
I made it work in Android 4.4.2 devices by following changes:
private static final int OUTPUT_AUDIO_AAC_PROFILE = MediaCodecInfo.CodecProfileLevel.AACObjectLC;
MediaFormat outputAudioFormat = MediaFormat.createAudioFormat(OUTPUT_AUDIO_MIME_TYPE, inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), inputFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT));
timestampUs X < lastTimestampUs X for Audio track
error)if (audioPresentationTimeUsLast == 0) { // Defined in the begining of method audioPresentationTimeUsLast = audioEncoderOutputBufferInfo.presentationTimeUs; } else { if (audioPresentationTimeUsLast > audioEncoderOutputBufferInfo.presentationTimeUs) { audioEncoderOutputBufferInfo.presentationTimeUs = audioPresentationTimeUsLast + 1; } audioPresentationTimeUsLast = audioEncoderOutputBufferInfo.presentationTimeUs; } // Write data if (audioEncoderOutputBufferInfo.size != 0) { muxer.writeSampleData(outputAudioTrack, encoderOutputBuffer, audioEncoderOutputBufferInfo); }
Hope this helps...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With