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

Florian
  • 2,048
  • 3
  • 28
  • 36
  • What version of Android is in use on the devices generating the bad files? – fadden Oct 22 '14 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 '14 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). – Efe Kahraman Jan 06 '15 at 07:31

2 Answers2

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...

Efe Kahraman
  • 1,438
  • 14
  • 21
0

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

Marlon
  • 1,473
  • 11
  • 13
  • 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 '14 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 '14 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 '14 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 '14 at 04:42
  • Thank you very much, here's a link to a video I transcoded: https://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 '14 at 09:22
  • Hi Florian, one more comment not connected with the video you shared. I remember that there were something with AAC encoding on HTC One, I do not have this device available right now, but as far as I remember we were able to address this issue. Could you try to change profie to LC in the test: private static final int OUTPUT_AUDIO_AAC_PROFILE = MediaCodecInfo.CodecProfileLevel.AACObjectHE; If this does not help I will try to recall the details:) – Marlon Oct 26 '14 at 14:13
  • Hi Marlon, I've already tried didifferent Profile levels including LC, but unfortunately without success. With LC the CTS test is unable to complete the conversion. I receive a timestamp error, something like timestampX < timestampY or so. In addition I just found this issue which might be related http://stackoverflow.com/questions/22368611/inconsistent-sample-time-presentation-time-during-video-decoding – Florian Oct 28 '14 at 10:18
  • Here's the exact error I get if I switch to LC: "11-04 15:45:21.470: E/MPEG4Writer(24022): timestampUs 4906584 < lastTimestampUs 4970584 for Audio track" Did you already have time to look at the clip? – Florian Nov 04 '14 at 20:46
  • i did not find anything special in the file, it looks pretty much correct. i am trying to recall what was the issue with the same device on our side – Marlon Nov 06 '14 at 08:52