1

I am rendering an Mpeg4/avc video on android using the MediaCodec (and MediaMuxer).

I'm testing on both LG Nexus 4 & Samsung Galaxy 5.

On samsung, the rendered video looks as expected for both 640x640 and 480x480 frame size.

BUT, on the Nexus, 480x480 generates a bad looking video, while the 640x640 generates a good video.

Quesion is: what is the reason? is this a bug or a "feature" I am not aware of.

Is there a well-known frame size we can rely on being rendered correcly on all Android Device? Or do we need to test on various devices?

Guy
  • 12,250
  • 6
  • 53
  • 70

2 Answers2

3

Regarding " well-known frame size" - google ask for device vendors to satisfy requirements - http://source.android.com/compatibility/index.html, doc is here: http://static.googleusercontent.com/media/source.android.com/en//compatibility/android-cdd.pdf It has codecs section 5 (5.2 and 5.3 for exact values)where you can find codecs related reqs. To check it google provides CTS tests which covers all required resolution. So the advice is to stick to resolutions from this doc and covered by CTS tests

Marlon
  • 1,473
  • 11
  • 13
  • Thank you. I just tried the 480x360 @ 30fps which appears in the doc you linked, and still getting the same bad video. In the meanwhile, I have also tested Nexus 5 and Nexus 7 - they all behave okay. – Guy Jul 01 '14 at 10:47
  • 1
    what memory do you use between decoder and encoder? color format? – Marlon Jul 01 '14 at 12:50
  • ByteBuffer with the Surface color format. Note: Does it matter? other frame sizes work well. Also same frame sizes work well on 3 different phone models. In fact, I just ran the EncodeDecodeTest from CTS on this configuration, and it failed. So it seems that Google's own Nexus 4 does not pass Android compatibility tests :) I guess my only real option is to run some visual checks, similar to what CTS does, in runtime, to determined if the profile I want to use is good or not. I am probably missing something. – Guy Jul 01 '14 at 13:03
  • if CTS test fails there is nothing to do i think, only wait for system update:) can you try 720x480, 1280x720? all resolutions fail? – Marlon Jul 01 '14 at 13:07
  • Both 720x480 and 1280x720 work well. Correction to previous comment: It seems that all frame sizes that appear in the CTS test actually pass. The 480x480 is not in the CTS tests, and fail. If I want to use it, I need to verify myself, I guess. – Guy Jul 01 '14 at 13:09
  • yes, use resolutions from the reqs or add extra logic\risks – Marlon Jul 01 '14 at 13:21
1

With Lollipop Google added an API to query the video properties of the encoder. See http://developer.android.com/reference/android/media/MediaCodecInfo.VideoCapabilities.html

Here is an example for enumerating the capabilities of the H.264 encoders available:

for(MediaCodecInfo codecInfo : new MediaCodecList(MediaCodecList.ALL_CODECS).getCodecInfos()){
    if(!codecInfo.isEncoder())
                continue;
    String[] types = codecInfo.getSupportedTypes();
    for(int j=0;j<types.length;j++){
        if("video/avc".equalsIgnoreCase(types[j])){
            MediaCodecInfo.CodecCapabilities codecCaps = codecInfo.getCapabilitiesForType("video/avc");
            MediaCodecInfo.VideoCapabilities vidCaps = codecCaps.getVideoCapabilities();
            Range<Integer> framerates = vidCaps.getSupportedFrameRates();
            Range<Integer> widths = vidCaps.getSupportedWidths();
            Range<Integer> heights = vidCaps.getSupportedHeights();
            Log.d("H.264Encoder", "Found encoder with\n" + widths.toString()
                            + " x " + heights.toString() + " @ " + framerates.toString() + " fps aligned to " + vidCaps.getWidthAlignment());
        }
    }
}
Johnny
  • 41
  • 2