mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-24 06:46:09 +00:00
fix(export): preserve cropped native aspect ratio
This commit is contained in:
@@ -1485,15 +1485,15 @@ export default function VideoEditor() {
|
||||
[gifSizePreset],
|
||||
);
|
||||
|
||||
const desiredMp4SourceDimensions = useMemo(
|
||||
() =>
|
||||
calculateMp4SourceDimensions(
|
||||
videoPlaybackRef.current?.video?.videoWidth || 1920,
|
||||
videoPlaybackRef.current?.video?.videoHeight || 1080,
|
||||
aspectRatio,
|
||||
),
|
||||
[aspectRatio],
|
||||
);
|
||||
const desiredMp4SourceDimensions = useMemo(() => {
|
||||
const sourceVideo = isPreviewReady ? videoPlaybackRef.current?.video : null;
|
||||
return calculateMp4SourceDimensions(
|
||||
sourceVideo?.videoWidth || 1920,
|
||||
sourceVideo?.videoHeight || 1080,
|
||||
aspectRatio,
|
||||
cropRegion,
|
||||
);
|
||||
}, [aspectRatio, cropRegion, isPreviewReady]);
|
||||
|
||||
const mp4OutputDimensions = useMemo(() => {
|
||||
const baseWidth = supportedMp4SourceDimensions.encoderPath
|
||||
|
||||
@@ -9,6 +9,18 @@ describe("calculateMp4SourceDimensions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the cropped source bounds for native exports", () => {
|
||||
expect(
|
||||
calculateMp4SourceDimensions(320, 180, "native", {
|
||||
width: 1,
|
||||
height: 0.8,
|
||||
}),
|
||||
).toEqual({
|
||||
width: 320,
|
||||
height: 144,
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the rotated source bounds for 9:16 original exports", () => {
|
||||
expect(calculateMp4SourceDimensions(1920, 1080, "9:16")).toEqual({
|
||||
width: 1080,
|
||||
|
||||
@@ -30,9 +30,15 @@ export function calculateMp4SourceDimensions(
|
||||
sourceWidth: number,
|
||||
sourceHeight: number,
|
||||
aspectRatio: AspectRatio,
|
||||
cropRegion?: { width: number; height: number },
|
||||
): { width: number; height: number } {
|
||||
const safeSourceWidth = normalizeEvenDimension(sourceWidth);
|
||||
const safeSourceHeight = normalizeEvenDimension(sourceHeight);
|
||||
const useCroppedBounds = aspectRatio === "native";
|
||||
const safeSourceWidth = normalizeEvenDimension(
|
||||
sourceWidth * (useCroppedBounds ? (cropRegion?.width ?? 1) : 1),
|
||||
);
|
||||
const safeSourceHeight = normalizeEvenDimension(
|
||||
sourceHeight * (useCroppedBounds ? (cropRegion?.height ?? 1) : 1),
|
||||
);
|
||||
const sourceAspectRatio = safeSourceHeight > 0 ? safeSourceWidth / safeSourceHeight : 16 / 9;
|
||||
const aspectRatioValue = getAspectRatioValue(aspectRatio, sourceAspectRatio);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user