Skip to content

Commit fe46e6c

Browse files
committed
Use native ffprobe in PATH if it exists
It's more likely that this is to update since it uses (1st party?) native package manager releases. The npm one is only manually updated/published. It'll be good for fallback/dev, but native will be better.
1 parent dad6c4e commit fe46e6c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/components/file/media/media-detector.service.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { path as ffprobeBinary } from '@ffprobe-installer/ffprobe';
1+
import npmFfprobe from '@ffprobe-installer/ffprobe';
22
import { forwardRef, Inject, Injectable } from '@nestjs/common';
3-
import { execa } from 'execa';
3+
import { CachedByArg as Once } from '@seedcompany/common';
4+
import { $, execa } from 'execa';
45
import { FFProbeResult } from 'ffprobe';
56
import { imageSize } from 'image-size';
67
import { ISize as ImageSize } from 'image-size/dist/types/interface';
@@ -69,11 +70,12 @@ export class MediaDetector {
6970
}
7071

7172
private async ffprobe(url: string): Promise<Partial<FFProbeResult>> {
73+
const binaryPath = await this.getFfprobeBinaryPath();
7274
try {
7375
return await retry(
7476
async () => {
7577
const probe = await execa(
76-
ffprobeBinary,
78+
binaryPath,
7779
[
7880
'-v',
7981
'error',
@@ -104,4 +106,14 @@ export class MediaDetector {
104106
return {};
105107
}
106108
}
109+
110+
@Once()
111+
private async getFfprobeBinaryPath() {
112+
try {
113+
await retry(async () => await $`which ffprobe`, { retries: 3 });
114+
return 'ffprobe';
115+
} catch {
116+
return npmFfprobe.path;
117+
}
118+
}
107119
}

0 commit comments

Comments
 (0)