Improve editor timeline and caption voice workflows (#13)
* fix editor media caption and audio workflows * improve editor timeline and caption voice workflows --------- Co-authored-by: haixin.yang <haixin.yang@weimob.com>
This commit is contained in:
1 parent
42ea7685e4
commit
a6b7a9e51b
40 files changed
+794
-365
No files matched your search
+31
-175
@@ -1,11 +1,11 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { LanguageIntro } from "./components/panels.jsx";
|
||||
import { PreviewStage } from "./components/PreviewStage.jsx";
|
||||
import { VoicePanel } from "./components/VoicePanel.jsx";
|
||||
import { Timeline } from "./components/Timeline.jsx";
|
||||
import { Topbar } from "./components/Topbar.jsx";
|
||||
import { AssetDragPreview, ExportProgressOverlay, RemasterProgressOverlay } from "./components/EditorOverlays.jsx";
|
||||
import { AssetDragPreview, ExportProgressOverlay } from "./components/EditorOverlays.jsx";
|
||||
import { EditorSidebar } from "./components/EditorSidebar.jsx";
|
||||
import { useExportElapsed } from "./hooks/useExportElapsed.js";
|
||||
import { usePreviewFrameSize } from "./hooks/usePreviewFrameSize.js";
|
||||
@@ -56,8 +56,7 @@ import { decodeWaveform, downloadBlob } from "./lib/media.js";
|
||||
import { getImageThumbnailCount, getVisualSegmentsTotal } from "./lib/timeline.js";
|
||||
import { removeVisualPropertyKeyframe, updateVisualSegmentPlaybackRate, upsertVisualKeyframe, upsertVisualPropertyKeyframe } from "./lib/visualEffects.js";
|
||||
import { getLinkedSourceAudioEnd, getLinkedSourceAudioSegments } from "./lib/sourceAudioSync.js";
|
||||
import { captureRemasterSource, enhanceRemasterFrame } from "./lib/remasterEnhancement.js";
|
||||
import { enhanceRemasterClip } from "./lib/remasterClipEnhancement.js";
|
||||
import { getTimelineInitialContentZoom } from "./lib/timelineScale.js";
|
||||
|
||||
function getExportDimensions(ratio, longEdge) {
|
||||
const sourceLongEdge = Math.max(ratio.width, ratio.height);
|
||||
@@ -76,9 +75,9 @@ export function App() {
|
||||
const [uiLanguage, setUiLanguage] = useState(() => getStoredLanguage());
|
||||
const [showExportMenu, setShowExportMenu] = useState(false);
|
||||
const [exportSettings, setExportSettings] = useState({ resolution: "1080", frameRate: 30, codec: "h264", quality: "high" });
|
||||
const [remasterQuality, setRemasterQuality] = useState("fast");
|
||||
const [captionVoiceFocusRequest, setCaptionVoiceFocusRequest] = useState(0);
|
||||
const timelineImportRestoreRef = useRef(false);
|
||||
const [introClosing, setIntroClosing] = useState(false);
|
||||
const [remasterJob, setRemasterJob] = useState({ running: false, mode: "", segmentId: "", progress: 0, phase: "", frameIndex: 0, totalFrames: 0, startedAt: 0, backend: "" });
|
||||
const {
|
||||
captionPlacement, captionPosition, captionSegments, captionSize, captionStyle,
|
||||
captionsEnabled, script, selectedSegmentId, setCaptionPlacement,
|
||||
@@ -145,7 +144,7 @@ export function App() {
|
||||
avatarMotionCacheRef, avatarMotionWorkerRef, avatarRenderWorkerRef,
|
||||
avatarTestAudioImportedRef, avatarTestImportedRef, currentTimeRef, draggedAssetIdRef,
|
||||
exportStartRef, fileInputRef, imageUrlRefs, musicRef, musicUrlRef, pointerAssetDragRef,
|
||||
previewCanvasRef, previewShellRef, previewVideoRef, projectFileInputRef, remasterAbortControllerRef, sourceAudioRef,
|
||||
previewCanvasRef, previewShellRef, previewVideoRef, projectFileInputRef, sourceAudioRef,
|
||||
sourceAudioUrlRef, suppressAssetClickRef, suppressTimelineClipClickRef,
|
||||
timelineClipDragRef, timelineDurationRef, trackScrollRef, visionAbortControllerRef,
|
||||
visionJobGenerationRef, visionObjectUrlsRef, visualPlaybackFrameRef,
|
||||
@@ -216,6 +215,26 @@ export function App() {
|
||||
sourceAudioStart, sourceAudioUrl, stickerSegments, timelineDurationRef, timelineHorizon,
|
||||
trackVisibility, visionRecords, visualSegments, visualType,
|
||||
});
|
||||
const previousTimelineContentDurationRef = useRef(estimatedDuration);
|
||||
useEffect(() => {
|
||||
const previousDuration = previousTimelineContentDurationRef.current;
|
||||
const becameNonEmpty = previousDuration <= 0 && estimatedDuration > 0;
|
||||
const becameEmpty = previousDuration > 0 && estimatedDuration <= 0;
|
||||
|
||||
if (becameNonEmpty) {
|
||||
if (timelineImportRestoreRef.current) timelineImportRestoreRef.current = false;
|
||||
else setTimelineZoom(getTimelineInitialContentZoom(estimatedDuration));
|
||||
if (trackScrollRef.current) trackScrollRef.current.scrollLeft = 0;
|
||||
} else if (becameEmpty) {
|
||||
timelineImportRestoreRef.current = false;
|
||||
setTimelineHorizon(10);
|
||||
setTimelineZoom(getTimelineInitialContentZoom(0));
|
||||
setCurrentTime(0);
|
||||
if (trackScrollRef.current) trackScrollRef.current.scrollLeft = 0;
|
||||
}
|
||||
|
||||
previousTimelineContentDurationRef.current = estimatedDuration;
|
||||
}, [estimatedDuration, setCurrentTime, setTimelineHorizon, setTimelineZoom, trackScrollRef]);
|
||||
const previewFrameSize = usePreviewFrameSize(previewShellRef, ratio, compactRail);
|
||||
const selectedVisualSegment = visualSegments[selectedVisualSegmentIndex] ?? previewVisualSegment ?? null;
|
||||
const selectedVisualRange = visualTimeline[selectedVisualSegmentIndex] ?? previewVisualRange;
|
||||
@@ -272,155 +291,6 @@ export function App() {
|
||||
return nextItems;
|
||||
});
|
||||
};
|
||||
const clearSelectedVisualEnhancement = () => {
|
||||
if (!selectedVisualSegment?.id) return;
|
||||
remasterAbortControllerRef.current?.abort();
|
||||
setVisualSegments((items) => items.map((item) => {
|
||||
if (item.id !== selectedVisualSegment.id) return item;
|
||||
if (item.enhancement?.mode !== "remaster-drunet-full" || !item.enhancement.original?.src) return { ...item, enhancement: null };
|
||||
const original = item.enhancement.original;
|
||||
return {
|
||||
...item,
|
||||
src: original.src,
|
||||
blob: original.blob,
|
||||
width: original.width,
|
||||
height: original.height,
|
||||
sourceStart: original.sourceStart,
|
||||
sourceDuration: original.sourceDuration,
|
||||
trackFrames: original.trackFrames ?? [],
|
||||
enhancement: null,
|
||||
};
|
||||
}));
|
||||
setRemasterJob({ running: false, mode: "", segmentId: "", progress: 0, phase: "", frameIndex: 0, totalFrames: 0, startedAt: 0 });
|
||||
};
|
||||
const enhanceSelectedVisualFrame = async () => {
|
||||
if (!selectedVisualSegment?.id || !selectedVisualSegment.src) return notify(t("remasterSelectClip"));
|
||||
if (remasterJob.running) return;
|
||||
const controller = new AbortController();
|
||||
remasterAbortControllerRef.current = controller;
|
||||
setIsPlaying(false);
|
||||
previewVideoRef.current?.pause();
|
||||
setRemasterJob({ running: true, mode: "frame", segmentId: selectedVisualSegment.id, progress: 1, phaseKey: "remasterPreparing", frameIndex: 0, totalFrames: 1, startedAt: Date.now() });
|
||||
try {
|
||||
const bitmap = await captureRemasterSource({
|
||||
type: selectedVisualSegment.type,
|
||||
src: selectedVisualSegment.src,
|
||||
video: previewVideoRef.current,
|
||||
});
|
||||
const result = await enhanceRemasterFrame({
|
||||
bitmap,
|
||||
maxLongEdge: remasterQuality === "quality" ? 960 : 640,
|
||||
signal: controller.signal,
|
||||
onProgress: ({ progress, phaseKey, phaseParams }) => setRemasterJob((job) => ({ ...job, running: true, progress, phaseKey, phaseParams })),
|
||||
});
|
||||
if (controller.signal.aborted) return;
|
||||
const previewUrl = URL.createObjectURL(result.blob);
|
||||
imageUrlRefs.current.add(previewUrl);
|
||||
setVisualSegments((items) => items.map((item) => {
|
||||
if (item.id !== selectedVisualSegment.id) return item;
|
||||
return { ...item, enhancement: {
|
||||
enabled: true,
|
||||
mode: "remaster-drunet-frame-preview",
|
||||
previewUrl,
|
||||
previewBlob: result.blob,
|
||||
localTime: visualLocalTime,
|
||||
sourceTime: previewVisualSourceTime,
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
inferenceMs: result.inferenceMs,
|
||||
} };
|
||||
}));
|
||||
setRemasterJob({ running: false, mode: "frame", segmentId: selectedVisualSegment.id, progress: 100, phase: t("remasterReady"), frameIndex: 1, totalFrames: 1, startedAt: 0 });
|
||||
notify(t("remasterReady"));
|
||||
} catch (error) {
|
||||
if (error?.name !== "AbortError") notify(error instanceof Error ? error.message : t("remasterFailed"));
|
||||
setRemasterJob({ running: false, mode: "frame", segmentId: selectedVisualSegment.id, progress: 0, phase: "", frameIndex: 0, totalFrames: 1, startedAt: 0 });
|
||||
} finally {
|
||||
if (remasterAbortControllerRef.current === controller) remasterAbortControllerRef.current = null;
|
||||
}
|
||||
};
|
||||
const cancelRemasterEnhancement = () => {
|
||||
if (!remasterJob.running) return;
|
||||
setRemasterJob((job) => ({ ...job, phase: "", phaseKey: "remasterCanceling", phaseParams: {} }));
|
||||
remasterAbortControllerRef.current?.abort();
|
||||
};
|
||||
const enhanceSelectedVisualClip = async () => {
|
||||
if (!selectedVisualSegment?.id || !selectedVisualSegment.src) return notify(t("remasterSelectClip"));
|
||||
if (selectedVisualSegment.type !== "video") return notify(t("remasterClipOnlyVideo"));
|
||||
if (remasterJob.running) return;
|
||||
const existingOriginal = selectedVisualSegment.enhancement?.mode === "remaster-drunet-full"
|
||||
? selectedVisualSegment.enhancement.original
|
||||
: null;
|
||||
const original = existingOriginal ?? {
|
||||
src: selectedVisualSegment.src,
|
||||
blob: selectedVisualSegment.blob,
|
||||
width: selectedVisualSegment.width,
|
||||
height: selectedVisualSegment.height,
|
||||
sourceStart: selectedVisualSegment.sourceStart ?? 0,
|
||||
sourceDuration: selectedVisualSegment.sourceDuration,
|
||||
trackFrames: selectedVisualSegment.trackFrames ?? [],
|
||||
};
|
||||
const inputSegment = { ...selectedVisualSegment, ...original, type: "video" };
|
||||
const controller = new AbortController();
|
||||
remasterAbortControllerRef.current = controller;
|
||||
setIsPlaying(false);
|
||||
previewVideoRef.current?.pause();
|
||||
setRemasterJob({ running: true, mode: "clip", segmentId: selectedVisualSegment.id, progress: 1, phaseKey: "remasterClipPreparing", frameIndex: 0, totalFrames: 0, startedAt: Date.now() });
|
||||
try {
|
||||
const result = await enhanceRemasterClip({
|
||||
segment: inputSegment,
|
||||
videoElement: previewVideoRef.current,
|
||||
frameRate: exportSettings.frameRate,
|
||||
maxLongEdge: 960,
|
||||
signal: controller.signal,
|
||||
onProgress: ({ progress, phaseKey, phaseParams, frameIndex = 0, totalFrames = 0, backend = "" }) => setRemasterJob((job) => ({
|
||||
...job,
|
||||
running: true,
|
||||
progress,
|
||||
phase: "",
|
||||
phaseKey,
|
||||
phaseParams,
|
||||
frameIndex,
|
||||
totalFrames,
|
||||
backend: backend || job.backend,
|
||||
})),
|
||||
});
|
||||
if (controller.signal.aborted) return;
|
||||
const processedUrl = URL.createObjectURL(result.blob);
|
||||
imageUrlRefs.current.add(processedUrl);
|
||||
const processed = {
|
||||
src: processedUrl,
|
||||
blob: result.blob,
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
sourceStart: 0,
|
||||
sourceDuration: result.sourceDuration,
|
||||
trackFrames: [],
|
||||
};
|
||||
setVisualSegments((items) => items.map((item) => item.id === selectedVisualSegment.id ? {
|
||||
...item,
|
||||
...processed,
|
||||
enhancement: {
|
||||
enabled: true,
|
||||
mode: "remaster-drunet-full",
|
||||
original,
|
||||
processed,
|
||||
frameRate: result.frameRate,
|
||||
totalFrames: result.totalFrames,
|
||||
backend: result.backend,
|
||||
quality: remasterQuality,
|
||||
},
|
||||
} : item));
|
||||
setRemasterJob({ running: false, mode: "clip", segmentId: selectedVisualSegment.id, progress: 100, phase: t("remasterClipReady"), frameIndex: result.totalFrames, totalFrames: result.totalFrames, startedAt: 0 });
|
||||
notify(t("remasterClipReady"));
|
||||
} catch (error) {
|
||||
if (error?.name === "AbortError") notify(t("remasterCanceled"));
|
||||
else notify(error instanceof Error ? error.message : t("remasterFailed"));
|
||||
setRemasterJob({ running: false, mode: "clip", segmentId: selectedVisualSegment.id, progress: 0, phase: "", frameIndex: 0, totalFrames: 0, startedAt: 0 });
|
||||
} finally {
|
||||
if (remasterAbortControllerRef.current === controller) remasterAbortControllerRef.current = null;
|
||||
}
|
||||
};
|
||||
const exportElapsedSeconds = useExportElapsed(exporting, exportStartRef);
|
||||
const {
|
||||
effectiveCaptionPlacement, previewSmartCropRect, previewVisionAnalysis,
|
||||
@@ -476,15 +346,6 @@ export function App() {
|
||||
setScript, setSelectedSegmentId, setSelectedTrack,
|
||||
setVisionRecords, trackLocks,
|
||||
});
|
||||
const createCaptionFromPreview = (text, placement) => {
|
||||
const start = Math.max(0, currentTime);
|
||||
const segment = { id: crypto.randomUUID(), text, hidden: false, weight: 1, start, end: start + 2.5 };
|
||||
commitCaptionSegments([...captionSegments, segment].sort((a, b) => (a.start ?? 0) - (b.start ?? 0)), "字幕已加入时间线", 0);
|
||||
setSelectedSegmentId(segment.id);
|
||||
setCaptionPlacement({ x: placement.x, y: placement.y });
|
||||
setCaptionPosition("custom");
|
||||
};
|
||||
|
||||
const {
|
||||
clearAudioTrack, clearMusicTrack, clearSourceAudioTrack, commitAudio,
|
||||
replaceAudio, replaceMusic, replaceSourceAudio,
|
||||
@@ -605,7 +466,7 @@ export function App() {
|
||||
selectedStickerSegmentId, selectedTrack, selectedVisualSegmentId, setCurrentVisualAsset,
|
||||
setFitMode, setRatioId, setSelectedSegmentId, setSelectedVisualSegmentId,
|
||||
setUserAssets, sourceAudioBlob, sourceAudioUrlRef, stickerSegments,
|
||||
remasterAbortControllerRef, visionAbortControllerRef, visionObjectUrlsRef, visualSegments,
|
||||
visionAbortControllerRef, visionObjectUrlsRef, visualSegments,
|
||||
voiceRecorderStreamRef, voiceRecorderTimerRef,
|
||||
});
|
||||
|
||||
@@ -706,7 +567,9 @@ export function App() {
|
||||
setRatioId, setScript, setSelectedFilterId, setSelectedSegmentId, setSelectedStickerId,
|
||||
setSelectedStickerSegmentId, setSelectedTransitionId, setSelectedVoiceId, setShowFileMenu,
|
||||
setSourceAudioAssetId, setSourceAudioLinked, setSourceAudioVolume, setSpeed, setStickerSegments, setTimelineZoom, setTrackVisibility,
|
||||
setTimelineHorizon,
|
||||
setVisualSegments, setVolume, setCurrentVisualAsset, sourceAudioBlob, sourceAudioDuration,
|
||||
markTimelineViewRestored: (hasContent) => { timelineImportRestoreRef.current = hasContent; },
|
||||
sourceAudioAssetId, sourceAudioLinked, sourceAudioName, sourceAudioStart, sourceAudioVolume, speed, stickerSegments,
|
||||
timelineZoom, trackVisibility, visualSegments, volume,
|
||||
});
|
||||
@@ -877,15 +740,14 @@ export function App() {
|
||||
currentTime={currentTime}
|
||||
seekTo={seekTo}
|
||||
notify={notify}
|
||||
activeTool={activeTool}
|
||||
getDraggedAsset={getDraggedAsset}
|
||||
applyAssetToTrack={applyAssetToTrack}
|
||||
onCreateCaptionAt={createCaptionFromPreview}
|
||||
/>
|
||||
|
||||
<VoicePanel
|
||||
t={t}
|
||||
activeTool={activeTool}
|
||||
captionVoiceFocusRequest={captionVoiceFocusRequest}
|
||||
status={status}
|
||||
statusText={statusText}
|
||||
voiceTab={voiceTab}
|
||||
@@ -958,12 +820,6 @@ export function App() {
|
||||
visualLocalTime={visualLocalTime}
|
||||
visualTimelineStart={selectedVisualRange?.start ?? 0}
|
||||
updateSelectedVisualEffects={updateSelectedVisualEffects}
|
||||
remasterJob={remasterJob}
|
||||
remasterQuality={remasterQuality}
|
||||
setRemasterQuality={setRemasterQuality}
|
||||
enhanceSelectedVisualFrame={enhanceSelectedVisualFrame}
|
||||
enhanceSelectedVisualClip={enhanceSelectedVisualClip}
|
||||
clearSelectedVisualEnhancement={clearSelectedVisualEnhancement}
|
||||
selectedFilterId={selectedFilterId}
|
||||
setSelectedFilterId={setSelectedFilterId}
|
||||
trOption={trOption}
|
||||
@@ -990,6 +846,7 @@ export function App() {
|
||||
selectedTrack={selectedTrack}
|
||||
setSelectedTrack={setSelectedTrack}
|
||||
setActiveTool={setActiveTool}
|
||||
requestCaptionVoiceFocus={() => setCaptionVoiceFocusRequest((request) => request + 1)}
|
||||
trackVisibility={trackVisibility}
|
||||
toggleTrackVisibility={toggleTrackVisibility}
|
||||
trackLocks={trackLocks}
|
||||
@@ -1060,7 +917,6 @@ export function App() {
|
||||
|
||||
<AssetDragPreview preview={assetDragPreview} t={t} />
|
||||
<ExportProgressOverlay exporting={exporting} percent={exportPercent} phase={exportPhase} elapsedSeconds={exportElapsedSeconds} t={t} />
|
||||
<RemasterProgressOverlay job={remasterJob} onCancel={cancelRemasterEnhancement} t={t} />
|
||||
{shouldShowLanguageIntro ? (
|
||||
<LanguageIntro t={t} closing={introClosing} onChoose={chooseInterfaceLanguage} />
|
||||
) : null}
|
||||
|
||||
Reference in new issue
Block a user