Mediacodec and camera, color space incorrect

前端 未结 2 1666
春和景丽
春和景丽 2021-02-03 14:59

By referring Aegonis\'s work 1 and work 2, I also got the H.264 stream , but the color is not correct. I am using HTC Butterfly for development. Here is part of my code:

2条回答
  •  醉梦人生
    2021-02-03 15:26

    Got it, now the color looks good, the test is based on HTC Butterfly. When set the resolution to 320x240, your color transform should looks like:

        System.arraycopy(input, 0, output, 0, frameSize);
        for (int i = 0; i < (qFrameSize); i++) {  
            output[frameSize + i*2] = (input[frameSize + qFrameSize + i - 32 - 320]);  
            output[frameSize + i*2 + 1] = (input[frameSize + i - 32 - 320]);            
        }
    

    for resolution 640x480 and above,

    System.arraycopy(input, 0, output, 0, frameSize);    
        for (int i = 0; i < (qFrameSize); i++) {  
            output[frameSize + i*2] = (input[frameSize + qFrameSize + i]);  
            output[frameSize + i*2 + 1] = (input[frameSize + i]);   
        } 
    

    For the frame rate issue, we can use the getSupportedPreviewFpsRange() to check the supported frame rate range of our device as:

    List fpsRange = parameters.getSupportedPreviewFpsRange();
    for (int[] temp3 : fpsRange) {
    System.out.println(Arrays.toString(temp3));}
    

    And the following setting works correct when play the encoded H.264 ES,

    parameters.setPreviewFpsRange(29000, 30000);    
    //parameters.setPreviewFpsRange(4000,60000);//this one results fast playback when I use the FRONT CAMERA 
    

提交回复
热议问题