mirror of
https://github.com/siddharthvaddem/openscreen.git
synced 2026-11-04 07:02:07 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69f1b4d20f |
@@ -1040,7 +1040,7 @@ export default function VideoEditor() {
|
|||||||
|
|
||||||
if (saveResult.canceled) {
|
if (saveResult.canceled) {
|
||||||
toast.info("Export canceled");
|
toast.info("Export canceled");
|
||||||
} else if (saveResult.success) {
|
} else if (saveResult.success && saveResult.path) {
|
||||||
handleExportSaved("GIF", saveResult.path);
|
handleExportSaved("GIF", saveResult.path);
|
||||||
} else {
|
} else {
|
||||||
setExportError(saveResult.message || "Failed to save GIF");
|
setExportError(saveResult.message || "Failed to save GIF");
|
||||||
@@ -1167,7 +1167,7 @@ export default function VideoEditor() {
|
|||||||
|
|
||||||
if (saveResult.canceled) {
|
if (saveResult.canceled) {
|
||||||
toast.info("Export canceled");
|
toast.info("Export canceled");
|
||||||
} else if (saveResult.success) {
|
} else if (saveResult.success && saveResult.path) {
|
||||||
handleExportSaved("Video", saveResult.path);
|
handleExportSaved("Video", saveResult.path);
|
||||||
} else {
|
} else {
|
||||||
setExportError(saveResult.message || "Failed to save video");
|
setExportError(saveResult.message || "Failed to save video");
|
||||||
@@ -1232,11 +1232,16 @@ export default function VideoEditor() {
|
|||||||
// Build export settings from current state
|
// Build export settings from current state
|
||||||
const sourceWidth = video.videoWidth || 1920;
|
const sourceWidth = video.videoWidth || 1920;
|
||||||
const sourceHeight = video.videoHeight || 1080;
|
const sourceHeight = video.videoHeight || 1080;
|
||||||
|
const aspectRatioValue =
|
||||||
|
aspectRatio === "native"
|
||||||
|
? getNativeAspectRatioValue(sourceWidth, sourceHeight, cropRegion)
|
||||||
|
: getAspectRatioValue(aspectRatio);
|
||||||
const gifDimensions = calculateOutputDimensions(
|
const gifDimensions = calculateOutputDimensions(
|
||||||
sourceWidth,
|
sourceWidth,
|
||||||
sourceHeight,
|
sourceHeight,
|
||||||
gifSizePreset,
|
gifSizePreset,
|
||||||
GIF_SIZE_PRESETS,
|
GIF_SIZE_PRESETS,
|
||||||
|
aspectRatioValue,
|
||||||
);
|
);
|
||||||
|
|
||||||
const settings: ExportSettings = {
|
const settings: ExportSettings = {
|
||||||
@@ -1260,7 +1265,17 @@ export default function VideoEditor() {
|
|||||||
|
|
||||||
// Start export immediately
|
// Start export immediately
|
||||||
handleExport(settings);
|
handleExport(settings);
|
||||||
}, [videoPath, exportFormat, exportQuality, gifFrameRate, gifLoop, gifSizePreset, handleExport]);
|
}, [
|
||||||
|
videoPath,
|
||||||
|
exportFormat,
|
||||||
|
exportQuality,
|
||||||
|
gifFrameRate,
|
||||||
|
gifLoop,
|
||||||
|
gifSizePreset,
|
||||||
|
aspectRatio,
|
||||||
|
cropRegion,
|
||||||
|
handleExport,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleCancelExport = useCallback(() => {
|
const handleCancelExport = useCallback(() => {
|
||||||
if (exporterRef.current) {
|
if (exporterRef.current) {
|
||||||
@@ -1475,6 +1490,13 @@ export default function VideoEditor() {
|
|||||||
videoPlaybackRef.current?.video?.videoHeight || 1080,
|
videoPlaybackRef.current?.video?.videoHeight || 1080,
|
||||||
gifSizePreset,
|
gifSizePreset,
|
||||||
GIF_SIZE_PRESETS,
|
GIF_SIZE_PRESETS,
|
||||||
|
aspectRatio === "native"
|
||||||
|
? getNativeAspectRatioValue(
|
||||||
|
videoPlaybackRef.current?.video?.videoWidth || 1920,
|
||||||
|
videoPlaybackRef.current?.video?.videoHeight || 1080,
|
||||||
|
cropRegion,
|
||||||
|
)
|
||||||
|
: getAspectRatioValue(aspectRatio),
|
||||||
)}
|
)}
|
||||||
onExport={handleOpenExportDialog}
|
onExport={handleOpenExportDialog}
|
||||||
selectedAnnotationId={selectedAnnotationId}
|
selectedAnnotationId={selectedAnnotationId}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { calculateOutputDimensions } from "./gifExporter";
|
||||||
|
import { GIF_SIZE_PRESETS } from "./types";
|
||||||
|
|
||||||
|
describe("calculateOutputDimensions", () => {
|
||||||
|
it("uses the selected aspect ratio for scaled GIF exports", () => {
|
||||||
|
expect(calculateOutputDimensions(1080, 1920, "medium", GIF_SIZE_PRESETS, 16 / 9)).toEqual({
|
||||||
|
width: 1280,
|
||||||
|
height: 720,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fits original-size GIF exports within the source bounds at the selected aspect ratio", () => {
|
||||||
|
expect(calculateOutputDimensions(1080, 1920, "original", GIF_SIZE_PRESETS, 16 / 9)).toEqual({
|
||||||
|
width: 1080,
|
||||||
|
height: 606,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -58,24 +58,39 @@ export function calculateOutputDimensions(
|
|||||||
sourceHeight: number,
|
sourceHeight: number,
|
||||||
sizePreset: GifSizePreset,
|
sizePreset: GifSizePreset,
|
||||||
sizePresets: typeof GIF_SIZE_PRESETS,
|
sizePresets: typeof GIF_SIZE_PRESETS,
|
||||||
|
targetAspectRatio = sourceWidth / sourceHeight,
|
||||||
): { width: number; height: number } {
|
): { width: number; height: number } {
|
||||||
const preset = sizePresets[sizePreset];
|
const preset = sizePresets[sizePreset];
|
||||||
const maxHeight = preset.maxHeight;
|
const maxHeight = preset.maxHeight;
|
||||||
|
const aspectRatio =
|
||||||
|
Number.isFinite(targetAspectRatio) && targetAspectRatio > 0
|
||||||
|
? targetAspectRatio
|
||||||
|
: sourceWidth / sourceHeight;
|
||||||
|
|
||||||
// If original is smaller than max height or preset is 'original', use source dimensions
|
const toEven = (value: number) => {
|
||||||
if (sourceHeight <= maxHeight || sizePreset === "original") {
|
const evenValue = Math.max(2, Math.floor(value / 2) * 2);
|
||||||
return { width: sourceWidth, height: sourceHeight };
|
return evenValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sizePreset === "original") {
|
||||||
|
const sourceAspect = sourceWidth / sourceHeight;
|
||||||
|
if (aspectRatio >= sourceAspect) {
|
||||||
|
const width = toEven(sourceWidth);
|
||||||
|
const height = toEven(width / aspectRatio);
|
||||||
|
return { width, height };
|
||||||
|
}
|
||||||
|
|
||||||
|
const height = toEven(sourceHeight);
|
||||||
|
const width = toEven(height * aspectRatio);
|
||||||
|
return { width, height };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate scaled dimensions preserving aspect ratio
|
const targetHeight = maxHeight;
|
||||||
const aspectRatio = sourceWidth / sourceHeight;
|
const targetWidth = Math.round(targetHeight * aspectRatio);
|
||||||
const newHeight = maxHeight;
|
|
||||||
const newWidth = Math.round(newHeight * aspectRatio);
|
|
||||||
|
|
||||||
// Ensure dimensions are even (required for some encoders)
|
|
||||||
return {
|
return {
|
||||||
width: newWidth % 2 === 0 ? newWidth : newWidth + 1,
|
width: toEven(targetWidth),
|
||||||
height: newHeight % 2 === 0 ? newHeight : newHeight + 1,
|
height: toEven(targetHeight),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user