feat: Add width and height to VideoFile output (#2281)

* feat: Add `width` and `height` to `VideoFile` output

* Format
This commit is contained in:
Marc Rousavy 2023-12-12 16:43:57 +01:00 committed by GitHub
parent 98f08800f2
commit 9a187c6d19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 3 deletions

View File

@ -25,6 +25,8 @@ suspend fun CameraView.startRecording(options: RecordVideoOptions, onRecordCallb
val map = Arguments.createMap() val map = Arguments.createMap()
map.putString("path", video.path) map.putString("path", video.path)
map.putDouble("duration", video.durationMs.toDouble() / 1000.0) map.putDouble("duration", video.durationMs.toDouble() / 1000.0)
map.putInt("width", video.size.width)
map.putInt("height", video.size.height)
onRecordCallback(map, null) onRecordCallback(map, null)
} }
val onError = { error: RecorderError -> val onError = { error: RecorderError ->

View File

@ -32,7 +32,7 @@ class RecordingSession(
private const val AUDIO_CHANNELS = 1 private const val AUDIO_CHANNELS = 1
} }
data class Video(val path: String, val durationMs: Long) data class Video(val path: String, val durationMs: Long, val size: Size)
private val bitRate = getBitRate() private val bitRate = getBitRate()
private val recorder: MediaRecorder private val recorder: MediaRecorder
@ -106,7 +106,7 @@ class RecordingSession(
val stopTime = System.currentTimeMillis() val stopTime = System.currentTimeMillis()
val durationMs = stopTime - (startTime ?: stopTime) val durationMs = stopTime - (startTime ?: stopTime)
callback(Video(outputFile.absolutePath, durationMs)) callback(Video(outputFile.absolutePath, durationMs, size))
} }
} }

View File

@ -61,7 +61,8 @@ extension CameraSession {
if status == .completed { if status == .completed {
// Recording was successfully saved // Recording was successfully saved
let video = Video(path: recordingSession.url.absoluteString, let video = Video(path: recordingSession.url.absoluteString,
duration: recordingSession.duration) duration: recordingSession.duration,
size: recordingSession.size ?? CGSize.zero)
onVideoRecorded(video) onVideoRecorded(video)
} else { } else {
// Recording wasn't saved and we don't have an error either. // Recording wasn't saved and we don't have an error either.

View File

@ -52,6 +52,13 @@ class RecordingSession {
return assetWriter.outputURL return assetWriter.outputURL
} }
/**
Gets the size of the recorded video, in pixels.
*/
var size: CGSize? {
return videoWriter?.naturalSize
}
/** /**
Get the duration (in seconds) of the recorded video. Get the duration (in seconds) of the recorded video.
*/ */

View File

@ -18,11 +18,17 @@ struct Video {
Duration of the recorded video (in seconds) Duration of the recorded video (in seconds)
*/ */
var duration: Double var duration: Double
/**
* The size of the video, in pixels.
*/
var size: CGSize
func toJSValue() -> NSDictionary { func toJSValue() -> NSDictionary {
return [ return [
"path": path, "path": path,
"duration": duration, "duration": duration,
"width": size.width,
"height": size.height,
] ]
} }
} }

View File

@ -53,4 +53,12 @@ export interface VideoFile extends TemporaryFile {
* Represents the duration of the video, in seconds. * Represents the duration of the video, in seconds.
*/ */
duration: number duration: number
/**
* The width of the video, in pixels.
*/
width: number
/**
* The height of the video, in pixels.
*/
height: number
} }