feat: Video Codec Option for recording video (#645)
* add video codec value * add types * use `recommendedVideoSettings` method instead * lint * refactor for better readability * add a method to get available codecs (ios) * imrove tsDoc description of the videoCodec option Co-authored-by: Marc Rousavy <marcrousavy@hotmail.com> * ios format Co-authored-by: Marc Rousavy <marcrousavy@hotmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { requireNativeComponent, NativeModules, NativeSyntheticEvent, findNodeHandle, NativeMethods, Platform } from 'react-native';
|
||||
import type { FrameProcessorPerformanceSuggestion } from '.';
|
||||
import type { FrameProcessorPerformanceSuggestion, VideoFileType } from '.';
|
||||
import type { CameraDevice } from './CameraDevice';
|
||||
import type { ErrorWithCause } from './CameraError';
|
||||
import { CameraCaptureError, CameraRuntimeError, tryParseNativeCameraError, isErrorWithCause } from './CameraError';
|
||||
@@ -9,7 +9,7 @@ import type { Frame } from './Frame';
|
||||
import type { PhotoFile, TakePhotoOptions } from './PhotoFile';
|
||||
import type { Point } from './Point';
|
||||
import type { TakeSnapshotOptions } from './Snapshot';
|
||||
import type { RecordVideoOptions, VideoFile } from './VideoFile';
|
||||
import type { CameraVideoCodec, RecordVideoOptions, VideoFile } from './VideoFile';
|
||||
|
||||
//#region Types
|
||||
export type CameraPermissionStatus = 'authorized' | 'not-determined' | 'denied' | 'restricted';
|
||||
@@ -238,6 +238,22 @@ export class Camera extends React.PureComponent<CameraProps> {
|
||||
}
|
||||
//#endregion
|
||||
|
||||
/**
|
||||
* Get a list of video codecs the current camera supports for a given file type. Returned values are ordered by efficiency (descending).
|
||||
* @example
|
||||
* ```ts
|
||||
* const codecs = await camera.current.getAvailableVideoCodecs("mp4")
|
||||
* ```
|
||||
* @throws {@linkcode CameraRuntimeError} When any kind of error occured while getting available video codecs. Use the {@linkcode ParameterError.code | code} property to get the actual error
|
||||
*/
|
||||
public async getAvailableVideoCodecs(fileType?: VideoFileType): Promise<CameraVideoCodec[]> {
|
||||
try {
|
||||
return await CameraModule.getAvailableVideoCodecs(this.handle, fileType);
|
||||
} catch (e) {
|
||||
throw tryParseNativeCameraError(e);
|
||||
}
|
||||
}
|
||||
|
||||
//#region Static Functions (NativeModule)
|
||||
/**
|
||||
* Get a list of all available camera devices on the current phone.
|
||||
|
@@ -3,6 +3,17 @@ import type { TemporaryFile } from './TemporaryFile';
|
||||
|
||||
export type VideoFileType = 'mov' | 'avci' | 'm4v' | 'mp4';
|
||||
|
||||
export type CameraVideoCodec =
|
||||
| 'h264'
|
||||
| 'hevc'
|
||||
| 'hevc-alpha'
|
||||
| 'jpeg'
|
||||
| 'pro-res-4444'
|
||||
| 'pro-res-422'
|
||||
| 'pro-res-422-hq'
|
||||
| 'pro-res-422-lt'
|
||||
| 'pro-res-422-proxy';
|
||||
|
||||
export interface RecordVideoOptions {
|
||||
/**
|
||||
* Set the video flash mode. Natively, this just enables the torch while recording.
|
||||
@@ -21,6 +32,13 @@ export interface RecordVideoOptions {
|
||||
* Called when the recording has been successfully saved to file.
|
||||
*/
|
||||
onRecordingFinished: (video: VideoFile) => void;
|
||||
/**
|
||||
* Set the video codec to record in. Different video codecs affect video quality and video size.
|
||||
* To get a list of all available video codecs use the `getAvailableVideoCodecs()` function.
|
||||
*
|
||||
* @default undefined
|
||||
*/
|
||||
videoCodec?: CameraVideoCodec;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user