]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/video-transcoding.ts
Add audio-only option to transcoders and player
[github/Chocobozzz/PeerTube.git] / server / lib / video-transcoding.ts
index 9243d17422da17fa46eaa647d03e29886f86771d..9dd54837fb3c2fe01d8e7721f6b733aa30d1c7b9 100644 (file)
@@ -81,12 +81,52 @@ async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoR
   const videoOutputPath = getVideoFilePath(video, newVideoFile)
   const videoTranscodedPath = join(transcodeDirectory, getVideoFilename(video, newVideoFile))
 
+  const transcodeOptions = resolution === VideoResolution.H_NOVIDEO
+    ? {
+        type: 'split-audio' as 'split-audio',
+        inputPath: videoInputPath,
+        outputPath: videoTranscodedPath,
+        resolution,
+      }
+    : {
+        type: 'video' as 'video',
+        inputPath: videoInputPath,
+        outputPath: videoTranscodedPath,
+        resolution,
+        isPortraitMode: isPortrait
+      }
+
+  await transcode(transcodeOptions)
+
+  return onVideoFileTranscoding(video, newVideoFile, videoTranscodedPath, videoOutputPath)
+}
+
+/**
+ * Extract audio into a separate audio-only mp4.
+ */
+async function splitAudioFile (video: MVideoWithFile) {
+  const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
+  const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
+  const extname = '.mp4'
+  const resolution = VideoResolution.H_NOVIDEO
+
+  // We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed
+  const videoInputPath = join(videosDirectory, video.getVideoFilename(video.getOriginalFile()))
+
+  const newVideoFile = new VideoFileModel({
+    resolution,
+    extname,
+    size: 0,
+    videoId: video.id
+  })
+  const videoOutputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(newVideoFile))
+  const videoTranscodedPath = join(transcodeDirectory, video.getVideoFilename(newVideoFile))
+
   const transcodeOptions = {
-    type: 'video' as 'video',
+    type: 'split-audio' as 'split-audio',
     inputPath: videoInputPath,
     outputPath: videoTranscodedPath,
-    resolution,
-    isPortraitMode: isPortrait
+    resolution
   }
 
   await transcode(transcodeOptions)