perf: reduce mobile video size
Improves upload and playback speed
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { Pressable, StyleSheet, Text, View } from "react-native";
|
import { Platform, Pressable, StyleSheet, Text, View } from "react-native";
|
||||||
import { CameraView } from "expo-camera";
|
import { CameraView } from "expo-camera";
|
||||||
import { logError } from "@/lib/errors";
|
import { logError } from "@/lib/errors";
|
||||||
|
|
||||||
const MAX_DURATION_S = 60;
|
const MAX_DURATION_S = 60;
|
||||||
|
const VIDEO_BITRATE_BPS = 1_200_000;
|
||||||
|
|
||||||
interface VideoRecordingOverlayProps {
|
interface VideoRecordingOverlayProps {
|
||||||
onComplete: (result: { uri: string; durationMs: number }) => void;
|
onComplete: (result: { uri: string; durationMs: number }) => void;
|
||||||
@@ -36,7 +37,10 @@ export function VideoRecordingOverlay({
|
|||||||
|
|
||||||
let result: { uri: string } | undefined;
|
let result: { uri: string } | undefined;
|
||||||
try {
|
try {
|
||||||
result = await cam.recordAsync({ maxDuration: MAX_DURATION_S });
|
result = await cam.recordAsync({
|
||||||
|
maxDuration: MAX_DURATION_S,
|
||||||
|
...(Platform.OS === "ios" ? { codec: "hvc1" as const } : {}),
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (cancelledRef.current) return;
|
if (cancelledRef.current) return;
|
||||||
logError(err, { scope: "compose.video.recordAsync" });
|
logError(err, { scope: "compose.video.recordAsync" });
|
||||||
@@ -83,6 +87,8 @@ export function VideoRecordingOverlay({
|
|||||||
ref={cameraRef}
|
ref={cameraRef}
|
||||||
style={StyleSheet.absoluteFill}
|
style={StyleSheet.absoluteFill}
|
||||||
facing="front"
|
facing="front"
|
||||||
|
videoQuality="480p"
|
||||||
|
videoBitrate={VIDEO_BITRATE_BPS}
|
||||||
mode="video"
|
mode="video"
|
||||||
mute={false}
|
mute={false}
|
||||||
onCameraReady={() => setCameraReady(true)}
|
onCameraReady={() => setCameraReady(true)}
|
||||||
|
|||||||
Reference in New Issue
Block a user