如何更改Android MediaCodec视频方向

时间:2014-11-12 10:33:26

标签: android video android-camera wowza libstreaming

我正在使用libstreaming(https://github.com/fyhertz/libstreaming)进行直播视频直播,但视频的方向始终在接收方(服务器)方面横向显示。我尝试使用rotateYUV420Degree90(data,mQuality.resX,mQuality.resY)旋转我的字节,但问题仍未解决。我附加了使用libstreaming库的代码来转换下面的字节。

 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;
}   

有没有办法处理相机方向或录制的视频方向。请帮我解决这个问题。

0 个答案:

没有答案