@gannochenko/staticstripes 0.0.9 → 0.0.11

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.
@@ -7,6 +7,7 @@ import {
7
7
  SequenceDefinition,
8
8
  Fragment,
9
9
  Container,
10
+ FFmpegOption,
10
11
  } from './type';
11
12
  import { execFile } from 'child_process';
12
13
  import { promisify } from 'util';
@@ -34,10 +35,18 @@ export class HTMLProjectParser {
34
35
  this.validateAssetFiles(assets);
35
36
 
36
37
  const outputs = this.processOutputs();
38
+ const ffmpegOptions = this.processFfmpegOptions();
37
39
  const sequences = this.processSequences(assets);
38
40
  const cssText = this.html.cssText;
39
41
 
40
- return new Project(sequences, assets, outputs, cssText, this.projectPath);
42
+ return new Project(
43
+ sequences,
44
+ assets,
45
+ outputs,
46
+ ffmpegOptions,
47
+ cssText,
48
+ this.projectPath,
49
+ );
41
50
  }
42
51
 
43
52
  /**
@@ -458,6 +467,85 @@ export class HTMLProjectParser {
458
467
  return results;
459
468
  }
460
469
 
470
+ /**
471
+ * Processes ffmpeg options from the parsed HTML
472
+ */
473
+ private processFfmpegOptions(): Map<string, FFmpegOption> {
474
+ const ffmpegElements = this.findFfmpegElements();
475
+ const options = new Map<string, FFmpegOption>();
476
+
477
+ // Process each <ffmpeg> element (should typically be only one)
478
+ for (const ffmpegElement of ffmpegElements) {
479
+ // Find all <option> child elements
480
+ if ('childNodes' in ffmpegElement && ffmpegElement.childNodes) {
481
+ for (const child of ffmpegElement.childNodes) {
482
+ if ('tagName' in child) {
483
+ const childElement = child as Element;
484
+ if (childElement.tagName === 'option') {
485
+ const attrs = new Map(
486
+ childElement.attrs.map((attr) => [attr.name, attr.value]),
487
+ );
488
+
489
+ const name = attrs.get('name');
490
+ if (!name) {
491
+ continue; // Skip options without name
492
+ }
493
+
494
+ // Get the text content (the FFmpeg arguments)
495
+ let args = '';
496
+ if ('childNodes' in childElement && childElement.childNodes) {
497
+ for (const textNode of childElement.childNodes) {
498
+ if ('value' in textNode) {
499
+ args += textNode.value;
500
+ }
501
+ }
502
+ }
503
+
504
+ // Trim whitespace
505
+ args = args.trim();
506
+
507
+ const option: FFmpegOption = {
508
+ name,
509
+ args,
510
+ };
511
+
512
+ options.set(name, option);
513
+ }
514
+ }
515
+ }
516
+ }
517
+ }
518
+
519
+ return options;
520
+ }
521
+
522
+ /**
523
+ * Finds all ffmpeg elements in the HTML
524
+ */
525
+ private findFfmpegElements(): Element[] {
526
+ const results: Element[] = [];
527
+
528
+ const traverse = (node: ASTNode) => {
529
+ if ('tagName' in node) {
530
+ const element = node as Element;
531
+
532
+ // Check if element is an <ffmpeg> tag
533
+ if (element.tagName === 'ffmpeg') {
534
+ results.push(element);
535
+ }
536
+ }
537
+
538
+ if ('childNodes' in node && node.childNodes) {
539
+ for (const child of node.childNodes) {
540
+ traverse(child);
541
+ }
542
+ }
543
+ };
544
+
545
+ traverse(this.html.ast);
546
+ return results;
547
+ }
548
+
461
549
  /**
462
550
  * Processes sequences and fragments from the parsed HTML
463
551
  */
package/src/project.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Asset, Output, SequenceDefinition } from './type';
1
+ import { Asset, Output, SequenceDefinition, FFmpegOption } from './type';
2
2
  import { Label } from './ffmpeg';
3
3
  import { AssetManager } from './asset-manager';
4
4
  import { Sequence } from './sequence';
@@ -15,6 +15,7 @@ export class Project {
15
15
  private sequencesDefinitions: SequenceDefinition[],
16
16
  assets: Asset[],
17
17
  private outputs: Map<string, Output>,
18
+ private ffmpegOptions: Map<string, FFmpegOption>,
18
19
  private cssText: string,
19
20
  private projectPath: string,
20
21
  ) {
@@ -93,6 +94,14 @@ export class Project {
93
94
  return this.outputs;
94
95
  }
95
96
 
97
+ public getFfmpegOptions(): Map<string, FFmpegOption> {
98
+ return this.ffmpegOptions;
99
+ }
100
+
101
+ public getFfmpegOption(name: string): FFmpegOption | undefined {
102
+ return this.ffmpegOptions.get(name);
103
+ }
104
+
96
105
  public getCssText(): string {
97
106
  return this.cssText;
98
107
  }
@@ -121,7 +130,10 @@ export class Project {
121
130
  /**
122
131
  * Renders all containers and creates virtual assets for them
123
132
  */
124
- public async renderContainers(outputName: string): Promise<void> {
133
+ public async renderContainers(
134
+ outputName: string,
135
+ activeCacheKeys?: Set<string>,
136
+ ): Promise<void> {
125
137
  const output = this.getOutput(outputName);
126
138
  if (!output) {
127
139
  throw new Error(`Output "${outputName}" not found`);
@@ -147,6 +159,8 @@ export class Project {
147
159
  output.resolution.width,
148
160
  output.resolution.height,
149
161
  projectDir,
162
+ outputName,
163
+ activeCacheKeys,
150
164
  );
151
165
 
152
166
  // Create virtual assets and update fragment assetNames
package/src/type.ts CHANGED
@@ -73,6 +73,11 @@ export type Output = {
73
73
  fps: number; // e.g. 30
74
74
  };
75
75
 
76
+ export type FFmpegOption = {
77
+ name: string; // e.g. "preview", "production"
78
+ args: string; // e.g. "-c:v h264_nvenc -preset fast"
79
+ };
80
+
76
81
  export type ProjectStructure = {
77
82
  sequences: SequenceDefinition[];
78
83
  assets: Map<string, Asset>;