]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Reencode the video on cut
authorChocobozzz <me@florianbigard.com>
Tue, 14 Feb 2023 12:55:21 +0000 (13:55 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 14 Feb 2023 13:06:34 +0000 (14:06 +0100)
Unfortunately copying audio/video is not precise enough and could lead
to inconsistencies

server/helpers/ffmpeg/ffmpeg-edition.ts
server/lib/job-queue/handlers/video-studio-edition.ts

index 78de8f3b35632d7bc213a7e3aa65bfe40c4b24a8..02c5ea8de9723eb79dc96553c8002b8c84da1a31 100644 (file)
@@ -3,7 +3,7 @@ import { VIDEO_FILTERS } from '@server/initializers/constants'
 import { AvailableEncoders } from '@shared/models'
 import { logger, loggerTagsFactory } from '../logger'
 import { getFFmpeg, runCommand } from './ffmpeg-commons'
-import { presetCopy, presetVOD } from './ffmpeg-presets'
+import { presetVOD } from './ffmpeg-presets'
 import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS, hasAudioStream } from './ffprobe-utils'
 
 const lTags = loggerTagsFactory('ffmpeg')
@@ -13,25 +13,38 @@ async function cutVideo (options: {
   outputPath: string
   start?: number
   end?: number
+
+  availableEncoders: AvailableEncoders
+  profile: string
 }) {
-  const { inputPath, outputPath } = options
+  const { inputPath, outputPath, availableEncoders, profile } = options
 
   logger.debug('Will cut the video.', { options, ...lTags() })
 
+  const mainProbe = await ffprobePromise(inputPath)
+  const fps = await getVideoStreamFPS(inputPath, mainProbe)
+  const { resolution } = await getVideoStreamDimensionsInfo(inputPath, mainProbe)
+
   let command = getFFmpeg(inputPath, 'vod')
     .output(outputPath)
 
-  command = presetCopy(command)
+  command = await presetVOD({
+    command,
+    input: inputPath,
+    availableEncoders,
+    profile,
+    resolution,
+    fps,
+    canCopyAudio: false,
+    canCopyVideo: false
+  })
 
   if (options.start) {
-    // Using -ss as output option is more precise than using it as input option
     command.outputOption('-ss ' + options.start)
   }
 
   if (options.end) {
-    const endSeeking = options.end - (options.start || 0)
-
-    command.outputOption('-to ' + endSeeking)
+    command.outputOption('-to ' + options.end)
   }
 
   await runCommand({ command })
index 23f9a34ccdc0fa36191a3005474bc2ef2d31f1ed..3e208d83df4c818115d2c73db42f4fa8a97feca8 100644 (file)
@@ -164,7 +164,10 @@ function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) {
     ...pick(options, [ 'inputPath', 'outputPath' ]),
 
     start: task.options.start,
-    end: task.options.end
+    end: task.options.end,
+
+    availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
+    profile: CONFIG.TRANSCODING.PROFILE
   })
 }