簡體   English   中英

CameraX 視頻錄制凍結並生成空視頻文件

[英]CameraX video recording freezes and generates empty video file

我使用以下兩種情況(預覽+視頻捕獲)使用 CameraX 實現了視頻錄制,如下所示:

@SuppressLint("RestrictedApi")
    @Override
    public android.view.View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        executor = Executors.newSingleThreadExecutor();
        android.view.View rootView = super.onCreateView(inflater, container, savedInstanceState);
        PreviewView previewView = rootView.findViewById(R.id.camera);
        ImageView capture = rootView.findViewById(R.id.capture);

        ListenableFuture<ProcessCameraProvider> cameraProviderFuture =
                ProcessCameraProvider.getInstance(getActivity());

        cameraProviderFuture.addListener(() -> {
            try {
                // Camera provider is now guaranteed to be available
                ProcessCameraProvider cameraProvider = cameraProviderFuture.get();

                // Set up the view finder use case to display camera preview
                Preview preview = new Preview.Builder().build();

                // Set up the capture use case to allow users to take photos
                videoCapture = new VideoCapture.Builder()
                        .setVideoFrameRate(30).setTargetAspectRatio(AspectRatio.RATIO_4_3)
                        .build();

                // Choose the camera by requiring a lens facing
                CameraSelector cameraSelector = new CameraSelector.Builder()
                        .requireLensFacing(CameraSelector.LENS_FACING_BACK)
                        .build();

                // Attach use cases to the camera with the same lifecycle owner
                Camera camera = cameraProvider.bindToLifecycle(
                        ((LifecycleOwner) this),
                        cameraSelector,
                        preview,
                        videoCapture);

                // Connect the preview use case to the previewView
                preview.setSurfaceProvider(
                        previewView.getSurfaceProvider());

                capture.setOnClickListener(onCaptureClick);

            } catch (InterruptedException | ExecutionException e) {
                // Currently no exceptions thrown. cameraProviderFuture.get()
                // shouldn't block since the listener is being called, so no need to
                // handle InterruptedException.
            }
        }, ContextCompat.getMainExecutor(getActivity()));

        return rootView;
    }

    private Boolean isRecording = false;

    private View.OnClickListener onCaptureClick = new View.OnClickListener() {
        @SuppressLint({"RestrictedApi", "MissingPermission"})
        @Override
        public void onClick(View view) {
            if(!isRecording){
                isRecording = true;
                SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
                String timestamp = mDateFormat.format(new Date());
                File mediaFile = new File(GlobalConstants.TEMP_DIR(), "VID_" + timestamp + ".mp4");// File.createTempFile("IMG_", ".jpg", tempDir);
                VideoCapture.OutputFileOptions outputFileOptions = new VideoCapture.OutputFileOptions.Builder(mediaFile).build();
                videoCapture.startRecording(outputFileOptions, executor, new VideoCapture.OnVideoSavedCallback() {
                    @Override
                    public void onVideoSaved(@NonNull VideoCapture.OutputFileResults outputFileResults) {
                        Log.d(LOG_TAG, "videoSaved");
                    }

                    @Override
                    public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
                        Log.d(LOG_TAG, "videoError");
                    }
                });
            } else videoCapture.stopRecording();
        }
    };

預覽用例工作正常,但在開始錄制時,在某些錄制會話上工作正常,但在其他錄制會話上,屏幕凍結並且在停止錄制時,成功調用onVideoSaved回調但生成的視頻文件為空。

調試控制台拋出這個:

D/CAMERA::VideoActivity: Initialize VideoActivity
I/MultiWindowDecorSupport: updateCaptionType >> com.android.internal.policy.MultiWindowDecorSupport@19a4248, isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
D/MultiWindowDecorSupport: setCaptionType = 0
D/InputTransport: Input channel constructed: fd=95
D/ViewRootImpl@be5fe8f[VideoActivity]: setView = DecorView@617251c[VideoActivity] TM=true MM=false
I/Choreographer: Skipped 175 frames!  The application may be doing too much work on its main thread.
V/InputMethodManager: Not IME target window, ignoring
D/SurfaceView: onWindowVisibilityChanged(0) true android.widget.VideoView{4d18525 VFE...... .F....I. 0,0-0,0 #7f0901a8 app:id/preview_video} of ViewRootImpl@be5fe8f[VideoActivity]
D/ViewRootImpl@be5fe8f[VideoActivity]: Relayout returned: old=[0,0][800,1280] new=[0,0][800,1280] result=0x7 surface={true 3367393280} changed=true
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000,  [800x1280]-format:1
D/OpenGLRenderer: eglCreateWindowSurface = 0xc314abc0, 0xc8b65808
E/RecyclerView: No adapter attached; skipping layout
D/SurfaceView: show() Surface(name=SurfaceView - cat.gencat.mossos.camera.test/cat.gencat.mossos.camera.ui._template.activities.VideoActivity@4d18525@0[6359])/@0xed542aa android.widget.VideoView{4d18525 VFE...... .F....ID 0,0-800,1160 #7f0901a8 app:id/preview_video}
D/SurfaceView: surfaceCreated 1 #8 android.widget.VideoView{4d18525 VFE...... .F....ID 0,0-800,1160 #7f0901a8 app:id/preview_video}
D/SurfaceView: surfaceChanged (800,1160) 1 #8 android.widget.VideoView{4d18525 VFE...... .F....ID 0,0-800,1160 #7f0901a8 app:id/preview_video}
D/DeferrableSurface: Surface created[total_surfaces=1, used_surfaces=0](androidx.camera.core.SurfaceRequest$2@4dc674e}
I/ACodec:  [] Now uninitialized
I/ACodec: [] onAllocateComponent
I/OMXClient: IOmx service obtained
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Loaded
I/ACodec:  [] Now uninitialized
I/ACodec: [] onAllocateComponent
I/OMXClient: IOmx service obtained
I/ACodec: [OMX.google.aac.encoder] Now Loaded
I/ACodec:  [OMX.Exynos.AVC.Encoder] Now uninitialized
     [] Now kWhatShutdownCompleted event : 8600
I/MediaCodec: Codec shutdown complete
I/ACodec:  [] Now uninitialized
I/ACodec: [] onAllocateComponent
I/OMXClient: IOmx service obtained
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Loaded
I/ACodec: app-pid(6359)
W/OMXUtils: do not know color format 0x7f000011 = 2130706449
    do not know color format 0x10 = 16
W/OMXUtils: do not know color format 0x7f00a000 = 2130747392
    do not know color format 0x7f000789 = 2130708361
I/ACodec: app-name : cat.gencat.mossos.camera.test
    setupAVCEncoderParameters with [profile: Baseline] [level: Level1]
    Enable Perceptual Video Coding
    Success set VideoMinQP(5/5/5) VideoMaxQP(50/50/50)
    SECSetparameters : default
I/ACodec: [OMX.Exynos.AVC.Encoder] cannot encode HDR static metadata. Ignoring.
    setupVideoEncoder succeeded
    [OMX.Exynos.AVC.Encoder] configure, AMessage : AMessage(what = 'conf', target = 21) = {
      int32_t color-format = 2130708361
      int32_t i-frame-interval = 1
      string mime = "video/avc"
      int32_t width = 1440
      int32_t bitrate = 8388608
      int32_t frame-rate = 30
      int32_t height = 1080
      int32_t encoder = 1
    }
W/OMXUtils: do not know color format 0x7f000789 = 2130708361
D/DeferrableSurface: Surface created[total_surfaces=2, used_surfaces=0](androidx.camera.core.impl.ImmediateSurface@3cc7a05}
I/ACodec:  [OMX.google.aac.encoder] Now uninitialized
     [] Now kWhatShutdownCompleted event : 8600
I/MediaCodec: Codec shutdown complete
I/ACodec:  [] Now uninitialized
I/ACodec: [] onAllocateComponent
I/OMXClient: IOmx service obtained
I/ACodec: [OMX.google.aac.encoder] Now Loaded
I/ACodec: app-pid(6359)
I/VideoCapture: source: 1 audioSampleRate: 8000 channelConfig: 16 audioFormat: 2 bufferSize: 640
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case androidx.camera.core.VideoCapture@e6f7d02 ACTIVE
D/UseCaseAttachState: Active and attached use case: [] for camera: 0
D/CameraOrientationUtil: getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case Preview:androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634 INACTIVE
D/UseCaseAttachState: Active and attached use case: [] for camera: 0
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case androidx.camera.core.VideoCapture@e6f7d02 ACTIVE
D/UseCaseAttachState: Active and attached use case: [] for camera: 0
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use cases [Preview:androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634, androidx.camera.core.VideoCapture@e6f7d02] now ATTACHED
D/UseCaseAttachState: All use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
D/Camera2CameraImpl: mMeteringRepeating is ATTACHED, SessionConfig Surfaces: 2, CaptureConfig Surfaces: 1
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522] for camera: 0
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Resetting Capture Session
I/Choreographer: Skipped 155 frames!  The application may be doing too much work on its main thread.
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Releasing session in state INITIALIZED
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Attempting to force open the camera.
D/CameraStateRegistry: tryOpenCamera(Camera@8c15fa0[id=0]) [Available Cameras: 1, Already Open: false (Previous state: CLOSED)] --> SUCCESS
D/CameraStateRegistry: Recalculating open cameras:
    Camera                                       State                 
    -------------------------------------------------------------------
    Camera@8c15fa0[id=0]                         OPENING               
    Camera@a436015[id=1]                         UNKNOWN               
    -------------------------------------------------------------------
    Open count: 1 (Max allowed: 1)
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Opening camera.
D/ViewRootImpl@be5fe8f[VideoActivity]: Relayout returned: old=[0,0][800,1280] new=[0,0][800,1280] result=0x3 surface={true 3367393280} changed=false
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Transitioning camera internal state: INITIALIZED --> OPENING
D/CameraStateMachine: New public camera state CameraState{type=OPENING, error=null} from OPENING and null
D/CameraStateMachine: Publishing new public camera state CameraState{type=OPENING, error=null}
D/UseCaseAttachState: All use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
E/Camera_APM :: [APM]APM's Thread is started
E/Camera_APM :: [APM] This app is forground app
I/CameraManagerGlobal: postSingleUpdate device: camera id 0 status STATUS_NOT_AVAILABLE
I/CameraManagerGlobal: postSingleUpdate device: camera id 0 status STATUS_NOT_AVAILABLE
D/ViewRootImpl@be5fe8f[VideoActivity]: MSG_RESIZED: frame=[0,0][800,1280] ci=[0,32][0,0] vi=[0,32][0,0] or=1
D/ViewRootImpl@be5fe8f[VideoActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager: prepareNavigationBarInfo() DecorView@617251c[VideoActivity]
D/InputMethodManager: getNavigationBarColor() -855310
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case Preview:androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634 INACTIVE
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522] for camera: 0
D/InputMethodManager: prepareNavigationBarInfo() DecorView@617251c[VideoActivity]
D/InputMethodManager: getNavigationBarColor() -855310
V/InputMethodManager: Starting input: tba=cat.gencat.mossos.camera.test ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager: startInputInner - Id : 0
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport: Input channel constructed: fd=119
D/InputTransport: Input channel destroyed: fd=92
D/PreviewView: Surface requested by Preview.
D/SurfaceView: onWindowVisibilityChanged(0) true android.view.SurfaceView{a14e4bd V.E...... ......I. 0,0-0,0} of ViewRootImpl@be5fe8f[VideoActivity]
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case androidx.camera.core.VideoCapture@e6f7d02 ACTIVE
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522] for camera: 0
D/ViewRootImpl@be5fe8f[VideoActivity]: Relayout returned: old=[0,0][800,1280] new=[0,0][800,1280] result=0x1 surface={true 3367393280} changed=false
D/SurfaceView: show() Surface(name=SurfaceView - cat.gencat.mossos.camera.test/cat.gencat.mossos.camera.ui._template.activities.VideoActivity@a14e4bd@0[6359])/@0xdad80 android.view.SurfaceView{a14e4bd V.E...... ......ID 0,0-960,720}
D/SurfaceView: surfaceCreated 1 #8 android.view.SurfaceView{a14e4bd V.E...... ......ID 0,0-960,720}
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case Preview:androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634 ACTIVE
D/SurfaceViewImpl: Surface created.
D/SurfaceView: surfaceChanged (960,720) 1 #8 android.view.SurfaceView{a14e4bd V.E...... ......ID 0,0-960,720}
D/SurfaceViewImpl: Surface changed. Size: 960x720
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
W/libEGL: EGLNativeWindowType 0xc8c1e808 disconnect failed
D/OpenGLRenderer: eglDestroySurface = 0xc7e56620, 0xc8c1e800
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} CameraDevice.onOpened()
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Transitioning camera internal state: OPENING --> OPENED
D/CameraStateRegistry: Recalculating open cameras:
    Camera                                       State                 
    -------------------------------------------------------------------
    Camera@8c15fa0[id=0]                         OPEN                  
    Camera@a436015[id=1]                         UNKNOWN               
    -------------------------------------------------------------------
    Open count: 1 (Max allowed: 1)
D/CameraStateMachine: New public camera state CameraState{type=OPEN, error=null} from OPEN and null
D/ViewRootImpl@348be9d[FormActivity]: Relayout returned: old=[0,0][800,1280] new=[0,0][800,1280] result=0x5 surface={false 0} changed=true
D/CameraStateMachine: Publishing new public camera state CameraState{type=OPEN, error=null}
D/UseCaseAttachState: All use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
D/PreviewView: Preview transformation info updated. TransformationInfo{cropRect=Rect(0, 0 - 960, 720), rotationDegrees=90, targetRotation=0}
D/PreviewTransform: Transformation info set: TransformationInfo{cropRect=Rect(0, 0 - 960, 720), rotationDegrees=90, targetRotation=0} 960x720 false
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
D/SurfaceViewImpl: Surface set on Preview.
D/ViewRootImpl@348be9d[FormActivity]: stopped(true) old=false
D/SyncCaptureSessionBase: [androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl@5854ddc] getSurface...done
D/CaptureSession: Opening capture session.
D/DeferrableSurface: New surface in use[total_surfaces=2, used_surfaces=1](androidx.camera.core.SurfaceRequest$2@4dc674e}
D/DeferrableSurface: use count+1, useCount=1 androidx.camera.core.SurfaceRequest$2@4dc674e
D/DeferrableSurface: New surface in use[total_surfaces=2, used_surfaces=2](androidx.camera.core.impl.ImmediateSurface@3cc7a05}
D/DeferrableSurface: use count+1, useCount=1 androidx.camera.core.impl.ImmediateSurface@3cc7a05
D/CaptureSession: Attempting to send capture request onConfigured
D/CaptureSession: Issuing request for session.
D/CaptureSession: CameraCaptureSession.onConfigured() mState=OPENED
D/CaptureSession: CameraCaptureSession.onReady() OPENED
D/ViewRootImpl@348be9d[FormActivity]: Relayout returned: old=[0,0][800,1280] new=[0,0][800,1280] result=0x1 surface={false 0} changed=false
D/StreamStateObserver: Update Preview stream state to STREAMING
W/AMessage: failed to deliver message as target handler 15 is gone.
W/AMessage: failed to deliver message as target handler 18 is gone.
D/ViewRootImpl@be5fe8f[VideoActivity]: ViewPostIme pointer 0
D/ViewRootImpl@be5fe8f[VideoActivity]: ViewPostIme pointer 1
I/VideoCapture: startRecording
I/VideoCapture: videoEncoder start
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Loaded->Idle
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Idle->Executing
I/MediaCodec: setCodecState state : 0
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Executing
I/VideoCapture: audioEncoder start
I/ACodec: [OMX.google.aac.encoder] Now Loaded->Idle
I/ACodec: [OMX.google.aac.encoder] Now Idle->Executing
I/ACodec: [OMX.google.aac.encoder] Now Executing
D/CameraOrientationUtil: getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case androidx.camera.core.VideoCapture@e6f7d02 UPDATED
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
W/VideoCapture: Drops frame, current frame's timestamp 0 is earlier that last frame 0
D/CaptureSession: Attempting to submit CaptureRequest after setting
D/CaptureSession: Issuing request for session.
W/System: A resource failed to call close. 
I/MediaCodec: setCodecState state : 0
D/ViewRootImpl@be5fe8f[VideoActivity]: ViewPostIme pointer 0
D/ViewRootImpl@be5fe8f[VideoActivity]: ViewPostIme pointer 1
I/VideoCapture: stopRecording
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case androidx.camera.core.VideoCapture@e6f7d02 UPDATED
I/VideoCapture: audioRecorder stop
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
I/ACodec: [OMX.google.aac.encoder] Now Executing->Idle
I/ACodec: [OMX.google.aac.encoder] Now Idle->Loaded
    [OMX.google.aac.encoder] Now Loaded
     [OMX.google.aac.encoder] Now kWhatShutdownCompleted event : 8600
I/VideoCapture: Audio encode thread end
I/MediaCodec: setCodecState state : 1
I/VideoCapture: videoEncoder stop
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Executing->Idle
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Idle->Loaded
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Loaded
     [OMX.Exynos.AVC.Encoder] Now kWhatShutdownCompleted event : 8600
D/MPEG4Writer: Audio track stopping. Stop source
E/MPEG4Writer: Stop() called but track is not started
I/VideoCapture: Video encode thread end.
D/CaptureSession: Attempting to submit CaptureRequest after setting
D/CaptureSession: Issuing request for session.
I/MediaCodec: setCodecState state : 0
D/CAMERA::Video: videoSaved
I/ACodec:  [OMX.Exynos.AVC.Encoder] Now uninitialized
I/ACodec:  [] Now kWhatShutdownCompleted event : 8600
I/MediaCodec: Codec shutdown complete
I/ACodec:  [] Now uninitialized
I/ACodec: [] onAllocateComponent
I/OMXClient: IOmx service obtained
I/ACodec: [OMX.Exynos.AVC.Encoder] Now Loaded
I/ACodec: app-pid(6359)
W/OMXUtils: do not know color format 0x7f000011 = 2130706449
W/OMXUtils: do not know color format 0x10 = 16
    do not know color format 0x7f00a000 = 2130747392
W/OMXUtils: do not know color format 0x7f000789 = 2130708361
I/ACodec: app-name : cat.gencat.mossos.camera.test
I/ACodec: setupAVCEncoderParameters with [profile: Baseline] [level: Level1]
I/ACodec: Enable Perceptual Video Coding
    Success set VideoMinQP(5/5/5) VideoMaxQP(50/50/50)
I/ACodec: SECSetparameters : default
I/ACodec: [OMX.Exynos.AVC.Encoder] cannot encode HDR static metadata. Ignoring.
    setupVideoEncoder succeeded
    [OMX.Exynos.AVC.Encoder] configure, AMessage : AMessage(what = 'conf', target = 25) = {
      int32_t color-format = 2130708361
      int32_t i-frame-interval = 1
      string mime = "video/avc"
      int32_t width = 1440
      int32_t bitrate = 8388608
      int32_t frame-rate = 30
      int32_t height = 1080
      int32_t encoder = 1
    }
W/OMXUtils: do not know color format 0x7f000789 = 2130708361
D/DeferrableSurface: surface closed,  useCount=1 closed=true androidx.camera.core.impl.ImmediateSurface@3cc7a05
D/DeferrableSurface: Surface created[total_surfaces=3, used_surfaces=2](androidx.camera.core.impl.ImmediateSurface@a82cb55}
I/ACodec:  [OMX.google.aac.encoder] Now uninitialized
     [] Now kWhatShutdownCompleted event : 8600
I/MediaCodec: Codec shutdown complete
I/ACodec:  [] Now uninitialized
I/ACodec: [] onAllocateComponent
I/OMXClient: IOmx service obtained
I/ACodec: [OMX.google.aac.encoder] Now Loaded
I/ACodec: app-pid(6359)
I/VideoCapture: source: 1 audioSampleRate: 8000 channelConfig: 16 audioFormat: 2 bufferSize: 640
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Use case androidx.camera.core.VideoCapture@e6f7d02 RESET
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Resetting Capture Session
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Releasing session in state OPENED
D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
D/UseCaseAttachState: All use case: [androidx.camera.core.VideoCapture-40c15101-6bc1-46eb-8990-b6602597b276242187522, androidx.camera.core.Preview-1c59a876-f0e2-41bd-95ee-b14ad005c634145149517] for camera: 0
D/CaptureSession: onSessionFinished()
D/SyncCaptureSessionBase: [androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl@fce7dd3] getSurface...done
D/CaptureSession: Opening capture session.
D/DeferrableSurface: use count+1, useCount=2 androidx.camera.core.SurfaceRequest$2@4dc674e
D/DeferrableSurface: New surface in use[total_surfaces=3, used_surfaces=3](androidx.camera.core.impl.ImmediateSurface@a82cb55}
D/DeferrableSurface: use count+1, useCount=1 androidx.camera.core.impl.ImmediateSurface@a82cb55
W/AMessage: failed to deliver message as target handler 21 is gone.
W/AMessage: failed to deliver message as target handler 23 is gone.
E/CameraCaptureSession: Session 1: Failed to create capture session; configuration failed
D/DeferrableSurface: use count-1,  useCount=1 closed=false androidx.camera.core.SurfaceRequest$2@4dc674e
D/DeferrableSurface: use count-1,  useCount=0 closed=false androidx.camera.core.impl.ImmediateSurface@a82cb55
D/DeferrableSurface: Surface no longer in use[total_surfaces=3, used_surfaces=2](androidx.camera.core.impl.ImmediateSurface@a82cb55}
D/DeferrableSurface: use count-1,  useCount=0 closed=false androidx.camera.core.SurfaceRequest$2@4dc674e
D/DeferrableSurface: Surface no longer in use[total_surfaces=3, used_surfaces=1](androidx.camera.core.SurfaceRequest$2@4dc674e}
D/DeferrableSurface: use count-1,  useCount=0 closed=true androidx.camera.core.impl.ImmediateSurface@3cc7a05
D/DeferrableSurface: Surface no longer in use[total_surfaces=3, used_surfaces=0](androidx.camera.core.impl.ImmediateSurface@3cc7a05}
D/DeferrableSurface: Surface terminated[total_surfaces=2, used_surfaces=0](androidx.camera.core.impl.ImmediateSurface@3cc7a05}
E/CaptureSession: CameraCaptureSession.onConfigureFailed() RELEASED
D/Camera2CameraImpl: CameraDevice.onError(): 0 failed with ERROR_CAMERA_DEVICE while in OPENED state. Will attempt recovering from error.
D/Camera2CameraImpl: Attempt to reopen camera[0] after error[ERROR_CAMERA_DEVICE]
D/Camera2CameraImpl: {Camera@8c15fa0[id=0]} Transitioning camera internal state: OPENED --> REOPENING

這種行為是隨機的,因為有時會發生在第二次錄制中,有時我能夠成功執行 10 次以上的錄制。 這在帶有 Android 5 的三星上完美運行,但在帶有 Android 9 的三星 Tab Active2 上崩潰。

你可以使用這個庫,而不是做所有這些。 它將為您完成所有任務。

如何實施


Options options = Options.init()
                .setRequestCode(100)     
                .setCount(1)
                .setFrontfacing(false)
                .setSpanCount(1)
                .setMode(Options.Mode.Video)
                .setScreenOrientation(Options.SCREEN_ORIENTATION_PORTRAIT)    
                .setPath("/Chatverse Captures");
        Pix.start(this, options);

將此添加到您要錄制的位置,錄制時,您可以獲得這樣的文件路徑

將此粘貼到onActivityResult

if (requestCode == 100){
        if (resultCode == Activity.RESULT_OK && requestCode == 100) {
            String returnValue = data.getStringArrayListExtra(Pix.IMAGE_RESULTS).get(0);
            Toast.makeText(this,returnValue,Toast.LENGHT_SHORT).show();
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM