mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.38k stars 1.08k forks source link

🐛 First-Time Video Recording Causes Camera Stutter #3214

Open YubinKim16 opened 1 week ago

YubinKim16 commented 1 week ago

What's happening?

The very first time I record a video, there is a stutter effect for about 3-5 seconds.

I noticed there is a long delay after "[info] 📸 VisionCamera.start(): Starting Asset Writer..."

I tried these two solutions but none of them worked for me.

https://github.com/mrousavy/react-native-vision-camera/issues/1476 https://github.com/react-native-camera/react-native-camera/issues/3170

Reproduceable Code

<Camera 
ref={cameraRef}
onInitialized={() => console.log('camera initialized')}
outputOrientation="preview"
style={styles.camera}
device={device}
isActive={true}
audio={true}
photoQualityBalance="speed"
videoQualityBalance="speed"
videoResolution="720p"
photo={mode === 'image'}
video={mode === 'video'}
enableZoomGesture={true}
/>

Relevant log output

11:39:30.941: [info] 📸 VisionCamera.startRecording(options:onVideoRecorded:onError:): Starting Video recording...
11:39:30.941: [info] 📸 VisionCamera.startRecording(options:onVideoRecorded:onError:): Starting recording into file: file:///private/var/mobile/Containers/Data/Application/A4E79AEB-25C8-4F7E-80EC-71D4B4C6C572/tmp/B2678AF2-3950-447B-865B-576BAC424B32.mov
11:39:30.942: [info] 📸 VisionCamera.init(url:fileType:metadataProvider:clock:orientation:completion:): Creating RecordingSession... (orientation: landscapeLeft)
11:39:30.943: [info] 📸 VisionCamera.startRecording(options:onVideoRecorded:onError:): Enabling Audio for Recording...
11:39:30.943: [info] 📸 VisionCamera.activateAudioSession(): Activating Audio Session...
11:39:30.944: [info] 📸 VisionCamera.updateCategory(_:mode:options:): Changing AVAudioSession category from AVAudioSessionCategoryAmbient -> AVAudioSessionCategoryPlayAndRecord
11:39:30.946: [info] 📸 VisionCamera.initializeAudioTrack(withSettings:format:): Initializing Audio AssetWriter with settings: ["AVEncoderQualityForVBRKey": 91, "AVNumberOfChannelsKey": 1, "AVSampleRateKey": 44100, "AVEncoderBitRateStrategyKey": AVAudioBitRateStrategy_Variable, "AVEncoderBitRatePerChannelKey": 96000, "AVFormatIDKey": 1633772320]
11:39:32.323: [info] 📸 VisionCamera.updateCategory(_:mode:options:): AVAudioSession category changed!
11:39:35.320: [info] 📸 VisionCamera.initializeAudioTrack(withSettings:format:): Initialized Audio AssetWriter.
11:39:35.324: [info] 📸 VisionCamera.recommendedVideoSettings(forOptions:): Getting recommended video settings for AVFileType(_rawValue: com.apple.quicktime-movie) file...
11:39:35.328: [info] 📸 VisionCamera.activateAudioSession(): Audio Session activated!
11:39:35.334: [info] 📸 VisionCamera.initializeVideoTrack(withSettings:): Initializing Video AssetWriter with settings: ["AVVideoWidthKey": 1920, "AVVideoCodecKey": hvc1, "AVVideoHeightKey": 1080, "AVVideoCompressionPropertiesKey": {
    AllowFrameReordering = 1;
    AllowOpenGOP = 1;
    AverageBitRate = 7651584;
    ExpectedFrameRate = 30;
    MaxAllowedFrameQP = 41;
    MaxKeyFrameIntervalDuration = 1;
    MinAllowedFrameQP = 15;
    MinimizeMemoryUsage = 1;
    Priority = 80;
    ProfileLevel = "HEVC_Main_AutoLevel";
    RealTime = 1;
    RelaxAverageBitRateTarget = 1;
}]
11:39:35.342: [info] 📸 VisionCamera.initializeVideoTrack(withSettings:): Initialized Video AssetWriter.
11:39:35.342: [info] 📸 VisionCamera.start(): Starting Asset Writer...
11:39:49.975: [info] 📸 VisionCamera.start(): Asset Writer started!
11:39:49.975: [info] 📸 VisionCamera.start(): Asset Writer session started at 58539.161912291.
11:39:49.979: [info] 📸 VisionCamera.start(): Requesting video timeline start at 58539.162195958...
11:39:49.979: [info] 📸 VisionCamera.start(): Requesting audio timeline start at 58539.16587475...

Camera Device

{
  "formats": [],
  "minFocusDistance": 20,
  "isMultiCam": false,
  "id": "com.apple.avfoundation.avcapturedevice.built-in_video:1",
  "minZoom": 1,
  "hardwareLevel": "full",
  "position": "front",
  "sensorOrientation": "portrait",
  "supportsLowLightBoost": false,
  "maxExposure": 8,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "neutralZoom": 1,
  "supportsRawCapture": false,
  "supportsFocus": true,
  "minExposure": -8,
  "name": "Front Camera",
  "hasFlash": true,
  "maxZoom": 128.875,
  "hasTorch": false
}

Device

iPhone 14 (iOS 17.6.1)

VisionCamera Version

^4.5.2

Can you reproduce this issue in the VisionCamera Example app?

I didn't try (⚠️ your issue might get ignored & closed if you don't try this)

Additional information

maintenance-hans[bot] commented 1 week ago

Guten Tag, Hans here! 🍻

Thanks for reporting ze issue. It sounds like you are experiencing a delay when starting video recording. However, I see you didn't try reproducing zis issue in ze VisionCamera Example app. It's very important to check if ze problem is present zere, as it can help narrow down ze cause.

Also, please provide us with more logs from Xcode, especially if you see any warnings or errors during ze recording. This information will greatly help mrousavy in diagnosing ze problem.

If you need help on how to gather logs, please let me know! And remember, if you find ze project helpful, consider sponsoring mrousavy here. Your support helps ze project thrive!

Note: If you think I made a mistake, please ping @mrousavy to take a look.