cats-oss / android-gpuimage

Android filters based on OpenGL (idea from GPUImage for iOS)
9.01k stars 2.27k forks source link

How to record the original video? #437

Closed stonyz closed 5 years ago

stonyz commented 6 years ago

I use GPUImage to preview. and want to record the original video from camera.

The problem is, once I start recording, the preview will stop.

Preview in GPUImage, mGPUImage.setUpCamera(camera, orientation, flipHorizontal, false);

it works fine.

Once I start recording, the preview will stop and can't recover even I stoped recording. and has no any exception. and I noticed that GPUImageRenderer.onPreviewFrame isn't called when preview stopped.

private void startRecordVideo(String videoFile) {
        if (true) {
//          return;
        }
        if (camera == null) {
            Log.e(TAG, "startRecordVideo, camera is not open. file: " + videoFile );
            return;
        }
        if (mRecorder == null) {
            mRecorder = new MediaRecorder();
        }
        try {
            mRecorder.reset();

            camera.unlock();
            mRecorder.setCamera(camera);

            mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

            // Set output file format
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
            mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

            mRecorder.setVideoSize(640, 480);
            mRecorder.setVideoFrameRate(30);
            mRecorder.setVideoEncodingBitRate(Double.valueOf(1.8 * 1024 * 1024).intValue());
            mRecorder.setOrientationHint(90);

            mRecorder.setMaxDuration(30 * 1000);
//          mRecorder.setPreviewDisplay(cameraSurfaceView);
            Log.d(TAG, "record: path " + videoFile);

            mRecorder.setOutputFile(videoFile);
            mRecorder.prepare();
            mRecorder.start();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
stonyz commented 5 years ago

Fixed it, by switching camera2.

nikunjparadva commented 4 years ago

Hello @stonyz Can you enter the code of camera2 Integration.. It ll be more helpful to me.