- newVideoFile.set('size', stats.size)
- newVideoFile.set('fps', fps)
+ const audioInputPath = join(videosDirectory, video.getVideoFilename(video.getOriginalFile()))
+ const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname)
+
+ // If the user updates the video preview during transcoding
+ const previewPath = video.getPreview().getPath()
+ const tmpPreviewPath = join(CONFIG.STORAGE.TMP_DIR, basename(previewPath))
+ await copyFile(previewPath, tmpPreviewPath)
+
+ const transcodeOptions = {
+ type: 'merge-audio' as 'merge-audio',
+ inputPath: tmpPreviewPath,
+ outputPath: videoTranscodedPath,
+ audioPath: audioInputPath,
+ resolution
+ }
+
+ try {
+ await transcode(transcodeOptions)
+
+ await remove(audioInputPath)
+ await remove(tmpPreviewPath)
+ } catch (err) {
+ await remove(tmpPreviewPath)
+ throw err
+ }