录转rtsphan

java 部分

    int  myFrameSize = 36748;
    byte[] myBuf;
    byte[] myFreameBuf ;//=  new byte[myFrameSize];
    private void recordVirtualDisplay() {
        while (!mQuit.get()) {
            int index = mediaCodec.dequeueOutputBuffer(bufferInfo, 10000);
            if (index == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {

            } else if (index >= 0) {
                boolean mbTemp = encodeToVideoTrack(index);
                mediaCodec.releaseOutputBuffer(index, false);
            }
        }
    }
    
    private boolean encodeToVideoTrack(int index) {
        ByteBuffer encodedData = mediaCodec.getOutputBuffer(index);

        int end = bufferInfo.flags
                &MediaCodec.BUFFER_FLAG_END_OF_STREAM;
        if(end!=0) return false;

        if (bufferInfo.size == 0) {
            encodedData = null;
            return false;
        }
        if (encodedData != null) {
            encodedData.position(bufferInfo.offset);
            encodedData.limit(bufferInfo.offset + bufferInfo.size);
         
            myFrameSize = encodedData.remaining();
            myFreameBuf = new byte[myFrameSize];
            encodedData.get(myFreameBuf, 0, myFreameBuf.length);
            Log.e("-----", "myFrameSize = "+myFrameSize);
            sendFrameFromJNI(myFreameBuf,myFrameSize);
            Log.e("-----", "come after sendFrameFromJNI");
 
            return false;
        }
        return false;
    }

 

 


  #define MAX_FRAME_SIZE 50*1024

  unsigned char jniFrameBuffer[MAX_FRAME_SIZE] = {0};
  int frameSize = 0;

extern
"C" JNIEXPORT jstring JNICALL Java_com_example_testrtsp_MainActivity_sendFrameFromJNI( JNIEnv* env, jobject /* this */, jbyteArray buffer, jint len ) { LOGE(" 1212 _sendFrameFromJNI len= %d", len); jboolean isCopy = true; unsigned char *pBuffer = (unsigned char *)env->GetByteArrayElements(buffer,&isCopy); memcpy(jniFrameBuffer,pBuffer,len); frameSize = len; SendFrame((char*)jniFrameBuffer,&frameSize); std::string hello = "Hello from C++"; env->ReleaseByteArrayElements(buffer,(jbyte*)pBuffer,0); return env->NewStringUTF(hello.c_str()); }

 

 

https://www.cnblogs.com/Sharley/p/5610778.html

这个有nalu

https://www.jianshu.com/p/1977d151c7dc

 

https://github.com/EricLi22/AndroidMultiMedia/releases

 

java读二进制 和cpp修改

        String path = "E:\\test.264";
        File file = new File(path);
        FileInputStream in1 = new FileInputStream(file);
        DataInputStream data_in = new DataInputStream(in1);
        int length = (int)file.length();
        byte[] itemBuf = new byte[length];
        data_in.read(itemBuf,0,length);

        data_in.close();
        in1.close();
 
posted @ 2021-12-02 20:35  cnchengv  阅读(36)  评论(0编辑  收藏  举报