diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-23 03:38:38 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-01-13 09:13:31 +0100 |
commit | 0984960345704c10256b40b78db1e4d9d7527e77 (patch) | |
tree | 6cafd4dbfb089bcb3997daa56c5ac55f290ef378 | |
parent | 1ea7da819e5bfae7b443ed722c18c4165d101439 (diff) | |
download | PeerTube-0984960345704c10256b40b78db1e4d9d7527e77.tar.gz PeerTube-0984960345704c10256b40b78db1e4d9d7527e77.tar.zst PeerTube-0984960345704c10256b40b78db1e4d9d7527e77.zip |
add script printing command to generate a resolution for a given file
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | scripts/print-transcode-command.ts | 52 | ||||
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 34 |
3 files changed, 71 insertions, 16 deletions
diff --git a/package.json b/package.json index 90b3768ac..ef4b62dd9 100644 --- a/package.json +++ b/package.json | |||
@@ -54,6 +54,7 @@ | |||
54 | "update-host": "node ./dist/scripts/update-host.js", | 54 | "update-host": "node ./dist/scripts/update-host.js", |
55 | "create-transcoding-job": "node ./dist/scripts/create-transcoding-job.js", | 55 | "create-transcoding-job": "node ./dist/scripts/create-transcoding-job.js", |
56 | "create-import-video-file-job": "node ./dist/scripts/create-import-video-file-job.js", | 56 | "create-import-video-file-job": "node ./dist/scripts/create-import-video-file-job.js", |
57 | "print-transcode-command": "node ./dist/scripts/print-transcode-command.js", | ||
57 | "test": "scripty", | 58 | "test": "scripty", |
58 | "help": "scripty", | 59 | "help": "scripty", |
59 | "generate-cli-doc": "scripty", | 60 | "generate-cli-doc": "scripty", |
diff --git a/scripts/print-transcode-command.ts b/scripts/print-transcode-command.ts new file mode 100644 index 000000000..b75b711a4 --- /dev/null +++ b/scripts/print-transcode-command.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' | ||
2 | registerTSPaths() | ||
3 | |||
4 | import * as program from 'commander' | ||
5 | import * as ffmpeg from 'fluent-ffmpeg' | ||
6 | import { availableEncoders } from '@server/lib/video-transcoding-profiles' | ||
7 | import { buildx264VODCommand, runCommand, TranscodeOptions } from '@server/helpers/ffmpeg-utils' | ||
8 | import { exit } from 'process' | ||
9 | |||
10 | program | ||
11 | .arguments('<path>') | ||
12 | .requiredOption('-r, --resolution [resolution]', 'video resolution') | ||
13 | .action((path, cmd) => { | ||
14 | if (cmd.resolution !== undefined && Number.isNaN(+cmd.resolution)) { | ||
15 | console.error('The resolution must be an integer (example: 1080).') | ||
16 | process.exit(-1) | ||
17 | } | ||
18 | |||
19 | run(path, cmd) | ||
20 | .then(() => process.exit(0)) | ||
21 | .catch(err => { | ||
22 | console.error(err) | ||
23 | process.exit(-1) | ||
24 | }) | ||
25 | }) | ||
26 | .parse(process.argv) | ||
27 | |||
28 | async function run (path: string, cmd: any) { | ||
29 | const options = { | ||
30 | type: 'video' as 'video', | ||
31 | inputPath: path, | ||
32 | outputPath: '/dev/null', | ||
33 | |||
34 | availableEncoders, | ||
35 | profile: 'default', | ||
36 | |||
37 | resolution: +cmd.resolution, | ||
38 | isPortraitMode: false | ||
39 | } as TranscodeOptions | ||
40 | |||
41 | let command = ffmpeg(options.inputPath) | ||
42 | .output(options.outputPath) | ||
43 | |||
44 | command = await buildx264VODCommand(command, options) | ||
45 | |||
46 | command.on('start', (cmdline) => { | ||
47 | console.log(cmdline) | ||
48 | exit() | ||
49 | }) | ||
50 | |||
51 | await runCommand(command) | ||
52 | } | ||
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index bf6408d3e..1f5e8d8f6 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -312,22 +312,6 @@ function buildStreamSuffix (base: string, streamNum?: number) { | |||
312 | } | 312 | } |
313 | 313 | ||
314 | // --------------------------------------------------------------------------- | 314 | // --------------------------------------------------------------------------- |
315 | |||
316 | export { | ||
317 | getLiveTranscodingCommand, | ||
318 | getLiveMuxingCommand, | ||
319 | buildStreamSuffix, | ||
320 | convertWebPToJPG, | ||
321 | processGIF, | ||
322 | generateImageFromVideoFile, | ||
323 | TranscodeOptions, | ||
324 | TranscodeOptionsType, | ||
325 | transcode | ||
326 | } | ||
327 | |||
328 | // --------------------------------------------------------------------------- | ||
329 | |||
330 | // --------------------------------------------------------------------------- | ||
331 | // Default options | 315 | // Default options |
332 | // --------------------------------------------------------------------------- | 316 | // --------------------------------------------------------------------------- |
333 | 317 | ||
@@ -642,3 +626,21 @@ async function runCommand (command: ffmpeg.FfmpegCommand, onEnd?: Function) { | |||
642 | command.run() | 626 | command.run() |
643 | }) | 627 | }) |
644 | } | 628 | } |
629 | |||
630 | // --------------------------------------------------------------------------- | ||
631 | |||
632 | export { | ||
633 | getLiveTranscodingCommand, | ||
634 | getLiveMuxingCommand, | ||
635 | buildStreamSuffix, | ||
636 | convertWebPToJPG, | ||
637 | processGIF, | ||
638 | generateImageFromVideoFile, | ||
639 | TranscodeOptions, | ||
640 | TranscodeOptionsType, | ||
641 | transcode, | ||
642 | runCommand, | ||
643 | |||
644 | // builders | ||
645 | buildx264VODCommand | ||
646 | } | ||