diff options
author | Seth Falco <seth@falco.fun> | 2023-08-02 23:22:36 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-08-18 10:17:16 +0200 |
commit | 2055962c844e557d628d9d0aae9303590c39eab8 (patch) | |
tree | e1ead9fc49f6b70e51e3728485d5c6b6c2d7fba9 | |
parent | 8e4fba97b26090e0c77ee9591058cd34ef9d2f55 (diff) | |
download | PeerTube-2055962c844e557d628d9d0aae9303590c39eab8.tar.gz PeerTube-2055962c844e557d628d9d0aae9303590c39eab8.tar.zst PeerTube-2055962c844e557d628d9d0aae9303590c39eab8.zip |
fix: handle git installation of ffmpeg
-rw-r--r-- | packages/ffmpeg/src/ffmpeg-version.ts | 13 | ||||
-rw-r--r-- | packages/tests/src/server-helpers/core-utils.ts | 53 | ||||
-rw-r--r-- | server/server/helpers/core-utils.ts | 14 | ||||
-rw-r--r-- | server/server/initializers/checker-after-init.ts | 9 |
4 files changed, 78 insertions, 11 deletions
diff --git a/packages/ffmpeg/src/ffmpeg-version.ts b/packages/ffmpeg/src/ffmpeg-version.ts index 41d9b2d89..f737bc254 100644 --- a/packages/ffmpeg/src/ffmpeg-version.ts +++ b/packages/ffmpeg/src/ffmpeg-version.ts | |||
@@ -1,6 +1,9 @@ | |||
1 | import { exec } from 'child_process' | 1 | import { exec } from 'child_process' |
2 | import ffmpeg from 'fluent-ffmpeg' | 2 | import ffmpeg from 'fluent-ffmpeg' |
3 | 3 | ||
4 | /** | ||
5 | * @returns FFmpeg version string. Usually a semver string, but may vary when depending on installation method. | ||
6 | */ | ||
4 | export function getFFmpegVersion () { | 7 | export function getFFmpegVersion () { |
5 | return new Promise<string>((res, rej) => { | 8 | return new Promise<string>((res, rej) => { |
6 | (ffmpeg() as any)._getFfmpegPath((err, ffmpegPath) => { | 9 | (ffmpeg() as any)._getFfmpegPath((err, ffmpegPath) => { |
@@ -10,14 +13,10 @@ export function getFFmpegVersion () { | |||
10 | return exec(`${ffmpegPath} -version`, (err, stdout) => { | 13 | return exec(`${ffmpegPath} -version`, (err, stdout) => { |
11 | if (err) return rej(err) | 14 | if (err) return rej(err) |
12 | 15 | ||
13 | const parsed = stdout.match(/ffmpeg version .?(\d+\.\d+(\.\d+)?)/) | 16 | const parsed = stdout.match(/(?<=ffmpeg version )[a-zA-Z\d.-]+/) |
14 | if (!parsed?.[1]) return rej(new Error(`Could not find ffmpeg version in ${stdout}`)) | 17 | if (!parsed) return rej(new Error(`Could not find ffmpeg version in ${stdout}`)) |
15 | 18 | ||
16 | // Fix ffmpeg version that does not include patch version (4.4 for example) | 19 | res(parsed[0]) |
17 | let version = parsed[1] | ||
18 | if (version.match(/^\d+\.\d+$/)) { | ||
19 | version += '.0' | ||
20 | } | ||
21 | }) | 20 | }) |
22 | }) | 21 | }) |
23 | }) | 22 | }) |
diff --git a/packages/tests/src/server-helpers/core-utils.ts b/packages/tests/src/server-helpers/core-utils.ts index 06c78591e..d61cae855 100644 --- a/packages/tests/src/server-helpers/core-utils.ts +++ b/packages/tests/src/server-helpers/core-utils.ts | |||
@@ -5,7 +5,7 @@ import snakeCase from 'lodash-es/snakeCase.js' | |||
5 | import validator from 'validator' | 5 | import validator from 'validator' |
6 | import { getAverageTheoreticalBitrate, getMaxTheoreticalBitrate } from '@peertube/peertube-core-utils' | 6 | import { getAverageTheoreticalBitrate, getMaxTheoreticalBitrate } from '@peertube/peertube-core-utils' |
7 | import { VideoResolution } from '@peertube/peertube-models' | 7 | import { VideoResolution } from '@peertube/peertube-models' |
8 | import { objectConverter, parseBytes, parseDurationToMs } from '@peertube/peertube-server/server/helpers/core-utils.js' | 8 | import { objectConverter, parseBytes, parseDurationToMs, parseSemVersion } from '@peertube/peertube-server/server/helpers/core-utils.js' |
9 | 9 | ||
10 | describe('Parse Bytes', function () { | 10 | describe('Parse Bytes', function () { |
11 | 11 | ||
@@ -148,3 +148,54 @@ describe('Bitrate', function () { | |||
148 | } | 148 | } |
149 | }) | 149 | }) |
150 | }) | 150 | }) |
151 | |||
152 | describe('Parse semantic version string', function () { | ||
153 | |||
154 | it('Should parse Node.js version string', function () { | ||
155 | const actual = parseSemVersion('v18.16.0') | ||
156 | |||
157 | expect(actual.major).to.equal(18) | ||
158 | expect(actual.minor).to.equal(16) | ||
159 | expect(actual.patch).to.equal(0) | ||
160 | }) | ||
161 | |||
162 | it('Should parse FFmpeg version string from Debian 12 repo', function () { | ||
163 | const actual = parseSemVersion('5.1.3-1') | ||
164 | |||
165 | expect(actual.major).to.equal(5) | ||
166 | expect(actual.minor).to.equal(1) | ||
167 | expect(actual.patch).to.equal(3) | ||
168 | }) | ||
169 | |||
170 | it('Should parse FFmpeg version string from Arch repo', function () { | ||
171 | const actual = parseSemVersion('n6.0') | ||
172 | |||
173 | expect(actual.major).to.equal(6) | ||
174 | expect(actual.minor).to.equal(0) | ||
175 | expect(actual.patch).to.equal(0) | ||
176 | }) | ||
177 | |||
178 | it('Should parse FFmpeg version from GitHub release', function () { | ||
179 | const actual = parseSemVersion('5.1.3') | ||
180 | |||
181 | expect(actual.major).to.equal(5) | ||
182 | expect(actual.minor).to.equal(1) | ||
183 | expect(actual.patch).to.equal(3) | ||
184 | }) | ||
185 | |||
186 | it('Should parse FFmpeg version from GitHub dev release', function () { | ||
187 | const actual = parseSemVersion('5.1.git') | ||
188 | |||
189 | expect(actual.major).to.equal(5) | ||
190 | expect(actual.minor).to.equal(1) | ||
191 | expect(actual.patch).to.equal(0) | ||
192 | }) | ||
193 | |||
194 | it('Should parse FFmpeg version string with missing patch segment', function () { | ||
195 | const actual = parseSemVersion('4.4') | ||
196 | |||
197 | expect(actual.major).to.equal(4) | ||
198 | expect(actual.minor).to.equal(4) | ||
199 | expect(actual.patch).to.equal(0) | ||
200 | }) | ||
201 | }) | ||
diff --git a/server/server/helpers/core-utils.ts b/server/server/helpers/core-utils.ts index 6dc09d317..9b40ca5be 100644 --- a/server/server/helpers/core-utils.ts +++ b/server/server/helpers/core-utils.ts | |||
@@ -183,13 +183,23 @@ function pageToStartAndCount (page: number, itemsPerPage: number) { | |||
183 | // --------------------------------------------------------------------------- | 183 | // --------------------------------------------------------------------------- |
184 | 184 | ||
185 | type SemVersion = { major: number, minor: number, patch: number } | 185 | type SemVersion = { major: number, minor: number, patch: number } |
186 | |||
187 | /** | ||
188 | * Parses a semantic version string into its separate components. | ||
189 | * Fairly lax, and allows for missing or additional segments in the string. | ||
190 | * | ||
191 | * @param s String to parse semantic version from. | ||
192 | * @returns Major, minor, and patch version, or null if string does not follow semantic version conventions. | ||
193 | */ | ||
186 | function parseSemVersion (s: string) { | 194 | function parseSemVersion (s: string) { |
187 | const parsed = s.match(/^v?(\d+)\.(\d+)\.(\d+)$/i) | 195 | const parsed = s.match(/v?(\d+)\.(\d+)(?:\.(\d+))?/i) |
196 | |||
197 | if (!parsed) return null | ||
188 | 198 | ||
189 | return { | 199 | return { |
190 | major: parseInt(parsed[1]), | 200 | major: parseInt(parsed[1]), |
191 | minor: parseInt(parsed[2]), | 201 | minor: parseInt(parsed[2]), |
192 | patch: parseInt(parsed[3]) | 202 | patch: parsed[3] ? parseInt(parsed[3]) : 0 |
193 | } as SemVersion | 203 | } as SemVersion |
194 | } | 204 | } |
195 | 205 | ||
diff --git a/server/server/initializers/checker-after-init.ts b/server/server/initializers/checker-after-init.ts index afcf6176b..5e7e513f1 100644 --- a/server/server/initializers/checker-after-init.ts +++ b/server/server/initializers/checker-after-init.ts | |||
@@ -78,7 +78,14 @@ async function applicationExist () { | |||
78 | 78 | ||
79 | async function checkFFmpegVersion () { | 79 | async function checkFFmpegVersion () { |
80 | const version = await getFFmpegVersion() | 80 | const version = await getFFmpegVersion() |
81 | const { major, minor, patch } = parseSemVersion(version) | 81 | const semvar = parseSemVersion(version) |
82 | |||
83 | if (!semvar) { | ||
84 | logger.warn('Your ffmpeg version (%s) does not use semvar. Unable to determine version compatibility.', version) | ||
85 | return | ||
86 | } | ||
87 | |||
88 | const { major, minor, patch } = semvar | ||
82 | 89 | ||
83 | if (major < 4 || (major === 4 && minor < 1)) { | 90 | if (major < 4 || (major === 4 && minor < 1)) { |
84 | logger.warn('Your ffmpeg version (%s) is outdated. PeerTube supports ffmpeg >= 4.1. Please upgrade ffmpeg.', version) | 91 | logger.warn('Your ffmpeg version (%s) is outdated. PeerTube supports ffmpeg >= 4.1. Please upgrade ffmpeg.', version) |