diff options
author | Chocobozzz <me@florianbigard.com> | 2019-10-18 11:44:01 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-10-18 11:44:01 +0200 |
commit | eba06469b70ffd722532881e40574d2a38a2a19b (patch) | |
tree | e0b83e3d30e3d6605cfd34f302f159f40e6b75fb /server | |
parent | 2f26030dd2da121fb1d1701600e93f689141df40 (diff) | |
download | PeerTube-eba06469b70ffd722532881e40574d2a38a2a19b.tar.gz PeerTube-eba06469b70ffd722532881e40574d2a38a2a19b.tar.zst PeerTube-eba06469b70ffd722532881e40574d2a38a2a19b.zip |
Fix audio merging when specifying a preview
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/video-transcoding.ts | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index a204c0c63..612d388ee 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts | |||
@@ -1,7 +1,14 @@ | |||
1 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants' | 1 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants' |
2 | import { join } from 'path' | 2 | import { basename, join } from 'path' |
3 | import { canDoQuickTranscode, getVideoFileFPS, transcode, TranscodeOptions, TranscodeOptionsType } from '../helpers/ffmpeg-utils' | 3 | import { |
4 | import { ensureDir, move, remove, stat } from 'fs-extra' | 4 | canDoQuickTranscode, |
5 | getDurationFromVideoFile, | ||
6 | getVideoFileFPS, | ||
7 | transcode, | ||
8 | TranscodeOptions, | ||
9 | TranscodeOptionsType | ||
10 | } from '../helpers/ffmpeg-utils' | ||
11 | import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' | ||
5 | import { logger } from '../helpers/logger' | 12 | import { logger } from '../helpers/logger' |
6 | import { VideoResolution } from '../../shared/models/videos' | 13 | import { VideoResolution } from '../../shared/models/videos' |
7 | import { VideoFileModel } from '../models/video/video-file' | 14 | import { VideoFileModel } from '../models/video/video-file' |
@@ -97,22 +104,37 @@ async function mergeAudioVideofile (video: MVideoWithFileThumbnail, resolution: | |||
97 | const audioInputPath = join(videosDirectory, video.getVideoFilename(video.getOriginalFile())) | 104 | const audioInputPath = join(videosDirectory, video.getVideoFilename(video.getOriginalFile())) |
98 | const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname) | 105 | const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname) |
99 | 106 | ||
107 | // If the user updates the video preview during transcoding | ||
108 | const previewPath = video.getPreview().getPath() | ||
109 | const tmpPreviewPath = join(CONFIG.STORAGE.TMP_DIR, basename(previewPath)) | ||
110 | await copyFile(previewPath, tmpPreviewPath) | ||
111 | |||
100 | const transcodeOptions = { | 112 | const transcodeOptions = { |
101 | type: 'merge-audio' as 'merge-audio', | 113 | type: 'merge-audio' as 'merge-audio', |
102 | inputPath: video.getPreview().getPath(), | 114 | inputPath: tmpPreviewPath, |
103 | outputPath: videoTranscodedPath, | 115 | outputPath: videoTranscodedPath, |
104 | audioPath: audioInputPath, | 116 | audioPath: audioInputPath, |
105 | resolution | 117 | resolution |
106 | } | 118 | } |
107 | 119 | ||
108 | await transcode(transcodeOptions) | 120 | try { |
121 | await transcode(transcodeOptions) | ||
109 | 122 | ||
110 | await remove(audioInputPath) | 123 | await remove(audioInputPath) |
124 | await remove(tmpPreviewPath) | ||
125 | } catch (err) { | ||
126 | await remove(tmpPreviewPath) | ||
127 | throw err | ||
128 | } | ||
111 | 129 | ||
112 | // Important to do this before getVideoFilename() to take in account the new file extension | 130 | // Important to do this before getVideoFilename() to take in account the new file extension |
113 | inputVideoFile.extname = newExtname | 131 | inputVideoFile.extname = newExtname |
114 | 132 | ||
115 | const videoOutputPath = video.getVideoFilePath(inputVideoFile) | 133 | const videoOutputPath = video.getVideoFilePath(inputVideoFile) |
134 | // ffmpeg generated a new video file, so update the video duration | ||
135 | // See https://trac.ffmpeg.org/ticket/5456 | ||
136 | video.duration = await getDurationFromVideoFile(videoTranscodedPath) | ||
137 | await video.save() | ||
116 | 138 | ||
117 | return onVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath) | 139 | return onVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath) |
118 | } | 140 | } |