Skip to content

Commit 37f6cc5

Browse files
authored
Merge pull request #2880 from SeedCompany/native-ffprobe
2 parents dad6c4e + 9d87504 commit 37f6cc5

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Base node stage that sets up common config for dev & prod
22
FROM public.ecr.aws/docker/library/node:18-slim as node
33

4-
# Add wget in for healthchecks
4+
# Install these native packages
55
RUN apt-get update \
6-
&& apt-get install -y --no-install-recommends ca-certificates wget curl \
6+
&& apt-get install -y --no-install-recommends \
7+
ca-certificates wget curl \
8+
# Install ffprobe from here, as the npm version is manually published and as of comment segfaults with urls
9+
ffmpeg \
710
&& apt-get clean -q -y \
811
&& rm -rf /var/lib/apt/lists/*
912

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)