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 names known causes when subtitles, the subtitle download or a media import fail, and...

Bowen Xue7d16d6a0b3a2
diff --git a/freevideo_engine/comfy_editor.py b/freevideo_engine/comfy_editor.py
index 5150f7a..29d36e5 100644
--- a/freevideo_engine/comfy_editor.py
+++ b/freevideo_engine/comfy_editor.py
@@ -1055,9 +1055,11 @@ class ImportManager:
def prepare(self, identity):
try:
transcode(self.root, identity)
- except Exception:
+ except Exception as error:
+ # A full disk is not the file's fault, so the page says so instead of listing formats.
+ reason = _disk_full(error).get('reason', 'unreadable')
try:
- _import_update(self.root, identity, state='failed', reason='unreadable')
+ _import_update(self.root, identity, state='failed', reason=reason)
except (OSError, ValueError):
pass # The terminal snapshot is retained and retried by the worker/reads.
diff --git a/web/editor.js b/web/editor.js
index ffcb436..94e045e 100644
--- a/web/editor.js
+++ b/web/editor.js
@@ -1042,7 +1042,7 @@ export function openEditor({api, app, from = null, panel = {}, components: given
download: report => new Promise((resolve, reject) => {
const step = value => {
const install = value?.install;
- if (install?.state !== 'running') { resolve(install?.state === 'done'); return false; }
+ if (install?.state !== 'running') { resolve(install?.state === 'done' || install?.reason || false); return false; }
report(install.total > 0 ? install.done / install.total : 0); return true;
};
store.installEars().then(value => { if (step(value)) store.watchEarsPack(step); }, reject);
diff --git a/web/editor_library.js b/web/editor_library.js
index cac1cf8..17a1526 100644
--- a/web/editor_library.js
+++ b/web/editor_library.js
@@ -1,6 +1,7 @@
import {editorIcon} from './editor_icons.js';
import {sourceKey} from './editor_store.js';
import {issueButton} from './issue_button.js';
+import {connectionLostText} from './browser_extension.js';
const LIBRARY_ISSUE = ['Editor media library', '剪辑器素材库'];
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };
const stamp = frames => { const seconds = Math.floor((frames || 0) / 24); return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`; };
@@ -24,6 +25,10 @@ export function createEditorLibrary(host, {store, t, actions, state}) {
const uploading = new Map(), recentImports = new Map(), pendingAdds = new Map();
const preparing = () => t('Preparing this clip. It goes on the timeline when ready.', '素材准备好后会自动放到时间线上。');
const cannotOpen = () => t('This file cannot be opened. Supported formats: ', '这个文件打不开。支持的格式:') + FORMATS;
+ // Why an import did not work, and where to report it: only a file that could not be read lists the formats and asks for a report.
+ const importFailure = (reason, status) => status === 413 ? [t('This file is over 8 GiB. Trim or compress it, then try again.', '文件超过 8 GiB,请先剪短或压缩后再导入。')]
+ : reason === 'disk_full' ? [t('The disk is full. Free some space, then import again.', '磁盘空间不足,请清理出空间后再导入。')]
+ : reason === 'import_failed' ? [connectionLostText(t)] : [cannotOpen(), LIBRARY_ISSUE];
function metadata(row, kind) {
const g = row.geometry || row, cached = store.sources.get(`${kind}:${row.id}`);
return {frames: cached?.frames || Math.round(g.frames || (g.seconds || 0) * (g.fps || 24)), hasVideo: cached?.has_video ?? (kind === 'work' || row.kind === 'video'),
@@ -45,7 +50,7 @@ export function createEditorLibrary(host, {store, t, actions, state}) {
function requestAdd(row, kind, plus = false) {
if (disposed) return;
if (kind === 'work' || row.state === 'ready') return add(row, kind, plus).catch(actions.error);
- if (row.state === 'failed') { actions.notify?.(cannotOpen(), LIBRARY_ISSUE); return; }
+ if (row.state === 'failed') { actions.notify?.(...importFailure(row.reason)); return; }
const key = `${kind}:${row.id}`;
if (!pendingAdds.has(key)) pendingAdds.set(key, {plus, project: actions.projectToken?.()});
actions.notify?.(preparing());
@@ -58,7 +63,7 @@ export function createEditorLibrary(host, {store, t, actions, state}) {
if (row.state === 'ready') {
pendingAdds.delete(key);
add(row, 'import', pending.plus, {...pending, queued: true}).catch(actions.error);
- } else if (row.state === 'failed') { pendingAdds.delete(key); actions.notify?.(cannotOpen(), LIBRARY_ISSUE); }
+ } else if (row.state === 'failed') { pendingAdds.delete(key); actions.notify?.(...importFailure(row.reason)); }
}
}
function card(row, kind) {
@@ -74,7 +79,7 @@ export function createEditorLibrary(host, {store, t, actions, state}) {
else if (row.kind === 'audio') picture.append(el('span', 'fv-ed-audio-icon', '♫'));
if (ready) picture.append(el('span', 'fv-ed-source-time', stamp(metadata(row, kind).frames)));
else if (row.state === 'failed') {
- picture.append(el('span', 'fv-ed-source-preparing', t('Cannot open', '打不开')));
+ picture.append(el('span', 'fv-ed-source-preparing', row.reason === 'disk_full' ? t('Disk full', '磁盘已满') : t('Cannot open', '打不开')));
} else picture.append(el('span', 'fv-ed-source-preparing', t('Preparing', '准备中')
+ (Number.isFinite(row.fraction) ? ` ${Math.round(Math.max(0, Math.min(1, row.fraction)) * 100)}%` : '')));
button.append(picture);
@@ -97,7 +102,7 @@ export function createEditorLibrary(host, {store, t, actions, state}) {
plus.ondblclick = event => { event.preventDefault(); event.stopPropagation(); };
plus.onkeydown = event => { if (event.key === 'Enter' || event.key === ' ') insert(event); };
container.append(button, plus);
- if (kind !== 'work' && row.state === 'failed') container.append(issueButton(t, () => ({where: LIBRARY_ISSUE, message: t('Cannot open', '打不开')})));
+ if (kind !== 'work' && row.state === 'failed' && row.reason !== 'disk_full') container.append(issueButton(t, () => ({where: LIBRARY_ISSUE, message: t('Cannot open', '打不开')})));
return container;
}
function updateUsed() {
@@ -122,8 +127,11 @@ export function createEditorLibrary(host, {store, t, actions, state}) {
for (const row of shown) grid.append(card(row, tab));
updateUsed();
message.textContent = ''; // Empty states stay silent.
- for (const row of shown) if (row.state === 'failed') message.textContent = t('This file cannot be opened. Supported formats: ', '这个文件打不开。支持的格式:') + FORMATS;
- if (message.textContent) message.append(issueButton(t, () => ({where: LIBRARY_ISSUE, message: cannotOpen()})));
+ const failed = shown.findLast(row => row.state === 'failed');
+ if (failed) {
+ const [text, where] = importFailure(failed.reason); message.textContent = text;
+ if (where) message.append(issueButton(t, () => ({where, message: text})));
+ }
if (scroll > 0) {
const replacement = anchor && [...grid.querySelectorAll('.fv-ed-source')].find(node => node.dataset.key === anchor.dataset.key);
host.scrollTop = replacement ? scroll + replacement.getBoundingClientRect().top - anchorTop : scroll;
@@ -225,7 +233,7 @@ export function createEditorLibrary(host, {store, t, actions, state}) {
if (place) { placing.push({id: item.id, place}); placeReady(imported); }
else startPending([item]);
}
- } catch { actions.notify(cannotOpen(), LIBRARY_ISSUE); }
+ } catch (error) { actions.notify(...importFailure(error?.message === 'import_failed' ? 'import_failed' : error?.reason, error?.status)); }
finally { pendingAdds.delete(`import:${id}`); uploading.delete(id); render(); }
}
}
diff --git a/web/editor_store.js b/web/editor_store.js
index 2690216..caa8bc1 100644
--- a/web/editor_store.js
+++ b/web/editor_store.js
@@ -392,7 +392,8 @@ export function createEditorStore(api, {t = en => en, notify = () => {}, onGener
xhr.onload = () => {
release();
if (xhr.status === 404) { notice('import', 'Import is unavailable until you restart after updating.', '更新后重启可导入素材。'); resolve(null); return; }
- if (xhr.status < 200 || xhr.status >= 300) { reject(errorFor(xhr)); return; }
+ // The server's reason (a full disk) comes along, as with a failed save.
+ if (xhr.status < 200 || xhr.status >= 300) { let body = null; try { body = JSON.parse(xhr.responseText); } catch {} reject(Object.assign(errorFor(xhr), {reason: body?.reason})); return; }
try { resolve(JSON.parse(xhr.responseText).import); } catch (error) { reject(error); }
};
xhr.onerror = () => { release(); reject(new Error('import_failed')); };
diff --git a/web/editor_text.js b/web/editor_text.js
index 71e8403..df42b3f 100644
--- a/web/editor_text.js
+++ b/web/editor_text.js
@@ -3,7 +3,7 @@
import * as model from './editor_model.js';
import {FONT_KEYS} from './fonts.js';
import {row, button, slider, number, segmented, toggle} from './editor_adjust.js';
-import {isText, isTextTrack, addText, changeText, changeSubtitleStyle, styleOf, activeText, setTextTrack, parseSRT, importSRT, addSubtitles, defaults, cleanStyle, SUBTITLE_DEFAULTS} from './editor_text_model.js';
+import {isText, isTextTrack, addText, changeText, changeSubtitleStyle, styleOf, activeText, setTextTrack, parseSRT, decodeSRT, importSRT, addSubtitles, defaults, cleanStyle, SUBTITLE_DEFAULTS} from './editor_text_model.js';
import {loadCoverage, loadTextFonts, textFontStack, missingGlyphs, missingHint, overTwoHint, textLayout, drawText} from './editor_text_layout.js';
import {createSelectionActions, isTyping} from './editor_select.js';
import {plan} from './editor_geometry.js';
@@ -69,10 +69,14 @@ export function createEditorText({element,state,t,actions,adjust,player,toolbar,
function speechLabel(fraction){speech.shown=fraction;const p=Math.round(Math.min(1,Math.max(0,Number(fraction)||0))*100),size=Math.max(1,Math.round(speech.need/1e6)),text=fraction==null?(speech.need?t(`Auto subtitles · Download ${size} MB`,`自动字幕 · 下载 ${size} MB`):t('Auto subtitles','自动字幕')):speech.loading?t(`Cancel · Downloading ${p}%`,`取消 · 下载 ${p}%`):t(`Cancel · ${p}%`,`取消 · ${p}%`);for(const b of speech.buttons){b.textContent=text;b.hidden=!(speech.available||speech.need);}}
function speechEnd(text,where=null){speech.stop?.();speech.stop=null;speech.job=null;speech.busy=false;speech.loading=false;speechLabel(null);if(text)actions.notify?.(text,where);}
const speechFailed=()=>t('Could not create subtitles','没能生成字幕'),speechSilent=()=>t('No speech found','没有听到说话声');
- const speechReason=reason=>reason==='no_sound'?speechSilent():reason==='language'?t('Language not supported yet','暂不支持这种语言'):speechFailed();
+ const speechDisk=()=>t('The disk is full. Free some space, then try again.','磁盘空间不足,请清理出空间后重试。');
+ // Causes the person can act on are named and carry no issue button; anything else is unexplained.
+ const speechReasons={no_sound:speechSilent,language:()=>t('Language not supported yet','暂不支持这种语言'),too_long:()=>t('Auto subtitles work on up to 2 hours of sound.','自动字幕最多处理 2 小时的声音。'),
+ source_missing:()=>t('A source file is missing. Import it again from the library.','有素材的原文件找不到了,请在素材库重新导入。'),unreadable:()=>t('The sound in a clip cannot be read.','有素材的声音无法读取。'),disk_full:speechDisk};
+ const speechReason=reason=>(Object.hasOwn(speechReasons,reason)?speechReasons[reason]:speechFailed)();
function speechResult(job){
if(job.state==='running'){speechLabel(job.fraction);return true;}
- if(job.state!=='done'){speechEnd(job.state==='cancelled'?null:speechReason(job.reason),job.state==='cancelled'||['no_sound','language'].includes(job.reason)?null:SPEECH_ISSUE);return false;}
+ if(job.state!=='done'){speechEnd(job.state==='cancelled'?null:speechReason(job.reason),job.state==='cancelled'||Object.hasOwn(speechReasons,job.reason)?null:SPEECH_ISSUE);return false;}
const cues=(Array.isArray(job.result?.lines)?job.result.lines:[]).filter(l=>typeof l?.text==='string'&&l.text.trim()&&l.end>l.start).map(l=>({start:l.start,frames:l.end-l.start,text:l.text.trim()}));
speechEnd();if(!cues.length){actions.notify?.(speechSilent());return false;}
finishInline();commitDraft();
@@ -88,10 +92,11 @@ export function createEditorText({element,state,t,actions,adjust,player,toolbar,
speech.loading=true;speechLabel(0);
const done=await actions.speech.download(fraction=>{if(run===speech.run)speechLabel(fraction);});
if(run!==speech.run)return;
- const ability=done?await actions.speech.ability():null;
+ // `done` is true, or the reason the download stopped.
+ const ability=done===true?await actions.speech.ability():null;
if(run!==speech.run)return;
if(ability){speech.available=ability.available;speech.need=ability.need;}
- if(!done||speech.need){speechEnd(t('Could not download. Try again.','没能下载,请再试一次。'),SPEECH_ISSUE);return;}
+ if(done!==true||speech.need){speechEnd(done==='disk_space'?speechDisk():t('Could not download. Try again.','没能下载,请再试一次。'),done==='disk_space'?null:SPEECH_ISSUE);return;}
if(!speech.available){speechEnd(speechFailed(),SPEECH_ISSUE);return;}
speech.loading=false;
}
@@ -164,9 +169,16 @@ export function createEditorText({element,state,t,actions,adjust,player,toolbar,
}else{
const file=el('input');file.type='file';file.accept='.srt';file.hidden=true;
const importButton=button(t('Import subtitle file','导入字幕文件'),{onClick:()=>file.click()});importButton.classList.add('fv-ed-import-srt');
- // Only a file that cannot be read says so; a refused edit (a locked track) flashes red like any other.
- file.onchange=async()=>{const f=file.files?.[0];if(!f)return;let text;const result={};try{if(f.size>4*1024*1024)throw new Error();text=await f.text();parseSRT(text,result);}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));if(result.truncated)actions.notify?.(t('Only the first 500 subtitles were imported.','只导入了前 500 条字幕。'));}};
+ // A file that cannot be used says why; a refused edit (a locked track) flashes red like any other.
+ file.onchange=async()=>{const f=file.files?.[0];if(!f)return;let text;const result={};
+ try{
+ if(f.size>4*1024*1024){actions.notify?.(t('Subtitle files can be up to 4 MB.','字幕文件不能超过 4 MB。'));return;}
+ try{text=decodeSRT(await f.arrayBuffer(),t('windows-1252','gb18030'));}catch{actions.notify?.(t('Could not read this subtitle file','读不出这个字幕文件'));return;}
+ try{parseSRT(text,result);}catch{actions.notify?.(t('No subtitles found. Only SRT files can be imported.','未找到字幕。仅支持导入 SRT 字幕文件。'));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));
+ if(result.truncated)actions.notify?.(t('Only the first 500 subtitles were imported.','只导入了前 500 条字幕。'));
+ else if(result.skipped)actions.notify?.(t(`${result.skipped} subtitles could not be read and were skipped.`,`${result.skipped} 条字幕无法读取,已跳过。`));}};
// Shown only where this computer can recognise speech.
const hear=button(t('Auto subtitles','自动字幕'),{onClick:toggleSpeech});hear.classList.add('fv-ed-auto-subtitles');for(const b of speech.buttons)if(!b.isConnected)speech.buttons.delete(b);speech.buttons.add(hear);speechLabel(speech.busy?speech.shown:null);
host.append(importButton,hear,file);
diff --git a/web/editor_text_model.js b/web/editor_text_model.js
index b7d3271..944f107 100644
--- a/web/editor_text_model.js
+++ b/web/editor_text_model.js
@@ -101,6 +101,14 @@ export function activeText(record, frame) {
return record.tracks.filter(t => isTextTrack(t) && !t.hidden).sort((a,b) => (a.kind === 'text' ? -1 : 1) - (b.kind === 'text' ? -1 : 1))
.flatMap(t => t.clips.filter(c => c.start <= frame && c.start+c.frames > frame).map(c => ({...c, style: styleOf(record,c), opacity: c.text_kind === 'text' && styleOf(record,c).fade ? Math.min(1,(frame-c.start+.5)/7.2,(c.start+c.frames-frame-.5)/7.2) : 1})));
}
+// A subtitle file's bytes as text: UTF-8, UTF-16 with its byte-order mark, or else the older local encoding
+// (`legacy`, e.g. GBK for Chinese), so such a file never turns into replacement characters.
+export function decodeSRT(bytes, legacy = 'windows-1252') {
+ const view = new Uint8Array(bytes);
+ if (view[0] === 0xff && view[1] === 0xfe) return new TextDecoder('utf-16le').decode(view);
+ if (view[0] === 0xfe && view[1] === 0xff) return new TextDecoder('utf-16be').decode(view);
+ try { return new TextDecoder('utf-8', {fatal: true}).decode(view); } catch { return new TextDecoder(legacy).decode(view); }
+}
export function parseSRT(text, result = {}) {
check(typeof text === 'string' && text.length <= 4*1024*1024, 'srt');
const blocks = text.replace(/^\ufeff/, '').replace(/\r\n?/g,'\n').trim().split(/\n\s*\n/);
@@ -126,7 +134,7 @@ export function parseSRT(text, result = {}) {
if (skipped) console.warn(`FreeVideo SRT import skipped ${skipped} unreadable blocks.`);
if (trimmed) console.warn(`FreeVideo SRT import trimmed ${trimmed} overlapping subtitles.`);
check(entries.length > 0, 'srt');
- result.truncated = entries.length > 500;
+ result.skipped = skipped; result.truncated = entries.length > 500;
if (result.truncated) console.warn('FreeVideo SRT import kept only the first 500 subtitles.');
return entries.slice(0, 500);
}