0

I am using the OpenCV 3.1 Library for Android in my project to process images and compile a video file on basis of several individual OpenCv::Mat.

My problem is to find the correct fourCC code. Using "MJPG" works fine on a Google Nexus 6P (Android 7.0) but not on a Nexus 4 (5.1.1) or a Galaxy A3 (6.0.1).

In the code, images is an Array containing the image data as bytearrays.

VideoWriter videoWriter = new VideoWriter(filePath, VideoWriter.fourcc('M','J','P','G'), FPS, new Size(w,h));
videoWriter.open(filePath, VideoWriter.fourcc('M','J','P','G'), FPS, new Size(w,h));

for (int i = 0; i < images.size(); i++) {
     byte[] image = images.get(i);
     Mat rgbMat = new Mat(h,w,CvType.CV_8UC3);
     rgbMat.put(0,0,image);

     videoWriter.write(rgbMat);
     rgbMat.release();

}

videoWriter.release();

As I said, I get a valid .avi file on the Nexus 6P but a corrupt file on the other phones. I know that the rest of my pipeline is working on all phones because I can save single images without a problem (not using OpenCV).

My question: Is there a fourCC code that should work on any phone, independent of the manufacturer?

I tried with no success: 'MPEG', 'MP4V', 'PIM1'

Thank you for your help!

4

2 回答 2

1

如果您在 onCameraFrame 中使用 mVideoWriter 覆盖,它每次都会初始化,因此使用下面提到的一些条件。

 if (mVideoWriter == null) {
            mVideoWriter = new VideoWriter();
            Log.d(TAG, "mVideoWriter good : " + mVideoWriter);
            mVideoWriter.open(file_path.toString() + "/" + System.currentTimeMillis() + ".avi", VideoWriter.fourcc('M', 'J', 'P', 'G'), 30.0, mRgba.size());
            Log.i(TAG, "onCameraFrame: recordFilePath");


        }
        if (!mVideoWriter.isOpened()) {
            Log.w(TAG, "onCameraFrame: open");
            mVideoWriter.open(path.toString() + "/" + System.currentTimeMillis() + ".avi", VideoWriter.fourcc('M', 'J', 'P', 'G'), 30.0, mRgba.size());

        }
于 2019-03-29T13:36:09.263 回答
0

问题是 Android 中的 VideoWriter 仅支持 .avi 格式。这是一个示例解决方案。

if (videoWriter.isOpened() == false) {
    Log.w("wewe", "som tu OPEN");
    videoWriter.open("/sdcard/movies/video.avi", VideoWriter.fourcc('M', 'J', 'P', 'G'), 25.0D, colorMat.size());
} else {
    videoWriter.write(colorMat);
}
于 2019-04-04T15:30:04.603 回答