Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Editor: a part pulled out of a clip's end continues it; a range drawn on its own is a separate video

Bowen Xue4c193c53eb08
diff --git a/freevideo_engine/comfy_editor.py b/freevideo_engine/comfy_editor.py
index 046e6e0..852d9e3 100644
--- a/freevideo_engine/comfy_editor.py
+++ b/freevideo_engine/comfy_editor.py
@@ -261,6 +261,11 @@ def validate(record):
if source is None:
raise ValueError('Splice requires source')
clip['splice'] = _splice(raw['splice'])
+ if 'follows' in raw:
+ # The part this one continues; a range drawn on its own has none.
+ if kind != 'video' or not isinstance(raw['follows'], str) or not _CLIP.fullmatch(raw['follows']) or raw['follows'] == identity:
+ raise ValueError('Invalid clip continuation')
+ clip['follows'] = raw['follows']
if 'target_frames' in raw:
if not _whole(raw['target_frames'], 1, 10**7):
raise ValueError('Invalid target frame count')
diff --git a/web/editor.js b/web/editor.js
index 6359778..41b4d27 100644
--- a/web/editor.js
+++ b/web/editor.js
@@ -462,8 +462,11 @@ export function openEditor({api, app, from = null, panel = {}, components: given
canGenerate(text) {
if (!store.generationAvailable || !actions.supportedSelection() || jobActive()) return false;
const range = selectionRange();
- const before = state.record.tracks[0].clips.find(clip => clip.start + clip.frames === range.start && clip.source && clip.extend && clip.in + clip.frames === clip.length);
- return !!text.trim() || !!before;
+ // Only a part pulled out of a finished one needs no description: it continues that one.
+ const head = state.record.tracks[0].clips.find(clip => clip.start === range.start);
+ const before = !!head && model.continuesBefore(state.record, head.id) && state.record.tracks[0].clips.some(clip =>
+ clip.start + clip.frames === range.start && clip.source && clip.extend && clip.in + clip.frames === clip.length);
+ return !!text.trim() || before;
},
previewRange: selection => genbar?.preview(selection),
async estimate(selection) {
diff --git a/web/editor_model.js b/web/editor_model.js
index 8133a1c..6c5b47f 100644
--- a/web/editor_model.js
+++ b/web/editor_model.js
@@ -160,6 +160,8 @@ export function parse(value) {
// Who last wrote the description, and an outside reference (a shot id) for callers.
if (item.text_by !== undefined) { check(TEXT_BY.includes(item.text_by), 'text'); clip.text_by = item.text_by; }
if (item.ref !== undefined) { check(typeof item.ref === 'string' && REF.test(item.ref), 'ref'); clip.ref = item.ref; }
+ // The part this one was pulled out of, or the part before it in the same range.
+ if (item.follows !== undefined) { check(kind === 'video' && typeof item.follows === 'string' && ID.test(item.follows) && item.follows !== item.id, 'follows'); clip.follows = item.follows; }
check(source !== null || (item.take === undefined && item.made_text === undefined), 'versions'); madeFields(item, clip);
Object.assign(clip, audioClipFields(item, kind));
Object.assign(clip, parseSpeedData(item, kind));
@@ -507,6 +509,10 @@ export function split(record, id, frame, {by = 'user'} = {}) {
if (!clip.source) { clip.in = right.in = 0; clip.length = clip.frames; right.length = right.frames; }
right.versions = right.versions.map(version => ({...version, in: version.in + left}));
for (const item of [clip, right]) item.versions = item.versions.filter(version => version.in < version.length);
+ // The two halves of a part that is not generated yet stay one video.
+ delete right.follows; if (!clip.source && trackOf(next, clip.id).id === 'v1') right.follows = clip.id;
+ // What continued the cut part now continues its second half.
+ for (const later of trackOf(next, clip.id).clips) if (later.follows === clip.id && later.start === end(right)) later.follows = right.id;
trackOf(next, clip.id).clips.push(right); rights.push(right);
}
if (rights.length === 2) { rights[0].link = rights[1].id; rights[1].link = rights[0].id; }
@@ -553,9 +559,9 @@ function segmentLengths(frames, maxSeconds = RULES.maxSeconds, maxFollowSeconds
check(typeof maxFollowSeconds === 'number' && Number.isFinite(maxFollowSeconds) && maxFollowSeconds >= RULES.minSeconds, 'range');
const max = Math.floor(Math.min(RULES.maxSeconds, maxSeconds)) * FPS, follow = Math.floor(Math.min(RULES.maxSeconds, maxFollowSeconds)) * FPS, lengths = [];
let left = Math.max(RULES.minSeconds, Math.round(frames / FPS)) * FPS;
- // Up to half a minute is one generation wherever this device makes it in one;
- // anything longer, or beyond the device, goes in parts of a quarter minute.
- if (left <= Math.floor(Math.min(RULES.singleSeconds, maxSeconds)) * FPS) return [left];
+ // Under half a minute is one generation wherever this device makes it in one;
+ // half a minute or more, or beyond the device, goes in parts of a quarter minute.
+ if (left < RULES.singleSeconds * FPS && left <= Math.floor(maxSeconds) * FPS) return [left];
check(left <= RULES.maxClips * max, 'range');
while (left) { const length = Math.min(left, lengths.length ? follow : max); lengths.push(length); left -= length; }
const last = lengths.length - 1;
@@ -594,18 +600,32 @@ function remember(clip, source = null) {
seen.add(identity); return true;
}).slice(0, 50);
}
+// A part continues the one before it only when it was pulled out of that part's end, or both were drawn as one range.
+// A range drawn on its own starts a new video, even when it touches the part before it.
+const continuing = (clip, before) => !!clip && !!before && before.id !== clip.id && end(before) === clip.start
+ && (clip.follows === before.id || (clip.part !== null && clip.part === before.part));
+const wholeEnd = clip => !!clip.source && clip.extend && clip.in + clip.frames === clip.length;
+const partBefore = (record, clip) => trackBy(record, 'v1').clips.find(before => continuing(clip, before)) ?? null;
+// Whether the part is drawn attached to the one before it on its track.
+export function continuesBefore(record, id) {
+ const clip = find(record, id); if (!clip) return false;
+ const video = trackOf(record, id).id === 'v1' ? clip : clip.link ? find(record, clip.link) : null;
+ return !!video && trackBy(record, 'v1').clips.includes(video) && !!partBefore(record, video);
+}
// The lengths one range is generated in, as planRange lays them out on empty tracks.
export const partLengths = (frames, {maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds} = {}) => segmentLengths(frames, maxSeconds, maxFollowSeconds);
// One video is generated in at most RULES.maxParts parts: the longest range that still fits.
-export function maxRangeFrames(record, {start, maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds}) {
- const before = trackBy(record, 'v1').clips.find(clip => end(clip) === start && clip.source && clip.extend && clip.in + clip.frames === clip.length);
+export function maxRangeFrames(record, {continues = false, maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds}) {
+ const before = continues;
const follow = Math.floor(Math.min(RULES.maxSeconds, maxFollowSeconds)) * FPS;
- return (before ? follow : Math.floor(Math.min(RULES.maxSeconds, maxSeconds)) * FPS) + (RULES.maxParts - 1) * follow;
+ // The part being continued is the first of the five.
+ return before ? (RULES.maxParts - 1) * follow : Math.floor(Math.min(RULES.maxSeconds, maxSeconds)) * FPS + (RULES.maxParts - 1) * follow;
}
// Manual boundaries use device limits, not the automatic fifteen-second preference.
-export function rangeParts(record, {start, frames, parts, maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds}) {
- const before = trackBy(record, 'v1').clips.find(clip => end(clip) === start && clip.source && clip.extend && clip.in + clip.frames === clip.length);
- const first = before ? maxFollowSeconds : maxSeconds;
+export function rangeParts(record, {start, frames, parts, continues, maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds}) {
+ // A range that starts on a part pulled out of the one before it keeps that part's shorter limit.
+ const head = trackBy(record, 'v1').clips.find(clip => clip.start === start);
+ const first = continues ?? !!(head && partBefore(record, head)) ? maxFollowSeconds : maxSeconds;
const valid = Array.isArray(parts) && parts.length > 0 && parts.length <= RULES.maxClips
&& parts.every((count, i) => whole(count, RULES.minSeconds * FPS) && count % FPS === 0
&& count <= Math.floor(i ? maxFollowSeconds : first) * FPS)
@@ -630,8 +650,8 @@ export function resizePlannedBoundary(record, leftId, rightId, frame, limits = {
&& left.part && left.part === right.part, 'range');
const members = [...pair(record, leftId), ...pair(record, rightId)]; busy(members);
check(members.every(clip => clip.pending && !clip.source), 'unsupported');
- const preceding = trackOf(record, leftId).clips.some(clip => end(clip) === left.start
- && ((clip.part === left.part && clip.pending) || (clip.source && clip.extend && clip.in + clip.frames === clip.length)));
+ const video = trackOf(record, leftId).id === 'v1' ? left : find(record, left.link);
+ const preceding = !!video && !!partBefore(record, video);
const maxSeconds = limits.maxSeconds ?? RULES.maxSeconds, maxFollowSeconds = limits.maxFollowSeconds ?? maxSeconds;
const result = adjustPartBoundary([left.frames, right.frames], 0, frame - left.start,
{maxSeconds: preceding ? maxFollowSeconds : maxSeconds, maxFollowSeconds});
@@ -688,8 +708,7 @@ export function planRange(record, {start, frames, parts, target = 'both', text =
}
check(boundary === start + frames, 'unsupported');
}
- const continuesAt = position => trackBy(record, 'v1').clips.some(clip => end(clip) === position && clip.source && clip.extend && clip.in + clip.frames === clip.length);
- const firstMaximum = continuesAt(start) ? maxFollowSeconds : maxSeconds;
+ const firstMaximum = videoHits[0]?.start === start && partBefore(record, videoHits[0]) ? maxFollowSeconds : maxSeconds;
let next = copy(record);
const originals = videoHits.length && videoHits.every(c => c.source) ? record.tracks.slice(0, 2).map(t => ({...t, clips: t.clips.filter(c => overlaps(c, start, frames))})) : null;
// A new attempt replaces an abandoned transaction over the same originals.
@@ -764,6 +783,9 @@ export function planRange(record, {start, frames, parts, target = 'both', text =
position += count;
}
}
+ // The new parts of one range are one video: each continues the part drawn before it.
+ const drawn = trackBy(next, 'v1').clips.filter(clip => clip.part === part).sort((a, b) => a.start - b.start);
+ drawn.forEach((clip, index) => { if (index && !clip.source && end(drawn[index - 1]) === clip.start) clip.follows = drawn[index - 1].id; });
if (originals) {
const clips = next.tracks.slice(0, 2).map(t => ({...t, clips: t.clips.filter(c => c.part === part)}));
next.replacements = [...(next.replacements || []), {part, originals: structuredClone(originals), clips: structuredClone(clips), rolledBack: false}];
@@ -787,10 +809,11 @@ export function extendClip(record, id, frames, {maxSeconds = RULES.maxSeconds, m
// A continuation adds a new pair; crossing sound on either lane is not a
// replacement. Plan in an empty record, then put the sound in the free lane.
const next = copy(restored), sound = sourceAudioTrack(next, start, count);
- const parts = rangeParts(restored, {start, frames: count, maxSeconds, maxFollowSeconds});
+ const parts = rangeParts(restored, {start, frames: count, continues: true, maxSeconds, maxFollowSeconds});
const planned = planRange({...emptyProject(restored), serial: next.serial},
{start, frames: count, parts, target: 'both', text: clip.text, maxSeconds: maxFollowSeconds, maxFollowSeconds});
- trackBy(next, 'v1').clips.push(...planned.tracks[0].clips);
+ // Pulled out of this part's end: the new parts continue it.
+ trackBy(next, 'v1').clips.push(...planned.tracks[0].clips.map(added => added.start === start ? {...added, follows: clip.id} : added));
sound.clips.push(...planned.tracks[1].clips);
next.serial = planned.serial;
return finish(next);
@@ -808,8 +831,13 @@ function generationClips(record, ids) {
const netFrames = (frames, continues) => continues ? Math.max(34, Math.ceil(frames / RULES.step) * RULES.step)
: Math.max(39, RULES.first + Math.ceil((frames - RULES.first) / RULES.step) * RULES.step);
function generationPlan(record, clips) {
- const first = clips[0], before = trackBy(record, 'v1').clips.find(clip => end(clip) === first.start && clip.source && clip.extend && clip.in + clip.frames === clip.length);
- const replacing = clips.some(clip => clip.source);
+ const replacing = clips.some(clip => clip.source), videos = [];
+ // Each run of parts that continue one another is one video and keeps its own length.
+ for (const clip of clips) { if (videos.length && continuing(clip, videos.at(-1).at(-1))) videos.at(-1).push(clip); else videos.push([clip]); }
+ return videos.flatMap(video => videoPlan(record, video, replacing));
+}
+function videoPlan(record, clips, replacing) {
+ const first = clips[0], before = trackBy(record, 'v1').clips.find(clip => continuing(first, clip) && wholeEnd(clip));
// Revealing a predecessor's hidden tail reduces the new visible range.
const credit = clips.every(clip => clip.target_frames !== undefined && !clip.source)
? clips.reduce((sum, clip) => sum + clip.target_frames - clip.frames, 0) : 0;
@@ -818,11 +846,12 @@ function generationPlan(record, clips) {
const target_frames = clip.target_frames ?? clip.frames; ideal += target_frames;
// Existing playback bounds and fill's visible length are invariant.
// A replacement may therefore need one more grid step than a draft.
- const continues = index > 0 || !!before;
+ const previous = index ? (continuing(clip, clips[index - 1]) ? clips[index - 1] : null) : before ?? null;
+ const continues = !!previous;
const net_frames = netFrames(Math.max(ideal - real, replacing ? clip.frames : 0), continues); real += net_frames;
const frames = replacing ? clip.frames : index === clips.length - 1 ? ideal - (real - net_frames) : net_frames;
check(frames >= 1, 'range');
- return {clip, before: index ? clips[index - 1] : before ?? null, target_frames, net_frames,
+ return {clip, before: previous, target_frames, net_frames,
request_frames: net_frames + (continues ? RULES.overlap : 0), frames};
});
}
@@ -831,7 +860,7 @@ export function prepare(record, ids) {
const next = copy(record);
const replacing = clips.some(clip => clip.source);
if (!replacing && clips.every(clip => clip.target_frames === undefined)) {
- const before = trackBy(next, 'v1').clips.find(clip => end(clip) === clips[0].start && clip.source && clip.extend);
+ const before = trackBy(next, 'v1').clips.find(clip => continuing(clips[0], clip) && clip.source && clip.extend);
if (before) {
const members = pair(next, before.id);
const spare = Math.min(...members.map(clip => clip.length - clip.in - clip.frames));
@@ -881,9 +910,16 @@ function update(record, ids, change) {
}
export function startAttempt(record, ids, text, {by = 'user'} = {}) {
check(validText(text) && TEXT_BY.includes(by), 'text');
- const next = copy(record), part = freshId(next), selected = linkedIds(next, ids);
+ const next = copy(record), selected = linkedIds(next, ids), parts = new Map();
busy(all(next).filter(clip => selected.has(clip.id)));
- for (const clip of all(next)) if (selected.has(clip.id)) { written(clip, text, by); clip.part = part; clip.pending = 'draft'; clip.reason = clip.job = null; }
+ // Parts that continue one another stay one video; ranges drawn apart stay apart, however many are started together.
+ let part = null, last = null;
+ for (const clip of trackBy(record, 'v1').clips.filter(clip => selected.has(clip.id)).sort((a, b) => a.start - b.start)) {
+ if (!last || !continuing(clip, last)) part = freshId(next);
+ parts.set(clip.id, part); if (clip.link) parts.set(clip.link, part); last = clip;
+ }
+ const other = () => part ??= freshId(next);
+ for (const clip of all(next)) if (selected.has(clip.id)) { written(clip, text, by); clip.part = parts.get(clip.id) ?? other(); clip.pending = 'draft'; clip.reason = clip.job = null; }
return finish(next);
}
export function assignJob(record, ids, job, {prepared = record} = {}) {
diff --git a/web/editor_room.js b/web/editor_room.js
index 935fa0f..f971e1f 100644
--- a/web/editor_room.js
+++ b/web/editor_room.js
@@ -90,6 +90,8 @@ export function pasteContent(record, content, at) {
for (const item of entries) {
const clip = item.clip;
clip.id = ids.get(clip.id); clip.link = ids.get(clip.link) ?? null;
+ // A copy continues only what was copied with it.
+ if (clip.follows !== undefined) { if (ids.has(clip.follows)) clip.follows = ids.get(clip.follows); else delete clip.follows; }
if (clip.part) { if (!parts.has(clip.part)) parts.set(clip.part, `c${++next.serial}`); clip.part = parts.get(clip.part); }
if (item.kind === 'video') item.track = 'v1';
let track = next.tracks.find(track => track.id === item.track);
diff --git a/web/editor_state.js b/web/editor_state.js
index 4643443..ee95fce 100644
--- a/web/editor_state.js
+++ b/web/editor_state.js
@@ -12,8 +12,8 @@ export function createEditorState(record, {limit = 200} = {}) {
let current = parse(record), selection = null, rangeDraft = null, playhead = 0, zoom = 12;
let maxSerial = current.serial;
const retainSerial = record => { maxSerial = Math.max(maxSerial, record.serial); return record.serial < maxSerial ? parse({...record, serial: maxSerial}) : record; };
- let undo = [], redo = []; const listeners = new Set();
- const remember = entry => { undo = limit ? [...undo, entry].slice(-limit) : []; redo = []; };
+ let undo = [], redo = [], step = 0; const listeners = new Set();
+ const remember = entry => { step++; undo = limit ? [...undo, entry].slice(-limit) : []; redo = []; };
const selected = () => ({selection, rangeDraft});
const restore = value => { selection = value.selection; rangeDraft = value.rangeDraft; };
const emit = (type, label) => {
@@ -49,7 +49,7 @@ export function createEditorState(record, {limit = 200} = {}) {
}
function travel(from, to, side) {
if (!from.length) return current;
- const entry = from.pop();
+ step++; const entry = from.pop();
to.push(entry.record ? {...entry, record: current} : entry);
if (entry.record) current = retainSerial(entry.record);
if (entry[side]) restore(entry[side]);
@@ -71,7 +71,7 @@ export function createEditorState(record, {limit = 200} = {}) {
const selectionChanged = cleared || selectionAfter !== undefined;
const entry = {record: current, label, ...(selectionChanged ? {before: selected(), after: {selection: normalized(selectionAfter ?? null, next), rangeDraft: selectionAfter?.kind === 'range' && typeof rangeText === 'string' ? {text: rangeText} : null}} : {})};
// Generation is a barrier: older full-record snapshots must not remove it.
- if (checkpoint) { undo = []; redo = []; } else remember(entry);
+ if (checkpoint) { step++; undo = []; redo = []; } else remember(entry);
if (selectionChanged) restore(entry.after);
current = next; emit('record', label); reconcile();
if (selectionChanged) emit('selection');
@@ -79,6 +79,10 @@ export function createEditorState(record, {limit = 200} = {}) {
},
undo() { return travel(undo, redo, 'before'); },
redo() { return travel(redo, undo, 'after'); },
+ // Counts the steps taken through the history, so a caller can tell that its own step is still the newest.
+ get step() { return step; },
+ // Takes the newest step back as if it never happened: nothing is left to redo.
+ withdraw(at) { if (at !== step || !undo.length) return false; travel(undo, redo, 'before'); redo.pop(); return true; },
settle(change) {
const attempt = record => { try { return retainSerial(parse(change(record))); } catch (error) { if (error instanceof EditError) return record; throw error; } };
const update = entry => entry.record ? {...entry, record: attempt(entry.record)} : entry;
@@ -87,7 +91,7 @@ export function createEditorState(record, {limit = 200} = {}) {
current = next; undo = nextUndo; redo = nextRedo;
if (changed) { emit('record'); reconcile(); } return current;
},
- replace(record) { const next = parse(record); maxSerial = next.serial; current = next; undo = []; redo = []; selection = null; rangeDraft = null; playhead = 0; emit('record'); emit('selection'); emit('playhead'); return current; },
+ replace(record) { const next = parse(record); maxSerial = next.serial; current = next; step++; undo = []; redo = []; selection = null; rangeDraft = null; playhead = 0; emit('record'); emit('selection'); emit('playhead'); return current; },
restoreView(value) {
// View drafts are untrusted and may refer to content changed elsewhere.
let next = null;
diff --git a/web/editor_text.js b/web/editor_text.js
index 6dfd39a..f70ba82 100644
--- a/web/editor_text.js
+++ b/web/editor_text.js
@@ -27,7 +27,7 @@ export function createEditorText({element,state,t,actions,adjust,player,toolbar,
const notice=el('span');notice.setAttribute('role','button');notice.tabIndex=0;notice.onclick=()=>jumpMissing();notice.onkeydown=e=>{if(['Enter',' '].includes(e.key)){e.preventDefault();jumpMissing();}}; notice.classList.add('fv-ed-text-notice'); notice.hidden=true; exportBox.prepend(notice);
const menu=el('div','fv-ed-text-menu'); menu.hidden=true; menu.setAttribute('role','menu'); element.append(menu);
const names={sans:t('Sans','黑体'),serif:t('Serif','宋体'),kai:t('Kai','楷体'),mono:t('Mono','等宽')};
- let disposed=false,ready=false,table=null,loadError=false,draft=null,lastStyle={},editing=null,drag=null,raf=null,layouts=new Map(),mapped={x:0,y:0,w:1,h:1};
+ let disposed=false,ready=false,table=null,loadError=false,draft=null,fresh=null,typing=null,lastStyle={},editing=null,drag=null,raf=null,layouts=new Map(),mapped={x:0,y:0,w:1,h:1};
const panels=new Map(), commands=createSelectionActions({state,t,actions});
const selected=()=>state.selection?.kind==='clip' && state.selection.ids.length===1 ? model.find(state.record,state.selection.ids[0]) : null;
const record=()=>draft?.record||state.record;
@@ -48,14 +48,23 @@ export function createEditorText({element,state,t,actions,adjust,player,toolbar,
apply(t('Content','内容'),change);
}
function commitDraft(){if(draft){const change=draft.change;apply(t('Text','文字'),change);const c=selectedText();if(c?.text_kind==='text')lastStyle={...styleOf(state.record,c)};}}
+ // Editing a text ended. One left without words is taken away; one that never had any leaves no step behind.
+ function endEditing(id){
+ const shown=model.find(record(),id),made=fresh?.id===id?fresh:null;if(made)fresh=null;
+ if(!isText(shown)||shown.text.trim()||locked(shown)){commitDraft();return;}
+ draft=null;if(!model.find(state.record,id)){render();return;}
+ if(!made||!state.withdraw(made.step))apply(t('Delete','删除'),r=>model.remove(r,[id]));
+ render();
+ }
+ function finishContent(){if(typing){const id=typing;typing=null;endEditing(id);}else commitDraft();}
function add(kind,at=state.playhead){
commitDraft(); finishInline(); player.pause();
const text='';
let id;
if(!apply(kind==='text'?t('Text','文字'):t('Subtitles','字幕'),r=>{const next=addText(r,{kind,at,text,style:{...lastStyle,x:.5,y:.5}});id=`c${next.serial}`;return next;}))return;
- state.select({kind:'clip',ids:[id]});state.seek(at);adjust.open();
+ fresh={id,step:state.step};state.select({kind:'clip',ids:[id]});state.seek(at);adjust.open();
if(kind==='text') startInline(id,true);
- else {const content=panels.get(kind)?.content;content?.focus();content?.select();}
+ else {const content=panels.get(kind)?.content;content?.focus();content?.select();typing=id;}
}
actions.addText=(kind,at)=>add(kind,at);
function buildPanel(host,kind){
@@ -99,11 +108,12 @@ export function createEditorText({element,state,t,actions,adjust,player,toolbar,
file.onchange=async()=>{const f=file.files?.[0];if(!f)return;let text;try{if(f.size>4*1024*1024)throw new Error();text=await f.text();parseSRT(text);}catch{actions.notify?.(t('Could not read this subtitle file','读不出这个字幕文件'));return;}finally{file.value='';}
if(apply(t('Import subtitle file','导入字幕文件'),r=>importSRT(r,text))){const missing=projectMissing(state.record);if(missing.length)actions.notify?.(missingHint([...new Set(missing.flatMap(r=>r.chars))],t));}};host.append(importButton,file);
}
- content.oninput=()=>{const c=selectedText();if(c)updateContent(c,content.value,true);};content.onchange=commitDraft;
+ content.oninput=()=>{const c=selectedText();if(c)updateContent(c,content.value,true);};content.onchange=finishContent;
+ content.onfocus=()=>{typing=selectedText()?.id??null;};content.onblur=finishContent;
content.onkeydown=e=>{
e.stopPropagation();
- if(e.key==='Escape'){e.preventDefault();commitDraft();content.blur();}
- else if(kind==='subtitle' && e.key==='Enter' && !e.shiftKey && !e.isComposing){e.preventDefault();const c=selectedText();commitDraft();if(c)add('subtitle',c.start+c.frames);}
+ if(e.key==='Escape'){e.preventDefault();finishContent();content.blur();}
+ else if(kind==='subtitle' && e.key==='Enter' && !e.shiftKey && !e.isComposing){e.preventDefault();const c=selectedText();if(!c||!model.find(record(),c.id)?.text.trim())return;commitDraft();add('subtitle',c.start+c.frames);content.value='';}
};
panels.set(kind,{content,warning,overflow,font,size,sizeNumber,custom,backing,bold,align,position,duration,fade,host});
updatePanel(kind);
@@ -220,7 +230,7 @@ export function createEditorText({element,state,t,actions,adjust,player,toolbar,
input.onkeydown=e=>{e.stopPropagation();if(e.key==='Escape'){e.preventDefault();finishInline();} };input.onkeyup=e=>e.stopPropagation();
input.onblur=()=>finishInline();render();input.focus();if(selectAll)input.select();
}
- function finishInline(){if(!editing)return;const old=editing;editing=null;old.input.onblur=null;const c=model.find(state.record,old.id);if(c&&c.text!==old.input.value)updateContent(c,old.input.value);else commitDraft();old.input.remove();render();}
+ function finishInline(){if(!editing)return;const old=editing;editing=null;old.input.onblur=null;const c=model.find(state.record,old.id);if(!old.input.value.trim())endEditing(old.id);else if(c&&c.text!==old.input.value)updateContent(c,old.input.value);else commitDraft();old.input.remove();render();}
function guide(axis,value){const line=el('span','fv-ed-text-guide '+axis);line.style[axis==='x'?'left':'top']=`${value*100}%`;boundsLayer.append(line);}
function beginDrag(e,c){
if(e.button!==0||locked(c)||editing)return;e.preventDefault();e.stopPropagation();
diff --git a/web/editor_tracks.js b/web/editor_tracks.js
index 90ecf41..efde6c3 100644
--- a/web/editor_tracks.js
+++ b/web/editor_tracks.js
@@ -239,14 +239,10 @@ export function createTracks(host, {state, sources = {}, t = en => en, actions =
return {start, frames: end - start, tracks: [...new Set(items.map(item => item.track))]};
}
// A range cannot be drawn longer than one video may be; `fromEnd` keeps its end where it is.
- function capRange(selection, fromEnd = false) {
- const limits = actions.generationLimits?.();
- let most = model.maxRangeFrames(state.record, {...limits, start: selection.start});
+ function capRange(selection, fromEnd = false, continues = false) {
+ const most = model.maxRangeFrames(state.record, {...actions.generationLimits?.(), continues});
if (selection.frames <= most) return selection;
- if (!fromEnd) return {...selection, frames: most};
- const stop = selection.start + selection.frames;
- most = model.maxRangeFrames(state.record, {...limits, start: stop - most});
- return {...selection, start: stop - most, frames: most};
+ return fromEnd ? {...selection, start: selection.start + selection.frames - most, frames: most} : {...selection, frames: most};
}
function rangeParts(selection, record = state.record) {
return model.rangeParts(record, {...selection, ...actions.generationLimits?.()});
@@ -480,8 +476,11 @@ export function createTracks(host, {state, sources = {}, t = en => en, actions =
const visual = model.clipState(clip), key = sourceKey(clip);
item.element.dataset.state = visual; item.element.dataset.track = track.id;
item.element.dataset.busy = String(busy(clip)); item.element.dataset.extend = String(clip.extend && actions.generationAvailable?.() !== false && !busy(clip));
- item.element.classList.toggle('fv-ed-joined-left', track.clips[index - 1]?.start + track.clips[index - 1]?.frames === clip.start);
- item.element.classList.toggle('fv-ed-joined-right', track.clips[index + 1]?.start === clip.start + clip.frames);
+ // A part not generated yet is attached only to the part it continues; drawn on its own it stays a separate block.
+ const attached = (left, right) => !!left && !!right && left.start + left.frames === right.start
+ && (right.pending === null || model.continuesBefore(state.record, right.id));
+ item.element.classList.toggle('fv-ed-joined-left', attached(track.clips[index - 1], clip));
+ item.element.classList.toggle('fv-ed-joined-right', attached(clip, track.clips[index + 1]));
if (visual === 'failed' && track.kind === 'video') item.status.replaceChildren(icon('warning'));
else item.status.replaceChildren();
const status = {planned: t('Not generated yet', '还没生成'), running: t('Generating', '正在生成'),
@@ -643,11 +642,11 @@ export function createTracks(host, {state, sources = {}, t = en => en, actions =
for (const value of [frame, frame + length]) points.push(Math.round(value / grid) * grid);
return transportSnapPoints(state, points, pointerEvent);
}
- function boundaryLimits(start, part = null) {
+ // Only a part that continues another is held to the length of a continued part; a range being drawn never is.
+ function boundaryLimits(clip = null) {
const limits = actions.generationLimits?.() || {}, maxSeconds = limits.maxSeconds ?? model.RULES.maxSeconds;
const maxFollowSeconds = limits.maxFollowSeconds ?? maxSeconds;
- const before = state.record.tracks[0].clips.some(clip => clip.start + clip.frames === start
- && ((part && clip.part === part && clip.pending) || (clip.source && clip.extend && actions.generationAvailable?.() !== false && clip.in + clip.frames === clip.length)));
+ const before = !!clip && model.continuesBefore(state.record, clip.id);
return {maxSeconds: before ? maxFollowSeconds : maxSeconds, maxFollowSeconds};
}
function updatePointer(event) {
@@ -667,7 +666,7 @@ export function createTracks(host, {state, sources = {}, t = en => en, actions =
const parts = isRange ? gesture.parts : [gesture.clip.frames, gesture.neighbor.clip.frames];
const index = isRange ? gesture.boundary : 0, start = isRange ? gesture.range.start : gesture.clip.start;
const from = start + parts.slice(0, index).reduce((sum, count) => sum + count, 0);
- const result = model.adjustPartBoundary(parts, index, frame - from, boundaryLimits(start, gesture.clip?.part));
+ const result = model.adjustPartBoundary(parts, index, frame - from, boundaryLimits(isRange ? null : gesture.clip));
gesture.result = {...result, frame: from + result.parts[index]};
if (isRange) {
gesture.selection = {...gesture.range, parts: result.parts}; previewSelection = gesture.selection; renderSelection();
@@ -738,7 +737,7 @@ export function createTracks(host, {state, sources = {}, t = en => en, actions =
if (error) tooltip.hidden = true;
} else if (gesture.type === 'edge') {
let result = edgeParameters(gesture.clip, gesture.edge, frame, points, state.zoom, {canExtend: actions.generationAvailable?.() !== false});
- if (result.kind === 'extend') result.frames = capRange({start: result.frame, frames: result.frames}).frames;
+ if (result.kind === 'extend') result.frames = capRange({start: result.frame, frames: result.frames}, false, true).frames;
if (result.kind === 'planned') {
let preview;
try { preview = model.resizePlanned(state.record, gesture.id, gesture.edge, result.frame, actions.generationLimits?.()); }
diff --git a/web/first_run_guide.js b/web/first_run_guide.js
index 85478d4..e195707 100644
--- a/web/first_run_guide.js
+++ b/web/first_run_guide.js
@@ -11,13 +11,14 @@ export const REPLAY_TEXT = {
export const CHAPTERS = [
{id: 'describe', anchor: '[data-fv-guide="describe"]', added: false,
- en: 'Describe the picture and sound you want here.', zh: '在这里写下想看到的画面和声音。'},
+ en: 'Type your prompt here. You can have an agent follow the Skill at the top right, or turn on FreeToken enhancement.',
+ zh: '在这里输入提示词。可以让 Agent 参考右⁠上⁠角的 Skill,或开启 FreeToken 提示词增强。'},
{id: 'range', anchor: '[data-fv-guide="range"]', added: true,
en: 'See the available sizes and lengths here, and how long each takes.', zh: '在这里查看可生成的尺\u2060寸、时长和预计用时。'},
{id: 'generate', anchor: '[data-fv-guide="generate"]', added: false,
en: 'Choose "Generate video". Progress and the time left appear in the preview.', zh: '点“生成视频”,进度和剩\u2060余\u2060时\u2060间会显示在预览区。'},
{id: 'longer', anchor: '[data-fv-guide="longer"]', added: true,
- en: 'For a longer video, or to change part of one, choose "Edit".', zh: '要做更长的视频,或者修\u2060改\u2060其\u2060中\u2060一\u2060段,点“剪辑”。'},
+ en: 'For a longer video, or to change part of one, choose "Edit".', zh: '要做更长的视频,或者修\u2060改\u2060其\u2060中\u2060一\u2060段,点“剪辑视图”。'},
{id: 'agent', anchor: '[data-fv-guide="agent"]', added: true,
en: 'Connect Claude Code, Codex or another agent in Settings and let it make videos.', zh: '在设置里连接 Claude Code、Codex 等 Agent,让它生成视频。'},
];
diff --git a/web/studio.js b/web/studio.js
index 12c224c..a33958d 100644
--- a/web/studio.js
+++ b/web/studio.js
@@ -239,7 +239,7 @@ export function openStudio(node) {
window.addEventListener('freevideo-reference-prompt', promptChanged);
cleanup.push(() => window.removeEventListener('freevideo-reference-prompt', promptChanged));
const promptSection = section(t('Describe your scene', '描述画面'));
- const promptHelp = el('a', t('Guide ↗', '指南 ↗'), 'fv-prompt-help');
+ const promptHelp = el('a', 'Skill ↗', 'fv-prompt-help');
promptHelp.href = 'https://github.com/MiniMax-AI/MiniMax-H3/blob/main/skills/h3-prompt-writing/SKILL.md';
promptHelp.target = '_blank'; promptHelp.rel = 'noopener noreferrer';
promptHelp.title = t('MiniMax H3 prompt guide', 'MiniMax H3 提示词指南');
diff --git a/web/view_navigation.js b/web/view_navigation.js
index 878b60f..8a2ec16 100644
--- a/web/view_navigation.js
+++ b/web/view_navigation.js
@@ -34,9 +34,6 @@ export function viewSwitch(view, onStudio, onNodes, onEditor) {
const button = document.createElement('button'); button.type = 'button';
const text = document.createElement('span'); text.textContent = label; button.append(text);
button.dataset.label = label; button.dataset.view = id;
- button.title = {studio: t('Describe a video and generate it', '写一句描述,生成一段视频'),
- nodes: t('Build and adjust the workflow as a node graph', '用节点图搭建和调整工作流'),
- editor: t('Join several video and audio parts into one video', '把多段画面和声音接成一条视频')}[id];
if (id === 'editor') button.dataset.fvGuide = 'longer';
button.setAttribute('aria-pressed', String(view === id)); button.onclick = action;
group.append(button);