shiveshnavin commited on
Commit
b93e09e
·
1 Parent(s): f9e47b5

Fix media

Browse files
Files changed (3) hide show
  1. common-utils +1 -1
  2. server-plugins/crop.js +14 -3
  3. utils/bubble/Bubble.js +42 -28
common-utils CHANGED
@@ -1 +1 @@
1
- Subproject commit 017243cdd3557fe8e78c195b79bdce52b17f5b92
 
1
+ Subproject commit f3193e64265d3e62a078f03e22b136a049c0b1d6
server-plugins/crop.js CHANGED
@@ -8,6 +8,10 @@ export class CropPlugin extends Plugin {
8
  super(name, options);
9
  }
10
 
 
 
 
 
11
  async applyPrerender(originalManuscript, jobId) {
12
  const transcript = originalManuscript.transcript || [];
13
  const targetWidth = +this.options.width || +this.options.targetWidth || 1080;
@@ -18,10 +22,17 @@ export class CropPlugin extends Plugin {
18
  if (!item.mediaAbsPaths || !item.mediaAbsPaths.length) continue;
19
  for (let mediaObj of item.mediaAbsPaths) {
20
  try {
21
- const mediaPath = mediaObj.path;
22
  if (!mediaPath || !fs.existsSync(mediaPath)) {
23
- this.log(`Media path does not exist: ${mediaPath}`);
24
- continue;
 
 
 
 
 
 
 
25
  }
26
 
27
  const meta = await FFMpegUtils.getMediaMetadata(mediaPath);
 
8
  super(name, options);
9
  }
10
 
11
+ mediaPathFlatten(mediaPath) {
12
+ return path.join('public', path.basename(mediaPath));
13
+ }
14
+
15
  async applyPrerender(originalManuscript, jobId) {
16
  const transcript = originalManuscript.transcript || [];
17
  const targetWidth = +this.options.width || +this.options.targetWidth || 1080;
 
22
  if (!item.mediaAbsPaths || !item.mediaAbsPaths.length) continue;
23
  for (let mediaObj of item.mediaAbsPaths) {
24
  try {
25
+ let mediaPath = mediaObj.path;
26
  if (!mediaPath || !fs.existsSync(mediaPath)) {
27
+ const flattenedPath = this.mediaPathFlatten(mediaPath);
28
+ if (fs.existsSync(flattenedPath)) {
29
+ mediaObj.path = flattenedPath;
30
+ mediaPath = flattenedPath;
31
+ this.log(`Using flattened media path: ${flattenedPath}`);
32
+ } else {
33
+ this.log(`Media path does not exist: ${mediaPath}. Trying at flattened path: ${flattenedPath} failed.`);
34
+ continue;
35
+ }
36
  }
37
 
38
  const meta = await FFMpegUtils.getMediaMetadata(mediaPath);
utils/bubble/Bubble.js CHANGED
@@ -273,10 +273,26 @@ class BubbleMaker {
273
  * Apply template defaults to a bubble config for a given video size.
274
  */
275
  _applyTemplate(bubble, vw, vh) {
276
- if (!bubble || !bubble.templateName) return bubble;
277
- const tpl = BaseBubbleTemplates[bubble.templateName];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  if (!tpl) return bubble;
 
279
  let b = _.merge({}, tpl, bubble);
 
280
  if (!b.animExtra) {
281
  if (tpl.mediaAbsPath && tpl.mediaAbsPath.animExtra) b.animExtra = tpl.mediaAbsPath.animExtra;
282
  else if (tpl.mediaAbsPaths && Array.isArray(tpl.mediaAbsPaths) && tpl.mediaAbsPaths[0] && tpl.mediaAbsPaths[0].animExtra) {
@@ -326,22 +342,21 @@ class BubbleMaker {
326
 
327
  let overlayMeta;
328
  try { overlayMeta = await FFMpegUtils.getMediaMetadata(overlayPath); } catch (e) { overlayMeta = null; }
329
- if (overlayMeta && overlayMeta.video && overlayMeta.video.width) {
330
- const ar = overlayMeta.video.width / overlayMeta.video.height;
331
- if (extra.size === 'full') {
332
- const maxW = Math.round(vw * (1 - 2 * padX / 100));
333
- const maxH = Math.round(vh * (1 - 2 * padY / 100));
334
- if (ar > maxW / maxH) { oh = maxH; ow = Math.round(maxH * ar); }
335
- else { ow = maxW; oh = Math.round(maxW / ar); }
336
- if (ow < maxW) ow = maxW;
337
- if (oh < maxH) oh = maxH;
338
  } else {
339
- if (!ow) ow = Math.round(vw * 0.30);
340
- if (!oh) oh = Math.round(ow / ar);
341
  }
 
 
 
 
342
  } else if (!oh) {
343
- if (extra.size === 'full') { oh = Math.round(vh * (1 - 2 * padY / 100)); ow = Math.round(vw * (1 - 2 * padX / 100)); }
344
- else oh = Math.round((ow || Math.round(vw * 0.30)) * 0.75);
345
  }
346
  if (!ow) ow = Math.round(vw * 0.30);
347
  if (!oh) oh = Math.round(ow * 0.75);
@@ -416,22 +431,21 @@ class BubbleMaker {
416
 
417
  let overlayMeta;
418
  try { overlayMeta = await FFMpegUtils.getMediaMetadata(overlayPath); } catch (e) { overlayMeta = null; }
419
- if (overlayMeta && overlayMeta.video && overlayMeta.video.width) {
420
- const ar = overlayMeta.video.width / overlayMeta.video.height;
421
- if (extra.size === 'full') {
422
- const maxW = Math.round(vw * (1 - 2 * padX / 100));
423
- const maxH = Math.round(vh * (1 - 2 * padY / 100));
424
- if (ar > maxW / maxH) { oh = maxH; ow = Math.round(maxH * ar); }
425
- else { ow = maxW; oh = Math.round(maxW / ar); }
426
- if (ow < maxW) ow = maxW;
427
- if (oh < maxH) oh = maxH;
428
  } else {
429
- if (!ow) ow = Math.round(vw * 0.30);
430
- if (!oh) oh = Math.round(ow / ar);
431
  }
 
 
 
 
432
  } else if (!oh) {
433
- if (extra.size === 'full') { oh = Math.round(vh * (1 - 2 * padY / 100)); ow = Math.round(vw * (1 - 2 * padX / 100)); }
434
- else oh = Math.round((ow || Math.round(vw * 0.30)) * 0.75);
435
  }
436
  if (!ow) ow = Math.round(vw * 0.30);
437
  if (!oh) oh = Math.round(ow * 0.75);
 
273
  * Apply template defaults to a bubble config for a given video size.
274
  */
275
  _applyTemplate(bubble, vw, vh) {
276
+ if (!bubble) return bubble;
277
+
278
+ let templateName = bubble.templateName;
279
+ let tpl = templateName ? BaseBubbleTemplates[templateName] : null;
280
+ if (!tpl) {
281
+ const entries = Object.entries(BaseBubbleTemplates || {});
282
+ const hasMedia = !!(bubble.mediaAbsPaths || bubble.mediaAbsPath || bubble.mediaAbs);
283
+ const hasText = !!bubble.bubbleText;
284
+ const fallback = hasMedia
285
+ ? entries.find(([name]) => name.toLowerCase().includes('media'))
286
+ : (hasText ? entries.find(([name]) => !name.toLowerCase().includes('media')) : null);
287
+ if (fallback) {
288
+ templateName = fallback[0];
289
+ tpl = fallback[1];
290
+ }
291
+ }
292
  if (!tpl) return bubble;
293
+
294
  let b = _.merge({}, tpl, bubble);
295
+ if (!b.templateName && templateName) b.templateName = templateName;
296
  if (!b.animExtra) {
297
  if (tpl.mediaAbsPath && tpl.mediaAbsPath.animExtra) b.animExtra = tpl.mediaAbsPath.animExtra;
298
  else if (tpl.mediaAbsPaths && Array.isArray(tpl.mediaAbsPaths) && tpl.mediaAbsPaths[0] && tpl.mediaAbsPaths[0].animExtra) {
 
342
 
343
  let overlayMeta;
344
  try { overlayMeta = await FFMpegUtils.getMediaMetadata(overlayPath); } catch (e) { overlayMeta = null; }
345
+ if (extra.size === 'full') {
346
+ const maxW = Math.max(1, Math.round(vw * (1 - 2 * padX / 100)));
347
+ ow = maxW;
348
+ if (overlayMeta && overlayMeta.video && overlayMeta.video.width && overlayMeta.video.height) {
349
+ const ar = overlayMeta.video.width / overlayMeta.video.height;
350
+ oh = Math.max(1, Math.round(ow / ar));
 
 
 
351
  } else {
352
+ oh = Math.max(1, Math.round(vh * (1 - 2 * padY / 100)));
 
353
  }
354
+ } else if (overlayMeta && overlayMeta.video && overlayMeta.video.width && overlayMeta.video.height) {
355
+ const ar = overlayMeta.video.width / overlayMeta.video.height;
356
+ if (!ow) ow = Math.round(vw * 0.30);
357
+ if (!oh) oh = Math.round(ow / ar);
358
  } else if (!oh) {
359
+ oh = Math.round((ow || Math.round(vw * 0.30)) * 0.75);
 
360
  }
361
  if (!ow) ow = Math.round(vw * 0.30);
362
  if (!oh) oh = Math.round(ow * 0.75);
 
431
 
432
  let overlayMeta;
433
  try { overlayMeta = await FFMpegUtils.getMediaMetadata(overlayPath); } catch (e) { overlayMeta = null; }
434
+ if (extra.size === 'full') {
435
+ const maxW = Math.max(1, Math.round(vw * (1 - 2 * padX / 100)));
436
+ ow = maxW;
437
+ if (overlayMeta && overlayMeta.video && overlayMeta.video.width && overlayMeta.video.height) {
438
+ const ar = overlayMeta.video.width / overlayMeta.video.height;
439
+ oh = Math.max(1, Math.round(ow / ar));
 
 
 
440
  } else {
441
+ oh = Math.max(1, Math.round(vh * (1 - 2 * padY / 100)));
 
442
  }
443
+ } else if (overlayMeta && overlayMeta.video && overlayMeta.video.width && overlayMeta.video.height) {
444
+ const ar = overlayMeta.video.width / overlayMeta.video.height;
445
+ if (!ow) ow = Math.round(vw * 0.30);
446
+ if (!oh) oh = Math.round(ow / ar);
447
  } else if (!oh) {
448
+ oh = Math.round((ow || Math.round(vw * 0.30)) * 0.75);
 
449
  }
450
  if (!ow) ow = Math.round(vw * 0.30);
451
  if (!oh) oh = Math.round(ow * 0.75);