tuna-agent 0.1.136 → 0.1.137

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -269,56 +269,74 @@ export async function analyzeVideo(url, onProgress) {
269
269
  // 90s monologue becomes ~11 scenes instead of one giant clip. A hard
270
270
  // ceiling still bounds runaway vision cost on very long videos.
271
271
  const TARGET_SCENE_SEC = 8;
272
- const HARD_CAP = 600; // ~80 min @ 8s safety bound on vision API spend
273
- const targetScenes = Math.max(1, Math.ceil(durationSec / TARGET_SCENE_SEC));
274
- const MAX_SCENES = Math.min(targetScenes + 20, HARD_CAP);
275
- // Split a [start,end] span into ≤TARGET_SCENE_SEC sub-slots, preserving
276
- // the voiceover on the FIRST sub-slot (the rest are silent continuations
277
- // of the same spoken line so lip-sync isn't duplicated downstream).
278
- const pushSplit = (start, end, voiceover) => {
279
- const span = end - start;
280
- if (span <= TARGET_SCENE_SEC * 1.5) {
281
- sceneSlots.push({ start, end, voiceover });
282
- return;
283
- }
284
- const n = Math.ceil(span / TARGET_SCENE_SEC);
285
- const step = span / n;
286
- for (let k = 0; k < n; k++) {
287
- sceneSlots.push({
288
- start: start + k * step,
289
- end: k === n - 1 ? end : start + (k + 1) * step,
290
- voiceover: k === 0 ? voiceover : '',
291
- });
292
- }
293
- };
272
+ // Safety ceiling ONLY (≈80 min @ 8s). It must NOT be derived from
273
+ // ceil(duration/8): Whisper emits hundreds of 2-4s segments for a talky
274
+ // video, so a tighter cap + slice() silently dropped the back half of
275
+ // the video (13-min clip 118 slots → only first 6:21 kept). The
276
+ // normalise pass below already collapses tiny segments into ~8s scenes,
277
+ // so the natural count ceil(duration/8) and this only guards runaway.
278
+ const HARD_CAP = 600;
279
+ const spans = [];
294
280
  if (segments.length > 0) {
295
- if (segments[0].start > SILENCE_THRESHOLD) {
296
- pushSplit(0, segments[0].start, '');
297
- }
281
+ if (segments[0].start > SILENCE_THRESHOLD)
282
+ spans.push({ start: 0, end: segments[0].start, voiceover: '' });
298
283
  for (let i = 0; i < segments.length; i++) {
299
284
  const seg = segments[i];
300
- pushSplit(seg.start, seg.end, seg.text?.trim() || '');
285
+ spans.push({ start: seg.start, end: seg.end, voiceover: seg.text?.trim() || '' });
301
286
  if (i < segments.length - 1) {
302
287
  const gap = segments[i + 1].start - seg.end;
303
- if (gap > SILENCE_THRESHOLD) {
304
- pushSplit(seg.end, segments[i + 1].start, '');
305
- }
288
+ if (gap > SILENCE_THRESHOLD)
289
+ spans.push({ start: seg.end, end: segments[i + 1].start, voiceover: '' });
306
290
  }
307
291
  }
308
292
  const lastEnd = segments[segments.length - 1].end;
309
- if (durationSec - lastEnd > SILENCE_THRESHOLD) {
310
- pushSplit(lastEnd, durationSec, '');
311
- }
293
+ if (durationSec - lastEnd > SILENCE_THRESHOLD)
294
+ spans.push({ start: lastEnd, end: durationSec, voiceover: '' });
312
295
  }
313
296
  else {
314
- // No transcript — split into scenes every 8s (Veo3 clip length)
315
297
  for (let t = 0; t < durationSec; t += TARGET_SCENE_SEC) {
316
- sceneSlots.push({ start: t, end: Math.min(t + TARGET_SCENE_SEC, durationSec), voiceover: '' });
298
+ spans.push({ start: t, end: Math.min(t + TARGET_SCENE_SEC, durationSec), voiceover: '' });
299
+ }
300
+ }
301
+ // 2) Normalise every span to ~TARGET-second scenes covering the FULL
302
+ // timeline:
303
+ // - long span (> 1.5×TARGET): split into ceil(span/TARGET) equal slots
304
+ // - short spans: greedily MERGE consecutive ones until ≈TARGET so a
305
+ // talky video becomes ~ceil(duration/8) Veo3-length scenes instead
306
+ // of hundreds of 2s fragments — crucially WITHOUT dropping the tail.
307
+ for (let i = 0; i < spans.length;) {
308
+ const s = spans[i];
309
+ const span = s.end - s.start;
310
+ if (span > TARGET_SCENE_SEC * 1.5) {
311
+ const n = Math.ceil(span / TARGET_SCENE_SEC);
312
+ const step = span / n;
313
+ for (let k = 0; k < n; k++) {
314
+ sceneSlots.push({
315
+ start: s.start + k * step,
316
+ end: k === n - 1 ? s.end : s.start + (k + 1) * step,
317
+ voiceover: k === 0 ? s.voiceover : '',
318
+ });
319
+ }
320
+ i++;
321
+ }
322
+ else {
323
+ let end = s.end;
324
+ const vo = s.voiceover ? [s.voiceover] : [];
325
+ let j = i + 1;
326
+ while (j < spans.length &&
327
+ (end - s.start) < TARGET_SCENE_SEC &&
328
+ (spans[j].end - s.start) <= TARGET_SCENE_SEC * 1.5) {
329
+ end = spans[j].end;
330
+ if (spans[j].voiceover)
331
+ vo.push(spans[j].voiceover);
332
+ j++;
333
+ }
334
+ sceneSlots.push({ start: s.start, end, voiceover: vo.join(' ') });
335
+ i = j;
317
336
  }
318
337
  }
319
- // Duration-aware cap (was a flat 30 that silently truncated any video
320
- // longer than ~4 min). Re-number after slicing.
321
- const finalSlots = sceneSlots.slice(0, MAX_SCENES);
338
+ // slice() now only ever trims pathological >80-min inputs.
339
+ const finalSlots = sceneSlots.slice(0, HARD_CAP);
322
340
  progress(`Đang cắt ${finalSlots.length} frames và phân tích...`);
323
341
  console.log('[analyze_video] Building', finalSlots.length, 'scenes (segments:', segments.length, ', duration:', durationSec, 's)');
324
342
  // Step 1: Extract frames sequentially. Per scene we grab 3 chronological
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuna-agent",
3
- "version": "0.1.136",
3
+ "version": "0.1.137",
4
4
  "description": "Tuna Agent - Run AI coding tasks on your machine",
5
5
  "bin": {
6
6
  "tuna-agent": "dist/cli/index.js"