• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fluent-ffmpeg / node-fluent-ffmpeg / 6889204749

16 Nov 2023 10:07AM UTC coverage: 84.691% (-6.1%) from 90.801%
6889204749

Pull #1235

github

web-flow
Merge a982927b9 into 4e02d1257
Pull Request #1235: V3 experiments

257 of 296 branches covered (0.0%)

1040 of 1228 new or added lines in 15 files covered. (84.69%)

1040 of 1228 relevant lines covered (84.69%)

8.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.09
/src/command.ts
1
import { Readable, Writable } from 'node:stream'
2!
2
import { FfmpegInput, InputDefinition } from './input'
2✔
3
import { FfmpegOutput, OutputDefinition } from './output'
2✔
4
import { FfmpegProcess, RunResult, RunOptions, ProcessOptions } from './process'
2✔
5

2✔
6
export type CommandOptions = {
2✔
7
  input?: InputDefinition
2✔
8
  inputs?: InputDefinition[]
2✔
9
  output?: OutputDefinition
2✔
10
  outputs?: OutputDefinition[]
2✔
11
}
2✔
12

2✔
13
export class FfmpegCommand implements CommandOptions {
10✔
14
  inputs: FfmpegInput[]
10✔
15
  outputs: FfmpegOutput[]
10✔
16

10✔
17
  constructor(options: CommandOptions) {
10✔
18
    if (options.input) {
10✔
19
      if (options.inputs) {
6✔
20
        throw new Error("Cannot specify both 'input' and 'inputs'")
2✔
21
      }
2✔
22

4✔
23
      options.inputs = [options.input]
4✔
24
    }
4✔
25

8✔
26
    if (options.output) {
10!
NEW
27
      if (options.outputs) {
×
NEW
28
        throw new Error("Cannot specify both 'output' and 'outputs'")
×
NEW
29
      }
×
NEW
30

×
NEW
31
      options.outputs = [options.output]
×
NEW
32
    }
×
33

8✔
34
    this.inputs = (options.inputs || []).map(
10!
35
      (inputOptions) => new FfmpegInput(inputOptions)
10✔
36
    )
10✔
37

10✔
38
    this.outputs = (options.outputs || []).map(
10✔
39
      (outputOptions) => new FfmpegOutput(outputOptions)
10✔
40
    )
10✔
41

10✔
42
    this.#validateIO()
10✔
43
  }
10✔
44

10✔
45
  #validateIO(): void {
10✔
46
    if (this.inputs.filter((i) => i.isStream).length > 1) {
8✔
47
      throw new Error(`At most one stream input is supported`)
2✔
48
    }
2✔
49

6✔
50
    if (this.outputs.filter((o) => o.isStream).length > 1) {
8!
NEW
51
      throw new Error(`At most one stream output is supported`)
×
NEW
52
    }
×
53
  }
8✔
54

10✔
55
  getFfmpegArguments(): string[] {
10✔
56
    let args: string[] = []
6✔
57

6✔
58
    for (let input of this.inputs) {
6✔
59
      args.push(...input.getFfmpegArguments())
10✔
60
    }
10✔
61

6✔
62
    // TODO complex filters
6✔
63

6✔
64
    if (this.outputs.some((o) => o.isLocalFile)) {
6!
NEW
65
      // Force overwrite outputs
×
NEW
66
      args.push('-y')
×
NEW
67
    }
×
68

6✔
69
    for (let output of this.outputs) {
6!
NEW
70
      args.push(...output.getFfmpegArguments())
×
NEW
71
    }
×
72

6✔
73
    return args
6✔
74
  }
6✔
75

10✔
76
  run(options: RunOptions): Promise<RunResult> {
10✔
NEW
77
    let procOtions: ProcessOptions = {
×
NEW
78
      args: this.getFfmpegArguments(),
×
NEW
79
      ...options
×
NEW
80
    }
×
NEW
81

×
NEW
82
    let streamInput = this.inputs.find((i) => i.isStream)
×
NEW
83
    if (streamInput) {
×
NEW
84
      procOtions.inputStream = streamInput.source as Readable
×
NEW
85
    }
×
NEW
86

×
NEW
87
    let streamOutput = this.outputs.find((i) => i.isStream)
×
NEW
88
    if (streamOutput) {
×
NEW
89
      procOtions.outputStream = streamOutput.target as Writable
×
NEW
90
    }
×
NEW
91

×
NEW
92
    return new FfmpegProcess(procOtions).run()
×
NEW
93
  }
×
94
}
10✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc