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.

Let the last continued part be as short as 2 seconds

Bowen Xuecc0d792516c8
diff --git a/freevideo_engine/agent/guide.py b/freevideo_engine/agent/guide.py
index 5343ea2..f0095b9 100644
--- a/freevideo_engine/agent/guide.py
+++ b/freevideo_engine/agent/guide.py
@@ -261,7 +261,7 @@ RULES = [
'Cut by default. Wherever the film can change shot, make the new shot from the reference pictures it should '
'have (cast cards, scene pictures) instead of continuing the previous video. Continue a video only for a '
'long take that cannot be cut, an action that must stay unbroken, or sound that must stay unbroken, and '
- 'continuing again and again is not recommended. Each continued part is at least 5 seconds. One video has at '
+ 'continuing again and again is not recommended. Each continued part is at least 5 seconds, and the last one can be as short as 2 seconds. One video has at '
'most 8 parts (the first and 7 continuations, about 110 seconds in all) when every continued part is at '
'least 10 seconds; with a continued part shorter than 10 seconds it has at most 4 parts, unless '
'first_frame_reference is true. Filling that is not recommended. Past it, cut to a new shot.',
@@ -301,7 +301,7 @@ RULES_ZH = [
'先用 people(角色图和各自的位置)做出首帧,再用它生成视频。',
'默认切镜头。能切镜头的地方就切:新镜头直接用对应的参考图(人物卡、场景图)生成,不接上一段视频。'
'只有不能切镜的长镜头、必须连贯的动作、必须连贯的声音,才接着上一段生成,而且不建议一段接一段地连续接。'
- '接着生成的每一段至少 5 秒。每段都不短于 10 秒时,一条视频最多 8 段(第一段加 7 次接着生成,总长约 110 秒);'
+ '接着生成的每一段至少 5 秒,最后一段可短至 2 秒。每段都不短于 10 秒时,一条视频最多 8 段(第一段加 7 次接着生成,总长约 110 秒);'
'有短于 10 秒的段时最多 4 段,first_frame_reference 为 true 时除外。不建议接满,超过就切镜头。',
'问话不是要求。用户问进度或状态(“在做吗”“怎么了”)时,用一句话照实回答,依据是你所知道的、任务和白模的状态,'
'什么都不要开始;不要把问句当提示词。某条 inbox 带有 whitebox 时,说明用户刚启动了白模场景,'
diff --git a/freevideo_engine/agent/jobs.py b/freevideo_engine/agent/jobs.py
index d5a70ce..51648bb 100644
--- a/freevideo_engine/agent/jobs.py
+++ b/freevideo_engine/agent/jobs.py
@@ -187,13 +187,16 @@ def part_prompt_problems(spec, prefix=''):
def _continued_part_problem(seconds, chain):
- """True when a video that continues another has a part the backend refuses, or is under MIN_PART_SECONDS.
+ """True when a video that continues another has a part the backend refuses, or is under MIN_TAIL_SECONDS.
The backend compares each part's node input frames (overlap included); a part that
- continues is also at least MIN_PART_SECONDS long.
+ another part continues is at least MIN_PART_SECONDS long, the last part MIN_TAIL_SECONDS.
"""
- from ..chain_plan import MIN_PART_FRAMES, MIN_PART_SECONDS
- return seconds < MIN_PART_SECONDS or any(block['frames'] < MIN_PART_FRAMES for block in chain['blocks'])
+ from ..chain_plan import MIN_PART_FRAMES, MIN_TAIL_FRAMES, MIN_TAIL_SECONDS
+ blocks = chain['blocks']
+ return seconds < MIN_TAIL_SECONDS or any(
+ block['frames'] < (MIN_TAIL_FRAMES if index == len(blocks) - 1 else MIN_PART_FRAMES)
+ for index, block in enumerate(blocks))
def length_problem(seconds, continued, prefix='', *, minimum=None, frames=None):
@@ -232,7 +235,7 @@ def parts_problems(spec, runner, prefix='', *, editor=None, work=None, planned=N
"""
if spec['kind'] != 'generate' or spec.get('refine_from'):
return []
- from ..chain_plan import MIN_PART_SECONDS, PlanError, parts_limit, plan
+ from ..chain_plan import MIN_TAIL_SECONDS, PlanError, parts_limit, plan
from ..chain_runner import ChainShortPartsTooMany, ChainTooLong
from ..chain_store import reference
continued, frames = bool(spec.get('continue_from')), single_frame_limit(spec)
@@ -243,7 +246,7 @@ def parts_problems(spec, runner, prefix='', *, editor=None, work=None, planned=N
except PlanError:
return [length_problem(spec['seconds'], continued, prefix, frames=frames)]
if continued and _continued_part_problem(spec['seconds'], chain):
- return [length_problem(spec['seconds'], continued, prefix, minimum=MIN_PART_SECONDS, frames=frames)]
+ return [length_problem(spec['seconds'], continued, prefix, minimum=MIN_TAIL_SECONDS, frames=frames)]
if runner is None:
return []
# A video with a continuing part shorter than full_part_frames has fewer parts, unless every part sees the first frame.
@@ -281,7 +284,7 @@ def parts_problems(spec, runner, prefix='', *, editor=None, work=None, planned=N
except ValueError:
return False
return earlier + len(blocks) <= (short_limit if made_short or short_blocks(blocks) else limit)
- shortest = MIN_PART_SECONDS if continued else 2
+ shortest = MIN_TAIL_SECONDS
fit = next((s for s in range(int(spec['seconds']), shortest - 1, -1) if fits(s)), None)
if fit is None:
problem = schema.diagnostic(prefix + '/continue_from', 'a video of fewer than %d parts' % error.limit, None)
diff --git a/freevideo_engine/chain_plan.py b/freevideo_engine/chain_plan.py
index dfbc028..8e87173 100644
--- a/freevideo_engine/chain_plan.py
+++ b/freevideo_engine/chain_plan.py
@@ -24,6 +24,8 @@ MIN_PART_SECONDS, FULL_PART_SECONDS = RULES['min_part_seconds'], RULES['full_par
MAX_PARTS, SHORT_MAX_PARTS = RULES['max_parts'], RULES['short_max_parts']
# The length a new continuation starts with, and its length on devices that cannot continue with a full part.
CONTINUE_SECONDS, SHORT_CONTINUE_SECONDS = RULES['continue_seconds'], RULES['short_continue_seconds']
+# The last part of a video, and nothing that another part continues, may be as short as MIN_TAIL_SECONDS.
+MIN_TAIL_SECONDS = RULES['min_tail_seconds']
def part_frames(seconds):
@@ -35,11 +37,26 @@ def part_frames(seconds):
# Continuing blocks below MIN_PART_FRAMES are too short; below FULL_PART_FRAMES they are short parts.
MIN_PART_FRAMES, FULL_PART_FRAMES = part_frames(MIN_PART_SECONDS), part_frames(FULL_PART_SECONDS)
+MIN_TAIL_FRAMES = part_frames(MIN_TAIL_SECONDS)
SHORTEST_FIRST = 2 # whole seconds: what the first part keeps when the continuing parts take the rest
MAX_SECONDS = 7200
MAX_BLOCKS = MAX_SECONDS // SHORTEST_BLOCK
+def _tail_lengths(total, following):
+ """Lengths of a video that continues a saved one when no even split gives every part MIN_PART_SECONDS: parts as
+ long as the device allows, and a last part of MIN_TAIL_SECONDS or more for the rest. None if no such split."""
+ count = math.ceil(round(total, 6) / following)
+ if count > MAX_BLOCKS or total < MIN_TAIL_SECONDS + MIN_PART_SECONDS * (count - 1):
+ return None
+ lengths = [following] * (count - 1)
+ lengths.append(round(total - sum(lengths), 6))
+ if lengths[-1] < MIN_TAIL_SECONDS: # take what the last part lacks from the one before it
+ lengths[-2] = round(lengths[-2] - (MIN_TAIL_SECONDS - lengths[-1]), 6)
+ lengths[-1] = MIN_TAIL_SECONDS
+ return lengths if all(length >= MIN_PART_SECONDS for length in lengths[:-1]) else None
+
+
def parts_limit(short, first_frame=False, max_parts=MAX_PARTS):
"""The most parts one video may have: fewer when one of its continuing parts is short, unless every
continuing part also sees the first frame."""
@@ -154,6 +171,9 @@ def plan(seconds, single=False, max_frames=None, single_limit_seconds=None, bloc
if lengths is None:
if fits and seconds < SINGLE_SECONDS:
return alone # a requested block length never makes a part this device cannot do
+ if continued and following >= MIN_PART_SECONDS:
+ lengths = _tail_lengths(total, following) # the last part may be shorter than the others
+ if lengths is None:
if first < (MIN_PART_SECONDS if continued else SHORTEST_BLOCK) or following < MIN_PART_SECONDS:
raise PlanError('device_limit', 'This device cannot generate this length at this size')
raise PlanError('length_not_splittable', 'This length cannot be cut into parts of the requested length')
diff --git a/freevideo_engine/chain_runner.py b/freevideo_engine/chain_runner.py
index dfdde18..1dd7239 100644
--- a/freevideo_engine/chain_runner.py
+++ b/freevideo_engine/chain_runner.py
@@ -69,9 +69,9 @@ class ChainPartTooShort(ValueError):
code = 'chain_part_too_short'
def __init__(self, seconds, limit):
- super().__init__('Each continued part must be at least %d seconds. Make it longer.' % limit)
+ super().__init__('A part followed by another part must be at least %d seconds. Make it longer.' % limit)
self.seconds, self.limit = seconds, limit
- self.message_zh = '接着生成的每一段至少 %d 秒,请加长这一段。' % limit
+ self.message_zh = '后面还接着其他段时,这一段至少 %d 秒,请加长这一段。' % limit
def _work_key(path):
@@ -365,9 +365,13 @@ class ChainRunner:
def _check_parts(self, record):
"""Refuses, before anything is written or queued, a chain with a continuing part too short or a video
continued through too many parts."""
+ # The last part of a video, one no other block continues, may be shorter than the parts before it.
+ followed = {row['after'] for row in record['blocks'] if isinstance(row['after'], str)}
short = [row['inputs']['frames'] for row in record['blocks']
if (row['after'] is not None or row['before'] is not None)
- and row['inputs']['frames'] < self.min_part_frames]
+ and row['inputs']['frames'] < (min(self.min_part_frames, chain_plan.MIN_TAIL_FRAMES)
+ if row['before'] is None and row['id'] not in followed
+ else self.min_part_frames)]
if short:
raise ChainPartTooShort(min(short) / chain_plan.FPS, chain_plan.MIN_PART_SECONDS)
lineage = self._lineage(record).values()
diff --git a/web/chain_rules.js b/web/chain_rules.js
index b0575bf..0204c0b 100644
--- a/web/chain_rules.js
+++ b/web/chain_rules.js
@@ -1 +1 @@
-export const CHAIN_RULES = {"min_part_seconds": 5, "full_part_seconds": 10, "max_parts": 8, "short_max_parts": 4, "continue_seconds": 10, "short_continue_seconds": 5};
+export const CHAIN_RULES = {"min_part_seconds": 5, "full_part_seconds": 10, "max_parts": 8, "short_max_parts": 4, "continue_seconds": 10, "short_continue_seconds": 5, "min_tail_seconds": 2};
diff --git a/web/editor.js b/web/editor.js
index e3598cf..61df5a5 100644
--- a/web/editor.js
+++ b/web/editor.js
@@ -55,7 +55,7 @@ export function partsLimitText(code, t = en => en, limit = null) {
const {followSeconds: least, fullSeconds: full, maxParts, shortMaxParts} = model.RULES;
if (code === 'chain_source_full') return t('This video already has the maximum of ' + maxParts + '\u00a0parts and cannot be extended.',
'这个视频已达 ' + maxParts + '\u00a0段上限,无法再接着生成。');
- if (code === 'chain_part_too_short') return t(`Each continued part must be at least ${least} seconds. Make it longer.`, `接着生成的每一段至少 ${least} 秒,请加长这一段。`);
+ if (code === 'chain_part_too_short') return t(`A part followed by another part must be at least ${least} seconds. Make it longer.`, `后面还接着其他段时,这一段至少 ${least} 秒,请加长这一段。`);
if (code === 'chain_short_parts') { const most = limit ?? shortMaxParts; return t(`With a part shorter than ${full} seconds, one continuous shot can have up to ${most} parts. Make every part at least ${full} seconds long, or use fewer parts.`,
`有短于 ${full} 秒的段时,一个连续镜头最多 ${most} 段。请把每段加长到至少 ${full} 秒,或减少段数。`); }
return t(`One continuous shot can have up to ${limit ?? maxParts} parts. Make it shorter.`, `一个连续镜头最多 ${limit ?? maxParts} 段,请缩短。`);
@@ -78,7 +78,7 @@ export function editorErrorText(value, t = en => en) {
if (code === 'gpu_memory' || /out of memory|cuda.*memory|显存不足|显存不够/i.test(raw))
return t(`${stage}: not enough GPU memory.`, `${stage}时显存不足。`);
const known = {
- chain_part_too_short: t(`Each continued part must be at least ${model.RULES.followSeconds} seconds.`, `接着生成的每一段至少 ${model.RULES.followSeconds} 秒。`),
+ chain_part_too_short: t(`A part followed by another part must be at least ${model.RULES.followSeconds} seconds.`, `后面还接着其他段时,这一段至少 ${model.RULES.followSeconds} 秒。`),
chain_short_parts: t(`With a part shorter than ${model.RULES.fullSeconds} seconds, one continuous shot can have up to ${model.RULES.shortMaxParts} parts.`,
`有短于 ${model.RULES.fullSeconds} 秒的段时,一个连续镜头最多 ${model.RULES.shortMaxParts} 段。`),
chain_too_long: t(`One continuous shot can have up to ${model.RULES.maxParts} parts.`, `一个连续镜头最多 ${model.RULES.maxParts} 段。`),
diff --git a/web/editor_model.js b/web/editor_model.js
index a61d40b..3f0c377 100644
--- a/web/editor_model.js
+++ b/web/editor_model.js
@@ -11,7 +11,7 @@ export const FPS = 24;
// followSeconds long; a video with a continuing part shorter than fullSeconds has at most shortMaxParts parts unless
// every part sees the first frame, any other at most maxParts. A new continuation starts at continueSeconds, or at
// shortContinueSeconds where a full part is too much for the device.
-export const RULES = Object.freeze({maxSeconds: 15, singleSeconds: 30, minSeconds: 2, tailSeconds: 5,
+export const RULES = Object.freeze({maxSeconds: 15, singleSeconds: 30, minSeconds: 2, tailSeconds: 5, lastSeconds: CHAIN_RULES.min_tail_seconds,
followSeconds: CHAIN_RULES.min_part_seconds, fullSeconds: CHAIN_RULES.full_part_seconds,
continueSeconds: CHAIN_RULES.continue_seconds, shortContinueSeconds: CHAIN_RULES.short_continue_seconds,
step: 17, first: 5, overlap: 22,
@@ -644,16 +644,20 @@ export const setPictureFit = (record, id, fit) => setPicture(record, id, {fit: p
// MIN_PART_FRAMES a continuing part is too short, below FULL_PART_FRAMES it is a short part.
const partFrames = seconds => RULES.overlap + RULES.step * Math.ceil((FPS * seconds - (RULES.step - 1)) / RULES.step);
export const MIN_PART_FRAMES = partFrames(RULES.followSeconds), FULL_PART_FRAMES = partFrames(RULES.fullSeconds);
+// The last part of a video, one no other part continues, may be as short as lastSeconds.
+export const MIN_TAIL_FRAMES = partFrames(RULES.lastSeconds);
// The most parts one video may have (chain_plan.parts_limit).
export const partsLimit = (short, firstFrame = false) => short && !firstFrame ? Math.min(RULES.maxParts, RULES.shortMaxParts) : RULES.maxParts;
// The shortest a part that continues another may be; a device that cannot make a part that long keeps the general minimum.
const followLeast = maxFollowSeconds => maxFollowSeconds >= RULES.followSeconds ? RULES.followSeconds : RULES.minSeconds;
-// A length to continue by, in whole seconds, raised to one that parts of followSeconds..maxFollowSeconds can add up to.
-export function continuedSeconds(seconds, maxFollowSeconds = RULES.maxSeconds) {
+// A length to continue by, in whole seconds, raised to one that parts of followSeconds..maxFollowSeconds can add up to;
+// with `tail` (no part continues the last one) that part may be as short as lastSeconds.
+export function continuedSeconds(seconds, maxFollowSeconds = RULES.maxSeconds, {tail = true} = {}) {
check(typeof seconds === 'number' && Number.isFinite(seconds) && typeof maxFollowSeconds === 'number' && Number.isFinite(maxFollowSeconds), 'range');
const least = followLeast(maxFollowSeconds), follow = Math.max(least, Math.floor(Math.min(RULES.maxSeconds, maxFollowSeconds)));
- const length = Math.max(least, Math.round(seconds));
- return Math.max(length, Math.ceil(length / follow) * least);
+ const last = tail ? Math.min(least, RULES.lastSeconds) : least;
+ const length = Math.max(last, Math.round(seconds));
+ return Math.max(length, (Math.ceil(length / follow) - 1) * least + last);
}
// The length a new continuation starts with: a full part, or a short one where the device cannot make a full part
// or `short` asks for it.
@@ -661,7 +665,7 @@ export function defaultContinueSeconds(maxFollowSeconds = RULES.maxSeconds, {sho
const full = !short && maxFollowSeconds >= RULES.fullSeconds;
return continuedSeconds(full ? RULES.continueSeconds : RULES.shortContinueSeconds, maxFollowSeconds);
}
-function segmentLengths(frames, maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds, continues = false) {
+function segmentLengths(frames, maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds, continues = false, tail = true) {
check(typeof maxSeconds === 'number' && Number.isFinite(maxSeconds) && maxSeconds >= RULES.minSeconds, 'range');
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 = [];
@@ -673,7 +677,7 @@ function segmentLengths(frames, maxSeconds = RULES.maxSeconds, maxFollowSeconds
// Every part after the first continues the one before it, as chain_plan lays them out: the parts after the first
// share what is left evenly, and a rest too short for them comes off the first. They are fullSeconds or longer
// whenever the length allows it, else at least followSeconds.
- const seconds = continues && follow >= RULES.followSeconds * FPS ? continuedSeconds(left / FPS, follow / FPS) : left / FPS;
+ const seconds = continues && follow >= RULES.followSeconds * FPS ? continuedSeconds(left / FPS, follow / FPS, {tail}) : left / FPS;
for (const least of [RULES.fullSeconds, RULES.followSeconds]) {
if (follow < least * FPS) continue;
const head = continues ? 0 : Math.min(max / FPS, seconds), rest = seconds - head, count = Math.ceil(rest / (follow / FPS));
@@ -687,8 +691,8 @@ function segmentLengths(frames, maxSeconds = RULES.maxSeconds, maxFollowSeconds
}
while (left) { const length = Math.min(left, lengths.length || continues ? follow : max); lengths.push(length); left -= length; }
const last = lengths.length - 1;
- if (last > 0 && lengths[last] < Math.min(follow, RULES.tailSeconds * FPS)) {
- const both = lengths[last - 1] + lengths[last]; lengths[last - 1] = Math.min(last === 1 && !continues ? max : follow, Math.max(both - follow, Math.ceil(both / 2 / FPS) * FPS)); lengths[last] = both - lengths[last - 1];
+ if (last > 0 && lengths[last] < Math.min(follow, RULES.tailSeconds * FPS) && !(continues && tail && follow >= RULES.followSeconds * FPS && lengths[last] >= RULES.lastSeconds * FPS)) {
+ const both = lengths[last - 1] + lengths[last]; lengths[last - 1] = Math.min(last === 1 && !continues ? max : follow, Math.max(both - follow, Math.ceil(both / 2 / FPS) * FPS, last > 1 || continues ? followLeast(follow / FPS) * FPS : 0)); lengths[last] = both - lengths[last - 1];
}
return lengths;
}
@@ -737,7 +741,7 @@ export function continuesBefore(record, id) {
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, continues = false} = {}) => segmentLengths(frames, maxSeconds, maxFollowSeconds, continues);
+export const partLengths = (frames, {maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds, continues = false, tail = true} = {}) => segmentLengths(frames, maxSeconds, maxFollowSeconds, continues, tail);
// One video is generated in at most partsLimit parts: the longest range that still fits. A device whose continuing
// parts are all short has the short-part limit.
export function maxRangeFrames(record, {continues = false, maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds, firstFrame = false}) {
@@ -748,34 +752,38 @@ export function maxRangeFrames(record, {continues = false, maxSeconds = RULES.ma
return before ? (parts - 1) * follow : Math.floor(Math.min(RULES.maxSeconds, maxSeconds)) * FPS + (parts - 1) * follow;
}
// Manual boundaries use device limits, not the automatic fifteen-second preference.
-export function rangeParts(record, {start, frames, parts, continues, maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds}) {
+export function rangeParts(record, {start, frames, parts, continues, tail, 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 following = continues ?? !!(head && partBefore(record, head)), first = following ? maxFollowSeconds : maxSeconds;
- // A part that continues another is at least followSeconds long.
- const least = index => (index || following ? followLeast(maxFollowSeconds) : RULES.minSeconds) * FPS;
+ // A part that continues another is at least followSeconds long; the last part of a video, one no part continues, lastSeconds.
+ const last = tail ?? !trackBy(record, 'v1').clips.some(clip => clip.start === start + frames && partBefore(record, clip));
+ const least = index => (Array.isArray(parts) && index === parts.length - 1 && last ? Math.min(RULES.lastSeconds, followLeast(maxFollowSeconds))
+ : index || following ? followLeast(maxFollowSeconds) : RULES.minSeconds) * FPS;
const valid = Array.isArray(parts) && parts.length > 0 && parts.length <= RULES.maxClips
&& parts.every((count, i) => whole(count, least(i)) && count % FPS === 0
&& count <= Math.floor(i ? maxFollowSeconds : first) * FPS)
&& parts.reduce((sum, count) => sum + count, 0) === frames;
- return valid ? [...parts] : partLengths(frames, {maxSeconds: first, maxFollowSeconds, continues: following});
+ return valid ? [...parts] : partLengths(frames, {maxSeconds: first, maxFollowSeconds, continues: following, tail: last});
}
-export function adjustPartBoundary(parts, index, leftFrames, {maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds, continues = false} = {}) {
+export function adjustPartBoundary(parts, index, leftFrames, {maxSeconds = RULES.maxSeconds, maxFollowSeconds = maxSeconds, continues = false, tail = false} = {}) {
check(Array.isArray(parts) && whole(index) && index < parts.length - 1 && Number.isFinite(leftFrames), 'range');
check(parts.every(count => whole(count, RULES.minSeconds * FPS) && count % FPS === 0), 'range');
const minimum = RULES.minSeconds * FPS, total = parts[index] + parts[index + 1];
const leftMax = Math.floor(index ? maxFollowSeconds : maxSeconds) * FPS, rightMax = Math.floor(maxFollowSeconds) * FPS;
// Every part that continues another is at least followSeconds long; a pair too short for that keeps the general minimum.
+ // The part after the boundary may be as short as lastSeconds when no part continues it (`tail`).
const follows = followLeast(maxFollowSeconds) * FPS, leftLeast = index || continues ? follows : minimum;
- const tight = total >= leftLeast + follows;
- const low = Math.max(tight ? leftLeast : minimum, total - rightMax), high = Math.min(leftMax, total - (tight ? follows : minimum));
+ const rightLeast = tail ? Math.min(follows, RULES.lastSeconds * FPS) : follows;
+ const tight = total >= leftLeast + rightLeast;
+ const low = Math.max(tight ? leftLeast : minimum, total - rightMax), high = Math.min(leftMax, total - (tight ? rightLeast : minimum));
check(Number.isFinite(low) && Number.isFinite(high) && low <= high, 'range');
const desired = Math.round(leftFrames / FPS) * FPS, left = Math.max(low, Math.min(high, desired));
const result = [...parts]; result[index] = left; result[index + 1] = total - left;
// The left part also stops where the part after it would fall under followSeconds.
return {parts: result, limited: desired >= leftMax && left === leftMax ? leftMax / FPS
: total - desired >= rightMax && total - left === rightMax ? rightMax / FPS
- : tight && desired > left && left === total - follows ? left / FPS : null};
+ : tight && desired > left && left === total - rightLeast ? left / FPS : null};
}
export function resizePlannedBoundary(record, leftId, rightId, frame, limits = {}) {
const left = find(record, leftId), right = find(record, rightId);
@@ -785,9 +793,11 @@ export function resizePlannedBoundary(record, leftId, rightId, frame, limits = {
check(members.every(clip => clip.pending && !clip.source), 'unsupported');
const video = trackOf(record, leftId).id === 'v1' ? left : find(record, left.link);
const preceding = !!video && !!partBefore(record, video);
+ const rightVideo = trackOf(record, rightId).id === 'v1' ? right : find(record, right.link);
+ const tail = !trackBy(record, 'v1').clips.some(clip => continuing(clip, rightVideo));
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, continues: preceding});
+ {maxSeconds: preceding ? maxFollowSeconds : maxSeconds, maxFollowSeconds, continues: preceding, tail});
const next = copy(record); detachAttempt(next, members.map(clip => clip.id));
for (const old of members) find(next, old.id).part = left.part;
for (const clip of pair(next, leftId)) { clip.frames = clip.length = result.parts[0]; clearPlan(clip); }
@@ -801,17 +811,18 @@ export function resizePlanned(record, id, edge, frame, limits = {}) {
const primary = members[0];
const video = trackOf(record, id).id === 'v1' ? primary : find(record, primary.link);
const maxFollowSeconds = limits.maxFollowSeconds ?? limits.maxSeconds ?? RULES.maxSeconds;
- // A planned part that continues another is at least followSeconds long.
- const minimum = (video && partBefore(record, video) ? followLeast(maxFollowSeconds) : RULES.minSeconds) * FPS;
+ // A planned part that continues another is at least followSeconds long, unless no part continues it.
+ const follows = !!video && !!partBefore(record, video), tail = !video || !trackBy(record, 'v1').clips.some(clip => continuing(clip, video));
+ const minimum = (follows ? Math.min(followLeast(maxFollowSeconds), tail ? RULES.lastSeconds : Infinity) : RULES.minSeconds) * FPS;
const neighbors = members.flatMap(clip => trackOf(record, clip.id).clips.filter(other => other.id !== clip.id));
const low = Math.max(0, ...neighbors.filter(clip => end(clip) <= primary.start).map(end));
const high = Math.min(1e7, ...neighbors.filter(clip => clip.start >= end(primary)).map(clip => clip.start));
const position = Math.round(frame / FPS) * FPS;
let start = edge === 'start' ? Math.max(low, Math.min(end(primary) - minimum, position)) : primary.start;
let stop = edge === 'end' ? Math.min(high, Math.max(start + minimum, position)) : end(primary);
- if (minimum > RULES.minSeconds * FPS) {
- // Lengths no run of continuing parts can fill (16–19 s at fifteen-second parts) are raised to the next one that fits.
- const fitted = continuedSeconds((stop - start) / FPS, maxFollowSeconds) * FPS;
+ if (follows) {
+ // Lengths no run of continuing parts can fill are raised to the next one that fits.
+ const fitted = continuedSeconds((stop - start) / FPS, maxFollowSeconds, {tail}) * FPS;
if (fitted > stop - start) {
if (edge === 'end' && start + fitted <= high) stop = start + fitted;
else if (edge === 'start' && stop - fitted >= low) start = stop - fitted;
@@ -821,7 +832,7 @@ export function resizePlanned(record, id, edge, frame, limits = {}) {
const part = primary.part || freshId(next);
for (const clip of pair(next, id)) { clip.start = start; clip.frames = clip.length = stop - start; clip.part = part; clearPlan(clip); }
next = finish(next);
- const lengths = rangeParts(next, {start, frames: stop - start, ...limits});
+ const lengths = rangeParts(next, {start, frames: stop - start, ...limits, tail});
let positionAt = start, currentId = id;
for (const count of lengths.slice(0, -1)) {
positionAt += count; next = split(next, currentId, positionAt);
@@ -1080,7 +1091,8 @@ function madeLineage(record, clip) {
// them. Returns {code, parts, limit} for the first problem, or null.
export function partsProblem(record, ids, {firstFrame = record.settings?.first_frame_reference === true, sourceLineage = {}} = {}) {
const rows = generationPlan(record, generationClips(record, ids));
- if (rows.some(row => row.before && row.request_frames < MIN_PART_FRAMES)) return {code: 'chain_part_too_short', parts: null, limit: RULES.followSeconds};
+ const followed = new Set(rows.map(row => row.before?.id));
+ if (rows.some(row => row.before && row.request_frames < (followed.has(row.clip.id) ? MIN_PART_FRAMES : MIN_TAIL_FRAMES))) return {code: 'chain_part_too_short', parts: null, limit: RULES.followSeconds};
const lineage = new Map();
for (const row of rows) {
const inherited = row.before?.source ? sourceLineage[`${row.before.source.kind}:${row.before.source.id}`] : null;
@@ -1103,7 +1115,8 @@ export function setContinuationSeconds(record, id, seconds, {maxSeconds = RULES.
check(members.every(clip => clip.pending && !clip.source), 'unsupported');
const video = members.find(clip => trackOf(record, clip.id).id === 'v1');
check(!!video && !!partBefore(record, video), 'unsupported');
- check(Number.isInteger(seconds) && seconds >= followLeast(maxFollowSeconds)
+ const last = !trackBy(record, 'v1').clips.some(clip => continuing(clip, video));
+ check(Number.isInteger(seconds) && seconds >= (last ? Math.min(RULES.lastSeconds, followLeast(maxFollowSeconds)) : followLeast(maxFollowSeconds))
&& seconds <= Math.floor(Math.min(RULES.maxSeconds, maxFollowSeconds)), 'range');
const delta = seconds * FPS - video.frames;
if (!delta) return record;
diff --git a/web/editor_tracks.js b/web/editor_tracks.js
index af51c30..66f94e7 100644
--- a/web/editor_tracks.js
+++ b/web/editor_tracks.js
@@ -87,10 +87,10 @@ export function edgeParameters(clip, edge, frame, points, zoom, {canExtend = tru
const sourceEnd = clip.start + clip.length - clip.in;
if (speedEdited(clip)) return {kind: 'trim', edge, frame: snapped.frame, guide: snapped.guide};
if (edge === 'end' && canExtend && clip.extend && snapped.frame > sourceEnd) {
- // What continues a video is at least followSeconds long; the preview already shows the raised length.
+ // What is added at the tail is at least lastSeconds long; the preview already shows the raised length.
const wanted = Math.round((snapped.frame - sourceEnd) / model.FPS), seconds = model.continuedSeconds(wanted, maxFollowSeconds);
return {kind: 'extend', frame: sourceEnd, frames: seconds * model.FPS, guide: snapped.guide, raised: seconds !== wanted,
- least: wanted < model.RULES.followSeconds && seconds >= model.RULES.followSeconds};
+ least: wanted < model.RULES.lastSeconds && seconds >= model.RULES.lastSeconds};
}
return {kind: 'trim', edge, frame: snapped.frame, guide: snapped.guide};
}
@@ -982,8 +982,8 @@ export function createTracks(host, {state, sources = {}, t = en => en, actions =
const frames = result.frame - finished.clip.start - finished.clip.frames + result.frames;
if (extendClip(finished.id, frames) && result.raised) {
// Say the new length (tenths, rounded down like other durations) so the change is visible.
- const least = model.RULES.followSeconds, length = secondsText(result.frames, model.FPS);
- actions.notify?.(result.least ? t(`Lengthened to ${length} s. Each continued part must be at least ${least} seconds.`, `已加长到 ${length} 秒。接着生成的每一段至少 ${least} 秒。`)
+ const least = model.RULES.lastSeconds, length = secondsText(result.frames, model.FPS);
+ actions.notify?.(result.least ? t(`Lengthened to ${length} s. The last part must be at least ${least} seconds.`, `已加长到 ${length} 秒。最后一段至少 ${least} 秒。`)
: t(`Lengthened to ${length} s.`, `已加长到 ${length} 秒。`));
}
} else attempt(t('Trim', '裁短'), record => model.trim(record, finished.id, finished.edge, result.frame));
diff --git a/web/howto.js b/web/howto.js
index cafdb7e..0850b57 100644
--- a/web/howto.js
+++ b/web/howto.js
@@ -35,8 +35,8 @@ const HOWTOS = [
zh: '填写更长的时长,会自动分段生成。'},
{id: 'generate', anchor: '[data-fv-guide="generate"]', en: 'Choose "Generate video".', zh: '点“生成视频”。'},
{id: 'extend', anchor: '.fv-action-extend', image: 'extend-button',
- en: 'Choose "Extend" below a finished video to continue it. Each continued part is at least 5 seconds; with a part shorter than 10 seconds, one video has at most 4 parts.',
- zh: '在生成好的视频下方点“接着生成”,继续下一段。接着生成的每一段至少 5 秒;有短于 10 秒的段时,一条视频最多 4 段。'},
+ en: 'Choose "Extend" below a finished video to continue it. Each continued part is at least 5 seconds, and the last one can be as short as 2 seconds. With a part shorter than 10 seconds, one video has at most 4 parts.',
+ zh: '在生成好的视频下方点“接着生成”,继续下一段。接着生成的每一段至少 5 秒,最后一段可短至 2 秒。有短于 10 秒的段时,一条视频最多 4 段。'},
{id: 'longer', anchor: '[data-view="editor"]', en: 'Parts can also be added one by one in "Edit".', zh: '也可在“剪辑视图”中逐段接续。'}]},
{id: 'editor-extend-refs', view: 'editor', title: ['Add reference images when extending in Edit', '在剪辑视图延长时加参考图'],
steps: [
diff --git a/web/tutorial_book_content.js b/web/tutorial_book_content.js
index c409087..36c7261 100644
--- a/web/tutorial_book_content.js
+++ b/web/tutorial_book_content.js
@@ -199,8 +199,8 @@ export const TUTORIAL_CHAPTERS = [
settings: {},
},
limits: {
- zh: ['接着生成的每一段至少 5 秒。一个连续镜头最多 8 段,有短于 10 秒的段时最多 4 段;创作面板中时长最长 60 秒;分镜剧本可在剪辑视图中逐个镜头添加,或用 AI 全自动。', '分段生成和接着生成需要 NVIDIA 显卡或 Mac。', '段数越多,衔接处越容易出现变化;适合切换镜头处,可直接开始新的一段。'],
- en: ['Each continued part is at least 5 seconds. One continuous shot has at most 8 parts, or 4 when a part is shorter than 10 seconds, and the creation panel accepts up to 60 seconds. For a storyboard, add shots one by one in Edit, or use Autopilot.', 'Generating in parts and Extend need an NVIDIA graphics card or a Mac.', 'The more parts are joined, the more the joins may change. Where a cut fits, cut to a new shot and start a fresh part.'],
+ zh: ['接着生成的每一段至少 5 秒,最后一段可短至 2 秒。一个连续镜头最多 8 段,有短于 10 秒的段时最多 4 段;创作面板中时长最长 60 秒;分镜剧本可在剪辑视图中逐个镜头添加,或用 AI 全自动。', '分段生成和接着生成需要 NVIDIA 显卡或 Mac。', '段数越多,衔接处越容易出现变化;适合切换镜头处,可直接开始新的一段。'],
+ en: ['Each continued part is at least 5 seconds, and the last one can be as short as 2 seconds. One continuous shot has at most 8 parts, or 4 when a part is shorter than 10 seconds, and the creation panel accepts up to 60 seconds. For a storyboard, add shots one by one in Edit, or use Autopilot.', 'Generating in parts and Extend need an NVIDIA graphics card or a Mac.', 'The more parts are joined, the more the joins may change. Where a cut fits, cut to a new shot and start a fresh part.'],
},
},
{