CameraApp is an iOS application designed to capture high-resolution videos and extract frames from those videos. It includes various camera settings such as ISO and shutter speed adjustments to enhance the quality of the captured media.
Features
- High-Resolution Video Recording: Capture videos up to 4000x3000 resolution.
- Frame Extraction: Extract frames from the recorded video at 0.2-second intervals.
- ISO and Shutter Speed Adjustments: Customize ISO and shutter speed for better exposure control.
- User Interface Controls: Easy-to-use buttons for starting/stopping recording, showing frames, uploading data, and retaking videos.
- Real-Time Camera Preview: Full-screen camera preview with real-time adjustments. Installation
1- Clone the repository:
git clone https://github.com/your-repository/CameraApp.git
2-Open the project in Xcode:
cd CameraApp
open CameraApp.xcodeproj
3- Build and run the project on a physical iOS device.
CameraViewController
This is the main view controller that handles camera setup, recording, and frame extraction.
- captureSession: Manages the flow of data from the input devices (camera) to the output (movie file).
- movieOutput: Manages the output for movie file recording.
- captureDevice: Represents the physical camera device.
- previewView: Displays the camera preview.
- timer: A timer for countdown during video recording.
- isoSettings and shutterSpeedSettings: Arrays of possible ISO values and shutter speeds.
- capturedFrames: Stores the extracted frames from the video.
- videoSegments: Stores the URLs of recorded video segments.
- lastCapturedFrame: Stores the last captured frame as a UIImage.
- isoPicker, shutterSpeedPicker: Pickers for selecting ISO and shutter speed values.
- capturedImageView: Displays the last captured frame.
- pausePlayButton, showFramesButton, uploadButton, timerLabel, exitButton, infoButton, loadingIndicator: Various buttons and labels for controlling the app.
- checkCameraAuthorizationStatus(): Checks if the app has permission to use the camera.
- setupCamera(): Configures the camera settings and starts the capture session.
- setupUI(): Sets up the user interface layout and constraints.
- startCapturingVideo(): Starts the video recording process.
- stopCapturingVideo(): Stops the video recording process.
- fileOutput(:didFinishRecordingTo:from:connections:error:): Handles the completion of video recording.
- extractFrames(from:): Extracts frames from the recorded video.
- toggleCapture(sender:): Toggles between starting and stopping video recording.
- updateTimerLabel(): Updates the countdown timer during recording.
- updateInnerCircleColor(isCapturing:): Updates the color of the inner circle on the pause/play button.
- updateCameraSettings(): Applies the selected ISO and shutter speed settings to the camera.
- showInfo(): Displays additional information about the recorded video.
- uploadAction(): Manages the process of saving the captured images to local storage.
- showLoadingIndicator(), hideLoadingIndicator(): Shows and hides the loading indicator.
- navigateToCapturedImagesViewController(): Navigates to the view controller that displays captured images.
- saveCapturedImagesToLocalStorage(): Saves the extracted frames to local storage.
- getTotalDuration(): Calculates the total duration of the recorded video segments.
- Use the isoPicker to select an ISO value. Higher values provide greater sensitivity in low light conditions.
- Use the shutterSpeedPicker to select a shutter speed. Faster speeds (e.g., 1/1000) freeze motion, while slower speeds (e.g., 1/30) create motion blur.
- Pause/Play Button: Starts or stops video recording.
- Show Frames Button: Displays the extracted frames from the recorded video.
- Upload Button: Saves the captured images to local storage.
- Exit Button: Resets the app and prepares it for a new video capture session.
- Info Button: Shows additional information about the recorded video.
- ISO and Shutter Speed Pickers: Adjusts camera settings for better exposure control.
The "Save Storage" functionality allows users to save extracted frames to the local storage and then delete them from memory to free up space.
-
Saving Frames to Storage:
- The extracted frames are saved as JPEG files in the app's document directory.
- The saveCapturedImagesToLocalStorage method iterates through the capturedFrames array, converts each UIImage to JPEG data, and writes it to a file in the document directory.
-
Deleting Frames from Memory:
- After saving the frames to local storage, the capturedFrames array is cleared to free up memory.
-
This is done within the saveCapturedImagesToLocalStorage method after all frames are saved to disk.
-
Extract Frames:
- Frames are extracted from the video using AVAssetImageGenerator and stored in the capturedFrames array.
-
Save Frames to Local Storage:
- The saveCapturedImagesToLocalStorage method is called, which:
- Iterates through the capturedFrames array.
- Converts each frame to JPEG data.
- Writes the JPEG data to a file in the document directory.
- The saveCapturedImagesToLocalStorage method is called, which:
-
Clear Frames from Memory:
- After successfully saving the frames, the capturedFrames array is cleared to free up memory.