From 5c7d650827cc471a03e7fa18362bcbcbe5d30838 Mon Sep 17 00:00:00 2001 From: frankdelange Date: Fri, 1 Nov 2019 02:06:19 +0100 Subject: Add audio-only option to transcoders and player This patch adds an audio-only option to PeerTube by means of a new transcoding configuration which creates mp4 files which only contain an audio stream. This new transcoder has a resolution of '0' and is presented in the preferences and in the player resolution menu as 'Audio-only' (localised). When playing such streams the player shows the file thumbnail as background and disables controls autohide. Audio-only files can be shared and streamed just like any other file. They can be downloaded as well, the resulting file will be an mp4 container with a single audio stream. This patch is a proof of concept to show the feasibility of 'true' audio-only support. There are better ways of doing this which also enable multiple audio streams for a given video stream (e.g. DASH) but as this would entail a fundamental change in the way PeerTube works it is a bridge too far for a simple proof of concept. --- server/lib/video-transcoding.ts | 46 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'server/lib') diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index 9243d1742..9dd54837f 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts @@ -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) -- cgit v1.2.3