5

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

3
  • What version of Android is in use on the devices generating the bad files?
    – fadden
    Oct 22, 2014 at 15:45
  • It's Android 4.4.2, on both the Nexus 5 where the code is working and on the HTC One where it does not work. By the way, it even works on a Motorola Moto X with Android 4.4.2.
    – Florian
    Oct 23, 2014 at 12:26
  • Hi, I see the same results for some 4.4.2 devices too. On the other hand, example code works fine on Samsung Galaxy S3 (4.3). Jan 6, 2015 at 7:31

2 Answers 2

8

I made it work in Android 4.4.2 devices by following changes:

  • Set AAC profile to AACObjectLC instead of AACObjectHE
private static final int OUTPUT_AUDIO_AAC_PROFILE = MediaCodecInfo.CodecProfileLevel.AACObjectLC;
  • During creation of output audio format, use sample rate and channel count of input format instead of fixed values
MediaFormat outputAudioFormat = MediaFormat.createAudioFormat(OUTPUT_AUDIO_MIME_TYPE,
inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE),
inputFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT));
  • Put a check just before audio muxing audio track to control presentation timestamps. (To avoid 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...

2
  • Thank you for your help. One more thing, where's the skipFrame variable coming from and where do you set it?
    – Florian
    Feb 5, 2015 at 7:20
  • Hi, you can discard it, it's useless. I revised the code snipped. Sorry for confusion. Feb 5, 2015 at 8:45
0

If original CTS tests fail you need to go to device vendors and ask for fixes

9
  • The thing is, the tests do not actually fail or throw errors. The outcome is just weird, so videos have corrupt audio tracks on that specific platform. I compared the log output (buffers, presentation times, etc) between two different phones, they are exactly the same. However, the resulting video of one device works, the video of the other one doesn't...
    – Florian
    Oct 22, 2014 at 15:22
  • // TODO: Check the generated output file. - this test does not have output file check so why device vendors may not detect the issue
    – Marlon
    Oct 22, 2014 at 15:30
  • Yes, you are probably right. Still, it would be good to find the root cause of this issue. I am just trying to understand where the error is coming from.
    – Florian
    Oct 23, 2014 at 13:53
  • Morelikely the error is coming from MediaCodec encoder. To understand what's wrong you need to analyze output file\bitstream. I recommend you to start with Elecard Stream Eye tool. Also please share the output file, i will take a look on it
    – Marlon
    Oct 24, 2014 at 4:42
  • Thank you very much, here's a link to a video I transcoded: dl.dropboxusercontent.com/u/12647354/Test%20Upload.mp4 The source video plays normal, after transcoding it with the CTS test, I receive the provided result.
    – Florian
    Oct 26, 2014 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.