Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/components/video-editor/VideoPlayback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
cursorSwayRef.current = cursorSway;
}, [cursorSway]);

// Sync currentTime prop to internal ref (in milliseconds)
useEffect(() => {
currentTimeRef.current = currentTime * 1000;
}, [currentTime]);

useEffect(() => {
if (!pixiReady || !videoReady) return;

Expand Down Expand Up @@ -1003,11 +1008,16 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
};

const ticker = () => {
const timeMs = currentTimeRef.current;
const { region, strength, blendedScale, transition } =
findDominantRegion(zoomRegionsRef.current, currentTimeRef.current, {
findDominantRegion(zoomRegionsRef.current, timeMs, {
connectZooms: connectZoomsRef.current,
});

if (region && Math.abs(timeMs - region.startMs) > 1000) {
// console.log(`[ZoomDebug] timeMs: ${timeMs}, dominantRegion_startMs: ${region.startMs}, strength: ${strength}`);
}

const defaultFocus = DEFAULT_FOCUS;
let targetScaleFactor = 1;
let targetFocus = defaultFocus;
Expand Down
19 changes: 9 additions & 10 deletions src/components/video-editor/videoPlayback/zoomRegionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { ZoomFocus, ZoomRegion } from "../types";
import { ZOOM_DEPTH_SCALES } from "../types";
import { TRANSITION_WINDOW_MS, ZOOM_IN_TRANSITION_WINDOW_MS } from "./constants";
import { TRANSITION_WINDOW_MS } from "./constants";
import { clampFocusToScale } from "./focusUtils";
import { clamp01, cubicBezier, easeOutScreenStudio } from "./mathUtils";

const CHAINED_ZOOM_PAN_GAP_MS = 1500;
const CONNECTED_ZOOM_PAN_DURATION_MS = 1000;
const ZOOM_IN_OVERLAP_MS = 500;

type DominantRegionOptions = {
connectZooms?: boolean;
Expand Down Expand Up @@ -36,24 +35,25 @@ function easeConnectedPan(value: number) {
}

export function computeRegionStrength(region: ZoomRegion, timeMs: number) {
const zoomInEnd = region.startMs + ZOOM_IN_OVERLAP_MS;
const leadInStart = zoomInEnd - ZOOM_IN_TRANSITION_WINDOW_MS;
const leadOutEnd = region.endMs + TRANSITION_WINDOW_MS;
const leadInStart = region.startMs;
const leadInEnd = leadInStart + TRANSITION_WINDOW_MS;
const leadOutStart = region.endMs;
const leadOutEnd = leadOutStart + TRANSITION_WINDOW_MS;

if (timeMs < leadInStart || timeMs > leadOutEnd) {
return 0;
}

if (timeMs < zoomInEnd) {
const progress = (timeMs - leadInStart) / ZOOM_IN_TRANSITION_WINDOW_MS;
if (timeMs < leadInEnd) {
const progress = Math.max(0, Math.min(1, (timeMs - leadInStart) / TRANSITION_WINDOW_MS));
return easeOutScreenStudio(progress);
}

if (timeMs <= region.endMs) {
if (timeMs <= leadOutStart) {
return 1;
}

const progress = clamp01((timeMs - region.endMs) / TRANSITION_WINDOW_MS);
const progress = clamp01((timeMs - leadOutStart) / TRANSITION_WINDOW_MS);
return 1 - easeOutScreenStudio(progress);
}

Expand Down Expand Up @@ -217,4 +217,3 @@ export function findDominantRegion(regions: ZoomRegion[], timeMs: number, option
? { ...activeRegion, transition: null }
: { region: null, strength: 0, blendedScale: null, transition: null };
}