diff --git a/package/src/devices/Templates.ts b/package/src/devices/Templates.ts new file mode 100644 index 0000000..93530de --- /dev/null +++ b/package/src/devices/Templates.ts @@ -0,0 +1,72 @@ +import { Dimensions } from 'react-native'; +import { FormatFilter } from './getCameraFormat'; + +type TTemplates = { + [key: string]: FormatFilter[]; +}; + +const SnapchatResolution = { width: 1920, height: 1080 }; +const InstagramResolution = { width: 3840, height: 2160 }; +const ScreenAspectRatio = Dimensions.get('window').height / Dimensions.get('window').width; + +/** + * Predefined templates for use in `useCameraFormat`/`getCameraFormat`. + * @example + * ```ts + * const format = useCameraFormat(device, Templates.Snapchat) + * ``` + */ +export const Templates: TTemplates = { + /** + * Highest resolution video recordings (e.g. 4k) + */ + Video: [{ videoResolution: 'max' }], + /** + * High resolution 60 FPS video recordings (e.g. 1080@60 FPS) + */ + Video60Fps: [{ fps: 60 }, { videoResolution: 'max' }], + /** + * High-FPS video recordings (e.g. 720@240 FPS) + */ + VideoSlowMotion: [{ fps: 240 }, { videoResolution: 'max' }], + /** + * High resolution video recordings with cinematic video stabilization + */ + VideoStabilized: [{ videoResolution: 'max' }, { videoStabilizationMode: 'cinematic-extended' }], + /** + * Highest resolution photo capture (e.g. 4k) + */ + Photo: [{ photoResolution: 'max' }], + /** + * Highest resolution photo capture with portrait screen aspect ratio (e.g. 4k) + */ + PhotoPortrait: [{ photoResolution: 'max' }, { photoAspectRatio: ScreenAspectRatio }], + /** + * HD-quality for faster Frame Processing in YUV pixelFormat (e.g. 720p) + */ + FrameProcessingYUV: [{ videoResolution: { width: 1080, height: 720 } }, { pixelFormat: 'yuv' }], + /** + * HD-quality for faster Frame Processing in RGB pixelFormat (e.g. 720p) + */ + FrameProcessingRGB: [{ videoResolution: { width: 1080, height: 720 } }, { pixelFormat: 'rgb' }], + /** + * Snapchat-style video recordings and photo capture + * Targets Full HD-quality for lower file sizes and portrait screen aspect ratio. + */ + Snapchat: [ + { videoAspectRatio: ScreenAspectRatio }, + { videoResolution: SnapchatResolution }, + { photoAspectRatio: ScreenAspectRatio }, + { photoResolution: SnapchatResolution }, + ], + /** + * Instagram-style video recordings and photo capture. + * Targets 4k-quality and portrait screen aspect ratio. + */ + Instagram: [ + { videoAspectRatio: ScreenAspectRatio }, + { videoResolution: InstagramResolution }, + { photoAspectRatio: ScreenAspectRatio }, + { photoResolution: InstagramResolution }, + ], +}; diff --git a/package/src/devices/getCameraFormat.ts b/package/src/devices/getCameraFormat.ts index ec3744c..bd015a1 100644 --- a/package/src/devices/getCameraFormat.ts +++ b/package/src/devices/getCameraFormat.ts @@ -20,18 +20,20 @@ export interface FormatFilter { photoResolution?: Size | 'max'; /** * The target aspect ratio of the video (and preview) output, expressed as a factor: `width / height`. + * (Note: Cameras are in landscape orientation) * * In most cases, you want this to be as close to the screen's aspect ratio as possible (usually ~9:16). * * @example * ```ts * const screen = Dimensions.get('screen') - * targetVideoAspectRatio: screen.width / screen.height + * targetVideoAspectRatio: screen.height / screen.width * ``` */ videoAspectRatio?: number; /** * The target aspect ratio of the photo output, expressed as a factor: `width / height`. + * (Note: Cameras are in landscape orientation) * * In most cases, you want this to be the same as `targetVideoAspectRatio`, which you often want * to be as close to the screen's aspect ratio as possible (usually ~9:16) @@ -39,7 +41,7 @@ export interface FormatFilter { * @example * ```ts * const screen = Dimensions.get('screen') - * targetPhotoAspectRatio: screen.width / screen.height + * targetPhotoAspectRatio: screen.height / screen.width * ``` */ photoAspectRatio?: number; diff --git a/package/src/index.ts b/package/src/index.ts index b1ead91..3c42341 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -12,6 +12,7 @@ export * from './VideoFile'; export * from './devices/getCameraFormat'; export * from './devices/getCameraDevice'; +export * from './devices/Templates'; export * from './hooks/useCameraDevice'; export * from './hooks/useCameraDevices';