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.
Agent: take check also reports picture cuts the prompt did not ask for, planned cuts that are...
Bowen Xue9f12e6a35025
diff --git a/freevideo_engine/agent/cut_pick.py b/freevideo_engine/agent/cut_pick.pyindex bbcd36e..484bf53 100644--- a/freevideo_engine/agent/cut_pick.py+++ b/freevideo_engine/agent/cut_pick.py@@ -55,15 +55,21 @@ def _spike(diffs, index, lo, hi, floor):return diffs[index] >= floor and diffs[index] >= CUT_SPIKE * (float(np.median(around)) if around else 0.0)+def cuts_in(small, times):+ """Seconds of the hard picture cuts in decoded frames, ascending, excluding 0 and the end."""+ diffs = _changes(small)+ return [round(times[i], 3) for i in range(1, len(times))+ if (diffs[i] >= CUT_DIFF and diffs[i] >= diffs[i - 1] and diffs[i] > (diffs[i + 1] if i + 1 < len(diffs) else -1)+ and _spike(diffs, i, max(1, i - 3), min(len(diffs), i + 4), CUT_DIFF))]++def detect_cuts(path, expected=None, *, tolerance=0.6):"""Seconds of the hard picture cuts, ascending, excluding 0 and the end. With `expected`, each expected cuttakes the strongest frame change within `tolerance` s; one with no such change is None, not guessed."""_, small, times = _pictures(path)- diffs = _changes(small)if not expected:- return [round(times[i], 3) for i in range(1, len(times))- if (diffs[i] >= CUT_DIFF and diffs[i] >= diffs[i - 1] and diffs[i] > (diffs[i + 1] if i + 1 < len(diffs) else -1)- and _spike(diffs, i, max(1, i - 3), min(len(diffs), i + 4), CUT_DIFF))]+ return cuts_in(small, times)+ diffs = _changes(small)found = []for wanted in expected:near = [i for i in range(1, len(times)) if abs(times[i] - wanted) <= tolerance]diff --git a/freevideo_engine/agent/productions.py b/freevideo_engine/agent/productions.pyindex 68b100f..32d3329 100644--- a/freevideo_engine/agent/productions.py+++ b/freevideo_engine/agent/productions.py@@ -962,14 +962,30 @@ class Productions:continueself._inspecting.add((identity, job))lines = [row['line'] for row in shot.get('lines') or [] if row.get('line')]+ made = take.get('spec') or {}+ prompt = made.get('prompt')+ # A prompt that is not text (taken from another job) says nothing about its cuts.+ planned = [t for t in spec.cut_times(prompt) if t > 0] if isinstance(prompt, str) else None+ given = made.get('media') or {}threading.Thread(target=self._inspect, daemon=True, args=(- identity, job, take['library_id'], shot.get('seconds'), lines)).start()+ identity, job, take['library_id'], shot.get('seconds'), lines, planned,+ self._frame_file(given.get('first')), self._frame_file(given.get('last')))).start()- def _inspect(self, identity, job, library, seconds, lines):+ def _frame_file(self, item):+ """The file of a given frame image that sits in the input folder, else None (other sources are not checked)."""+ name = item.get('file') if isinstance(item, dict) else None+ if not isinstance(name, str):+ return None+ try:+ return self.jobs.port.input_path(name)+ except (OSError, ValueError, TypeError):+ return None++ def _inspect(self, identity, job, library, seconds, lines, planned=None, first=None, last=None):try:with self.jobs.cpu:result = take_qa.check(self.jobs.port.library_video(library), seconds=seconds,- lines=lines, transcribe=self.transcribe)+ lines=lines, transcribe=self.transcribe, planned=planned, first=first, last=last)except Exception as error: # noqa: BLE001 - a failed check must not block the film; the judge sees it as uncheckedlogging.getLogger(__name__).warning('A take could not be checked (%s)', type(error).__name__)result = dict(error=type(error).__name__, problems=[], notes=[], ok=True)diff --git a/freevideo_engine/agent/take_qa.py b/freevideo_engine/agent/take_qa.pyindex a6abf96..6e59e5e 100644--- a/freevideo_engine/agent/take_qa.py+++ b/freevideo_engine/agent/take_qa.py@@ -28,6 +28,9 @@ GAP_EDGE = 0.5 # a gap counts as "in the middle" this far from boSPEECH_DB = -35.0CLIP_PEAK = 0.999LINE_MATCH = 0.6+CUT_MATCH = 0.6 # s, a detected cut this close to a planned one is that cut+ASPECT_TOLERANCE = 0.03 # shape difference up to which a given frame is compared+HOLD_DIFF = 12.0 # 0-255 mean difference between a given frame and the take's own end frameANALYSIS_WIDTH = 64SAMPLE_RATE = 16000WINDOW = 0.05@@ -68,6 +71,19 @@ def recognise(path):return ' '.join(word['text'] for line in heard['lines'] for word in line['words'])+def _still(path, shape):+ """A given frame image as a small gray array of the analysis size, or None when it cannot be read."""+ try:+ from PIL import Image+ with Image.open(media._file(path)) as image:+ # A different shape is cropped or padded by the generator, so the two do not compare pixel for pixel.+ if abs(image.width / image.height - shape[1] / shape[0]) > ASPECT_TOLERANCE:+ return None+ return np.asarray(image.convert('L').resize((shape[1], shape[0])), np.float32)+ except Exception: # noqa: BLE001 - an unreadable frame image only skips its check+ return None++def _edge_flicker(changes, times):"""Seconds of a single odd frame at the start or the end: a jump to or from the neighbour that themotion beside it does not explain."""@@ -112,13 +128,32 @@ def _runs(flags, times, minimum):return spans+def _shots(result, notes, small, times, planned):+ """Hard cuts inside the take: those the prompt did not ask for, planned ones that are missing, and the+ longest stretch without a cut."""+ from . import cut_pick+ cuts = cut_pick.cuts_in(small, times)+ edges = [0.0] + cuts + [times[-1]]+ result.update(cuts=cuts, longest_shot=round(max(b - a for a, b in zip(edges, edges[1:])), 2))+ if planned is None:+ return+ extra = [c for c in cuts if all(abs(c - p) > CUT_MATCH for p in planned)]+ lost = [p for p in planned if p > 0 and all(abs(c - p) > CUT_MATCH for c in cuts)]+ if extra:+ notes.append('picture cuts at %s that the prompt does not ask for' % ', '.join('%.1f s' % c for c in extra))+ if lost:+ notes.append('no picture cut at %s where the prompt has one' % ', '.join('%.1f s' % c for c in lost))++def _db(value):return float(20 * np.log10(max(float(value), 1e-9)))-def check(path, *, seconds=None, size=None, lines=None, transcribe=None):+def check(path, *, seconds=None, size=None, lines=None, transcribe=None, planned=None, first=None, last=None):"""Inspect one take. `seconds` is the planned length, `size` the expected (width, height),- `lines` the spoken lines the shot should contain and `transcribe(path)` returns the heard text."""+ `lines` the spoken lines the shot should contain and `transcribe(path)` returns the heard text.+ `planned` lists the seconds of the cuts the prompt asks for (empty: a single shot; None: not known),+ `first` and `last` are the given first and last frame images, if any."""problems, notes = [], []info = media.inspect(path)if size and (info['width'], info['height']) != tuple(size):@@ -154,6 +189,15 @@ def check(path, *, seconds=None, size=None, lines=None, transcribe=None):if flicker:notes.append('single odd frame at the %s (trim %s)' % (' and '.join(w for w, _ in flicker), ' and '.join('the first frame' if w == 'start' else 'the last frame' for w, _ in flicker)))result.update(black=black, frozen=frozen, flicker=[w for w, _ in flicker], stopped=ended)+ if len(small) > 2:+ _shots(result, notes, small, times, planned)+ for name, given, frame in (('first', first, small[0] if small else None), ('last', last, small[-1])):+ still = _still(given, frame.shape) if given else None+ if still is not None:+ held = float(np.abs(still - frame).mean())+ result[name + '_frame_diff'] = round(held, 1)+ if held > HOLD_DIFF:+ notes.append('the %s frame is not the given one' % name)if not info['has_audio']:problems.append('no audio track')