Skip to content

Commit f86399e

Browse files
fontesrpmrousavy
andauthored
feat: Add support for specifying a custom video path (#3844)
* feat: add support for specifying a video path * fix: run linter * fix: create parent dir on ios * Update packages/react-native-vision-camera/android/src/main/java/com/margelo/nitro/camera/hybrids/outputs/HybridVideoOutput.kt * Update packages/react-native-vision-camera/ios/Hybrid Objects/Recording/HybridVideoRecorder.swift * Update packages/react-native-vision-camera/src/specs/outputs/CameraVideoOutput.nitro.ts --------- Co-authored-by: Marc Rousavy <me@mrousavy.com>
1 parent 628f111 commit f86399e

9 files changed

Lines changed: 73 additions & 10 deletions

File tree

packages/react-native-vision-camera/android/src/main/java/com/margelo/nitro/camera/hybrids/outputs/HybridVideoOutput.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,15 @@ class HybridVideoOutput(
145145
@SuppressLint("MissingPermission")
146146
override fun createRecorder(settings: RecorderSettings): Promise<HybridRecorderSpec> {
147147
return Promise.async {
148-
// Create .mp4 file in temp directory
149-
val file = File.createTempFile("VisionCamera_", "mp4")
148+
val file =
149+
if (settings.filePath != null) {
150+
File(settings.filePath)
151+
} else {
152+
// Create .mp4 file in temp directory
153+
File.createTempFile("VisionCamera_", "mp4")
154+
}
155+
// Create all parent directories if they don't exist yet.
156+
file.parentFile?.mkdirs()
150157

151158
// Prepare output options
152159
val fileOutputOptions =

packages/react-native-vision-camera/ios/Hybrid Objects/Recording/HybridVideoRecorder.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ class HybridVideoRecorder: HybridRecorderSpec {
2323
) throws {
2424
self.videoOutput = videoOutput
2525
self.queue = queue
26-
self.fileURL = try URL.createTempURL(fileType: fileType.toUTType())
26+
if let customFilePath = settings.filePath {
27+
self.fileURL = URL(fileURLWithPath: customFilePath)
28+
} else {
29+
self.fileURL = try URL.createTempURL(fileType: fileType.toUTType())
30+
}
31+
// Create all parent directories if they don't exist yet.
32+
try FileManager.default.createDirectory(
33+
at: self.fileURL.deletingLastPathComponent(),
34+
withIntermediateDirectories: true
35+
)
2736
self.settings = settings
2837
super.init()
2938
}

packages/react-native-vision-camera/nitrogen/generated/android/c++/JHybridCameraVideoOutputSpec.cpp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-vision-camera/nitrogen/generated/android/c++/JRecorderSettings.hpp

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-vision-camera/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/RecorderSettings.kt

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-vision-camera/nitrogen/generated/ios/c++/HybridCameraVideoOutputSpecSwift.hpp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-vision-camera/nitrogen/generated/ios/swift/RecorderSettings.swift

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-vision-camera/nitrogen/generated/shared/c++/RecorderSettings.hpp

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-vision-camera/src/specs/outputs/CameraVideoOutput.nitro.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ export interface RecorderSettings {
143143
* into the video metadata using the ISO-6709 standard.
144144
*/
145145
location?: Location
146+
/**
147+
* The absolute path (including file name and extension) where
148+
* the recording file should be written to, or `undefined` to
149+
* create a file in the device's temporary directory.
150+
*
151+
* All parent directories in this {@linkcode filePath} will
152+
* be automatically created if they do not yet exist.
153+
*
154+
* @default undefined
155+
*/
156+
filePath?: string
146157
/**
147158
* If set, the recording automatically stops once it reaches
148159
* this duration, in seconds.
@@ -210,8 +221,9 @@ export interface CameraVideoOutput extends CameraOutput {
210221
* Creates and prepares a new {@linkcode Recorder}
211222
* instance with the given {@linkcode RecorderSettings}.
212223
*
213-
* The {@linkcode Recorder} will record to a temporary
214-
* file, and can only record once.
224+
* The {@linkcode Recorder} will record to the configured
225+
* file path, or to a temporary file if no path was provided.
226+
* It can only record once.
215227
*
216228
* If you want to create a second recording,
217229
* you must create a new {@linkcode Recorder}.

0 commit comments

Comments
 (0)