aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffmpeg/ffmpeg-edition.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-02-14 13:55:21 +0100
committerChocobozzz <me@florianbigard.com>2023-02-14 14:06:34 +0100
commit20321f2049f46a7bfaadcc5da2f1eb53b9bb4d76 (patch)
treeaa58dd778335149ee64e3971dec190c1bb337229 /server/helpers/ffmpeg/ffmpeg-edition.ts
parent98bd5e2256bfdeba6d5ab07f0421acfde1a0de26 (diff)
downloadPeerTube-20321f2049f46a7bfaadcc5da2f1eb53b9bb4d76.tar.gz
PeerTube-20321f2049f46a7bfaadcc5da2f1eb53b9bb4d76.tar.zst
PeerTube-20321f2049f46a7bfaadcc5da2f1eb53b9bb4d76.zip
Reencode the video on cut
Unfortunately copying audio/video is not precise enough and could lead to inconsistencies
Diffstat (limited to 'server/helpers/ffmpeg/ffmpeg-edition.ts')
-rw-r--r--server/helpers/ffmpeg/ffmpeg-edition.ts27
1 files changed, 20 insertions, 7 deletions
diff --git a/server/helpers/ffmpeg/ffmpeg-edition.ts b/server/helpers/ffmpeg/ffmpeg-edition.ts
index 78de8f3b3..02c5ea8de 100644
--- a/server/helpers/ffmpeg/ffmpeg-edition.ts
+++ b/server/helpers/ffmpeg/ffmpeg-edition.ts
@@ -3,7 +3,7 @@ import { VIDEO_FILTERS } from '@server/initializers/constants'
3import { AvailableEncoders } from '@shared/models' 3import { AvailableEncoders } from '@shared/models'
4import { logger, loggerTagsFactory } from '../logger' 4import { logger, loggerTagsFactory } from '../logger'
5import { getFFmpeg, runCommand } from './ffmpeg-commons' 5import { getFFmpeg, runCommand } from './ffmpeg-commons'
6import { presetCopy, presetVOD } from './ffmpeg-presets' 6import { presetVOD } from './ffmpeg-presets'
7import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS, hasAudioStream } from './ffprobe-utils' 7import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS, hasAudioStream } from './ffprobe-utils'
8 8
9const lTags = loggerTagsFactory('ffmpeg') 9const lTags = loggerTagsFactory('ffmpeg')
@@ -13,25 +13,38 @@ async function cutVideo (options: {
13 outputPath: string 13 outputPath: string
14 start?: number 14 start?: number
15 end?: number 15 end?: number
16
17 availableEncoders: AvailableEncoders
18 profile: string
16}) { 19}) {
17 const { inputPath, outputPath } = options 20 const { inputPath, outputPath, availableEncoders, profile } = options
18 21
19 logger.debug('Will cut the video.', { options, ...lTags() }) 22 logger.debug('Will cut the video.', { options, ...lTags() })
20 23
24 const mainProbe = await ffprobePromise(inputPath)
25 const fps = await getVideoStreamFPS(inputPath, mainProbe)
26 const { resolution } = await getVideoStreamDimensionsInfo(inputPath, mainProbe)
27
21 let command = getFFmpeg(inputPath, 'vod') 28 let command = getFFmpeg(inputPath, 'vod')
22 .output(outputPath) 29 .output(outputPath)
23 30
24 command = presetCopy(command) 31 command = await presetVOD({
32 command,
33 input: inputPath,
34 availableEncoders,
35 profile,
36 resolution,
37 fps,
38 canCopyAudio: false,
39 canCopyVideo: false
40 })
25 41
26 if (options.start) { 42 if (options.start) {
27 // Using -ss as output option is more precise than using it as input option
28 command.outputOption('-ss ' + options.start) 43 command.outputOption('-ss ' + options.start)
29 } 44 }
30 45
31 if (options.end) { 46 if (options.end) {
32 const endSeeking = options.end - (options.start || 0) 47 command.outputOption('-to ' + options.end)
33
34 command.outputOption('-to ' + endSeeking)
35 } 48 }
36 49
37 await runCommand({ command }) 50 await runCommand({ command })