aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-transcoding.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-transcoding.ts')
-rw-r--r--server/lib/video-transcoding.ts49
1 files changed, 4 insertions, 45 deletions
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index e932c0e55..c29e34ab5 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -1,7 +1,7 @@
1import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY } from '../initializers' 1import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY } from '../initializers'
2import { extname, join } from 'path' 2import { join } from 'path'
3import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils' 3import { getVideoFileFPS, transcode } from '../helpers/ffmpeg-utils'
4import { copy, ensureDir, move, remove, stat } from 'fs-extra' 4import { ensureDir, move, remove, stat } from 'fs-extra'
5import { logger } from '../helpers/logger' 5import { logger } from '../helpers/logger'
6import { VideoResolution } from '../../shared/models/videos' 6import { VideoResolution } from '../../shared/models/videos'
7import { VideoFileModel } from '../models/video/video-file' 7import { VideoFileModel } from '../models/video/video-file'
@@ -123,49 +123,8 @@ async function generateHlsPlaylist (video: VideoModel, resolution: VideoResoluti
123 }) 123 })
124} 124}
125 125
126async function importVideoFile (video: VideoModel, inputFilePath: string) {
127 const { videoFileResolution } = await getVideoFileResolution(inputFilePath)
128 const { size } = await stat(inputFilePath)
129 const fps = await getVideoFileFPS(inputFilePath)
130
131 let updatedVideoFile = new VideoFileModel({
132 resolution: videoFileResolution,
133 extname: extname(inputFilePath),
134 size,
135 fps,
136 videoId: video.id
137 })
138
139 const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
140
141 if (currentVideoFile) {
142 // Remove old file and old torrent
143 await video.removeFile(currentVideoFile)
144 await video.removeTorrent(currentVideoFile)
145 // Remove the old video file from the array
146 video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
147
148 // Update the database
149 currentVideoFile.set('extname', updatedVideoFile.extname)
150 currentVideoFile.set('size', updatedVideoFile.size)
151 currentVideoFile.set('fps', updatedVideoFile.fps)
152
153 updatedVideoFile = currentVideoFile
154 }
155
156 const outputPath = video.getVideoFilePath(updatedVideoFile)
157 await copy(inputFilePath, outputPath)
158
159 await video.createTorrentAndSetInfoHash(updatedVideoFile)
160
161 await updatedVideoFile.save()
162
163 video.VideoFiles.push(updatedVideoFile)
164}
165
166export { 126export {
167 generateHlsPlaylist, 127 generateHlsPlaylist,
168 optimizeVideofile, 128 optimizeVideofile,
169 transcodeOriginalVideofile, 129 transcodeOriginalVideofile
170 importVideoFile
171} 130}