How to change Android MediaCodec video orientation

2.2k views Asked by At

I'm using libstreaming (https://github.com/fyhertz/libstreaming) for my live video streaming but the orientation of the video is always in landscape orientation at the receiver(server) side. I tried rotating my byte using the rotateYUV420Degree90(data,mQuality.resX,mQuality.resY) but the issue has not solved. I'm attaching the code used the libstreaming library for converting the byte below.

 public byte[] convert(byte[] data) {

    // A buffer large enough for every case
    if (mBuffer==null || mBuffer.length != 3*mSliceHeight*mStride/2+mYPadding) {
        mBuffer = new byte[3*mSliceHeight*mStride/2+mYPadding];
    }

    if (!mPlanar) {
        if (mSliceHeight==mHeight && mStride==mWidth) {
            // Swaps U and V
            if (!mPanesReversed) {
                for (int i = mSize; i < mSize+mSize/2; i += 2) {
                    mBuffer[0] = data[i+1];
                    data[i+1] = data[i];
                    data[i] = mBuffer[0]; 
                }
            }
            if (mYPadding>0) {
                System.arraycopy(data, 0, mBuffer, 0, mSize);
                System.arraycopy(data, mSize, mBuffer, mSize+mYPadding, mSize/2);
                return mBuffer;
            }
            return data;
        }
    } else {
        if (mSliceHeight==mHeight && mStride==mWidth) {
            // De-interleave U and V
            if (!mPanesReversed) {
                for (int i = 0; i < mSize/4; i+=1) {
                    mBuffer[i] = data[mSize+2*i+1];
                    mBuffer[mSize/4+i] = data[mSize+2*i];
                }
            } else {
                for (int i = 0; i < mSize/4; i+=1) {
                    mBuffer[i] = data[mSize+2*i];
                    mBuffer[mSize/4+i] = data[mSize+2*i+1];
                }
            }
            if (mYPadding == 0) {
                System.arraycopy(mBuffer, 0, data, mSize, mSize/2);
            } else {
                System.arraycopy(data, 0, mBuffer, 0, mSize);
                System.arraycopy(mBuffer, 0, mBuffer, mSize+mYPadding, mSize/2);
                return mBuffer;
            }
            return data;
        }
    }

    return data;
}   

Is there any way to handle the camera orientation or the recorded video orientation. Please do help me resolve the issue.

0

There are 0 answers