diff options
Diffstat (limited to 'server/lib/video-transcoding.ts')
-rw-r--r-- | server/lib/video-transcoding.ts | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index a58c9dd20..b366e2e44 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts | |||
@@ -2,7 +2,7 @@ import { Job } from 'bull' | |||
2 | import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' | 2 | import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' |
3 | import { basename, extname as extnameUtil, join } from 'path' | 3 | import { basename, extname as extnameUtil, join } from 'path' |
4 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | 4 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' |
5 | import { MStreamingPlaylistFilesVideo, MVideoFile, MVideoWithAllFiles, MVideoWithFile } from '@server/types/models' | 5 | import { MStreamingPlaylistFilesVideo, MVideoFile, MVideoFullLight } from '@server/types/models' |
6 | import { VideoResolution } from '../../shared/models/videos' | 6 | import { VideoResolution } from '../../shared/models/videos' |
7 | import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type' | 7 | import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type' |
8 | import { transcode, TranscodeOptions, TranscodeOptionsType } from '../helpers/ffmpeg-utils' | 8 | import { transcode, TranscodeOptions, TranscodeOptionsType } from '../helpers/ffmpeg-utils' |
@@ -13,7 +13,7 @@ import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSER | |||
13 | import { VideoFileModel } from '../models/video/video-file' | 13 | import { VideoFileModel } from '../models/video/video-file' |
14 | import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' | 14 | import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' |
15 | import { updateMasterHLSPlaylist, updateSha256VODSegments } from './hls' | 15 | import { updateMasterHLSPlaylist, updateSha256VODSegments } from './hls' |
16 | import { generateVideoStreamingPlaylistName, getVideoFilename, getVideoFilePath } from './video-paths' | 16 | import { generateVideoFilename, generateVideoStreamingPlaylistName, getVideoFilePath } from './video-paths' |
17 | import { VideoTranscodingProfilesManager } from './video-transcoding-profiles' | 17 | import { VideoTranscodingProfilesManager } from './video-transcoding-profiles' |
18 | 18 | ||
19 | /** | 19 | /** |
@@ -24,7 +24,7 @@ import { VideoTranscodingProfilesManager } from './video-transcoding-profiles' | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | // Optimize the original video file and replace it. The resolution is not changed. | 26 | // Optimize the original video file and replace it. The resolution is not changed. |
27 | async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFile: MVideoFile, job?: Job) { | 27 | async function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile: MVideoFile, job?: Job) { |
28 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR | 28 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR |
29 | const newExtname = '.mp4' | 29 | const newExtname = '.mp4' |
30 | 30 | ||
@@ -55,8 +55,9 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFile: | |||
55 | try { | 55 | try { |
56 | await remove(videoInputPath) | 56 | await remove(videoInputPath) |
57 | 57 | ||
58 | // Important to do this before getVideoFilename() to take in account the new file extension | 58 | // Important to do this before getVideoFilename() to take in account the new filename |
59 | inputVideoFile.extname = newExtname | 59 | inputVideoFile.extname = newExtname |
60 | inputVideoFile.filename = generateVideoFilename(video, false, inputVideoFile.resolution, newExtname) | ||
60 | 61 | ||
61 | const videoOutputPath = getVideoFilePath(video, inputVideoFile) | 62 | const videoOutputPath = getVideoFilePath(video, inputVideoFile) |
62 | 63 | ||
@@ -72,7 +73,7 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFile: | |||
72 | } | 73 | } |
73 | 74 | ||
74 | // Transcode the original video file to a lower resolution. | 75 | // Transcode the original video file to a lower resolution. |
75 | async function transcodeNewWebTorrentResolution (video: MVideoWithFile, resolution: VideoResolution, isPortrait: boolean, job: Job) { | 76 | async function transcodeNewWebTorrentResolution (video: MVideoFullLight, resolution: VideoResolution, isPortrait: boolean, job: Job) { |
76 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR | 77 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR |
77 | const extname = '.mp4' | 78 | const extname = '.mp4' |
78 | 79 | ||
@@ -82,11 +83,13 @@ async function transcodeNewWebTorrentResolution (video: MVideoWithFile, resoluti | |||
82 | const newVideoFile = new VideoFileModel({ | 83 | const newVideoFile = new VideoFileModel({ |
83 | resolution, | 84 | resolution, |
84 | extname, | 85 | extname, |
86 | filename: generateVideoFilename(video, false, resolution, extname), | ||
85 | size: 0, | 87 | size: 0, |
86 | videoId: video.id | 88 | videoId: video.id |
87 | }) | 89 | }) |
90 | |||
88 | const videoOutputPath = getVideoFilePath(video, newVideoFile) | 91 | const videoOutputPath = getVideoFilePath(video, newVideoFile) |
89 | const videoTranscodedPath = join(transcodeDirectory, getVideoFilename(video, newVideoFile)) | 92 | const videoTranscodedPath = join(transcodeDirectory, newVideoFile.filename) |
90 | 93 | ||
91 | const transcodeOptions = resolution === VideoResolution.H_NOVIDEO | 94 | const transcodeOptions = resolution === VideoResolution.H_NOVIDEO |
92 | ? { | 95 | ? { |
@@ -122,7 +125,7 @@ async function transcodeNewWebTorrentResolution (video: MVideoWithFile, resoluti | |||
122 | } | 125 | } |
123 | 126 | ||
124 | // Merge an image with an audio file to create a video | 127 | // Merge an image with an audio file to create a video |
125 | async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: VideoResolution, job: Job) { | 128 | async function mergeAudioVideofile (video: MVideoFullLight, resolution: VideoResolution, job: Job) { |
126 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR | 129 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR |
127 | const newExtname = '.mp4' | 130 | const newExtname = '.mp4' |
128 | 131 | ||
@@ -175,7 +178,7 @@ async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: Video | |||
175 | 178 | ||
176 | // Concat TS segments from a live video to a fragmented mp4 HLS playlist | 179 | // Concat TS segments from a live video to a fragmented mp4 HLS playlist |
177 | async function generateHlsPlaylistResolutionFromTS (options: { | 180 | async function generateHlsPlaylistResolutionFromTS (options: { |
178 | video: MVideoWithFile | 181 | video: MVideoFullLight |
179 | concatenatedTsFilePath: string | 182 | concatenatedTsFilePath: string |
180 | resolution: VideoResolution | 183 | resolution: VideoResolution |
181 | isPortraitMode: boolean | 184 | isPortraitMode: boolean |
@@ -193,7 +196,7 @@ async function generateHlsPlaylistResolutionFromTS (options: { | |||
193 | 196 | ||
194 | // Generate an HLS playlist from an input file, and update the master playlist | 197 | // Generate an HLS playlist from an input file, and update the master playlist |
195 | function generateHlsPlaylistResolution (options: { | 198 | function generateHlsPlaylistResolution (options: { |
196 | video: MVideoWithFile | 199 | video: MVideoFullLight |
197 | videoInputPath: string | 200 | videoInputPath: string |
198 | resolution: VideoResolution | 201 | resolution: VideoResolution |
199 | copyCodecs: boolean | 202 | copyCodecs: boolean |
@@ -235,7 +238,7 @@ export { | |||
235 | // --------------------------------------------------------------------------- | 238 | // --------------------------------------------------------------------------- |
236 | 239 | ||
237 | async function onWebTorrentVideoFileTranscoding ( | 240 | async function onWebTorrentVideoFileTranscoding ( |
238 | video: MVideoWithFile, | 241 | video: MVideoFullLight, |
239 | videoFile: MVideoFile, | 242 | videoFile: MVideoFile, |
240 | transcodingPath: string, | 243 | transcodingPath: string, |
241 | outputPath: string | 244 | outputPath: string |
@@ -250,7 +253,7 @@ async function onWebTorrentVideoFileTranscoding ( | |||
250 | videoFile.fps = fps | 253 | videoFile.fps = fps |
251 | videoFile.metadata = metadata | 254 | videoFile.metadata = metadata |
252 | 255 | ||
253 | await createTorrentAndSetInfoHash(video, videoFile) | 256 | await createTorrentAndSetInfoHash(video, video, videoFile) |
254 | 257 | ||
255 | await VideoFileModel.customUpsert(videoFile, 'video', undefined) | 258 | await VideoFileModel.customUpsert(videoFile, 'video', undefined) |
256 | video.VideoFiles = await video.$get('VideoFiles') | 259 | video.VideoFiles = await video.$get('VideoFiles') |
@@ -260,7 +263,7 @@ async function onWebTorrentVideoFileTranscoding ( | |||
260 | 263 | ||
261 | async function generateHlsPlaylistCommon (options: { | 264 | async function generateHlsPlaylistCommon (options: { |
262 | type: 'hls' | 'hls-from-ts' | 265 | type: 'hls' | 'hls-from-ts' |
263 | video: MVideoWithFile | 266 | video: MVideoFullLight |
264 | inputPath: string | 267 | inputPath: string |
265 | resolution: VideoResolution | 268 | resolution: VideoResolution |
266 | copyCodecs?: boolean | 269 | copyCodecs?: boolean |
@@ -318,10 +321,12 @@ async function generateHlsPlaylistCommon (options: { | |||
318 | videoStreamingPlaylist.Video = video | 321 | videoStreamingPlaylist.Video = video |
319 | 322 | ||
320 | // Build the new playlist file | 323 | // Build the new playlist file |
324 | const extname = extnameUtil(videoFilename) | ||
321 | const newVideoFile = new VideoFileModel({ | 325 | const newVideoFile = new VideoFileModel({ |
322 | resolution, | 326 | resolution, |
323 | extname: extnameUtil(videoFilename), | 327 | extname, |
324 | size: 0, | 328 | size: 0, |
329 | filename: generateVideoFilename(video, true, resolution, extname), | ||
325 | fps: -1, | 330 | fps: -1, |
326 | videoStreamingPlaylistId: videoStreamingPlaylist.id | 331 | videoStreamingPlaylistId: videoStreamingPlaylist.id |
327 | }) | 332 | }) |
@@ -344,7 +349,7 @@ async function generateHlsPlaylistCommon (options: { | |||
344 | newVideoFile.fps = await getVideoFileFPS(videoFilePath) | 349 | newVideoFile.fps = await getVideoFileFPS(videoFilePath) |
345 | newVideoFile.metadata = await getMetadataFromFile(videoFilePath) | 350 | newVideoFile.metadata = await getMetadataFromFile(videoFilePath) |
346 | 351 | ||
347 | await createTorrentAndSetInfoHash(videoStreamingPlaylist, newVideoFile) | 352 | await createTorrentAndSetInfoHash(videoStreamingPlaylist, video, newVideoFile) |
348 | 353 | ||
349 | await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined) | 354 | await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined) |
350 | videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles') | 355 | videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles') |