2

大多数情况下,我想知道是否存在我无法与图书馆共享相同资源的根本冲突,如果是这样,我将需要采取不同的方法。

我的目标是同时保存检测器元数据的低质量视频,这样我就可以在没有太多延迟的情况下进行一些后期处理和切片。

基于CameraDetectorDemo -相机检测器

我一直在初始化 MediaRecorder,但如果我在检测器之前启动它会保存一个黑屏,如果我在检测器之后启动它,它会在启动时崩溃(代码 -19)。检测器正在附加预览,可能与此有关。

我添加了一些按钮来控制这些功能:

protected void cameraInit() {
    String state = Environment.getExternalStorageState();
    if (!Environment.MEDIA_MOUNTED.equals(state)) {
        Log.d(LOG_TAG, "Drive not mounted - cannot write video");
        return;
    }

    File file = new File(getExternalFilesDir(Environment.DIRECTORY_MOVIES), "demo.gp3");

    Log.d(LOG_TAG, String.format("Camera Initializing. Setting output to: %s", file.getAbsolutePath()));

    // Set sources
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Set profile
    recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));

    // Set output profile
    recorder.setOutputFile(file.getAbsolutePath());

    // Set preview output
    recorder.setPreviewDisplay(cameraPreview.getHolder().getSurface());



    try {
        this.recorder.prepare();
    } catch (IOException e) {
        Log.e(LOG_TAG, "IO exception on camera Initialization");
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // This is thrown if the previous calls are not called with the
        // proper order
        Log.e(LOG_TAG, "Failed to initialize things properly :(  ");
        e.printStackTrace();
    }
}

protected void cameraStart() {
    Log.d(LOG_TAG, "Camera Start");
    this.recorder.start();
}

protected void cameraStop() {
    Log.d(LOG_TAG, "Camera Stop");
    this.recorder.stop();
}
4

1 回答 1

1

Affdex SDK 的 CameraDetector 需要访问相机以获取其预览帧并对其进行处理,因此如果 MediaRecorder 控制了相机,这将不起作用。

可能你最好的选择是从相机中获取预览帧,将它们提供给 Affdex FrameDetector 进行处理,并通过 MediaCodec 和 MediaMuxer 将它们保存到视频文件中,尽管我没有尝试过。

于 2016-07-19T11:07:35.723 回答