transcode in STORAGE.TMP_DIR for s3fs compatibility (#147)
This commit is contained in:
parent
1600235a2f
commit
2fbd5e25dd
|
@ -16,11 +16,12 @@ import { CONFIG } from '../initializers/config'
|
||||||
*/
|
*/
|
||||||
async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) {
|
async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) {
|
||||||
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
|
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
|
||||||
|
const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
|
||||||
const newExtname = '.mp4'
|
const newExtname = '.mp4'
|
||||||
|
|
||||||
const inputVideoFile = inputVideoFileArg ? inputVideoFileArg : video.getOriginalFile()
|
const inputVideoFile = inputVideoFileArg ? inputVideoFileArg : video.getOriginalFile()
|
||||||
const videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile))
|
const videoInputPath = join(videosDirectory, video.getVideoFilename(inputVideoFile))
|
||||||
const videoTranscodedPath = join(videosDirectory, video.id + '-transcoded' + newExtname)
|
const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname)
|
||||||
|
|
||||||
const doQuickTranscode = await(canDoQuickTranscode(videoInputPath))
|
const doQuickTranscode = await(canDoQuickTranscode(videoInputPath))
|
||||||
|
|
||||||
|
@ -40,10 +41,11 @@ async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFi
|
||||||
// Important to do this before getVideoFilename() to take in account the new file extension
|
// Important to do this before getVideoFilename() to take in account the new file extension
|
||||||
inputVideoFile.set('extname', newExtname)
|
inputVideoFile.set('extname', newExtname)
|
||||||
|
|
||||||
|
const stats = await stat(videoTranscodedPath)
|
||||||
|
const fps = await getVideoFileFPS(videoTranscodedPath)
|
||||||
|
|
||||||
const videoOutputPath = video.getVideoFilePath(inputVideoFile)
|
const videoOutputPath = video.getVideoFilePath(inputVideoFile)
|
||||||
await move(videoTranscodedPath, videoOutputPath)
|
await move(videoTranscodedPath, videoOutputPath)
|
||||||
const stats = await stat(videoOutputPath)
|
|
||||||
const fps = await getVideoFileFPS(videoOutputPath)
|
|
||||||
|
|
||||||
inputVideoFile.set('size', stats.size)
|
inputVideoFile.set('size', stats.size)
|
||||||
inputVideoFile.set('fps', fps)
|
inputVideoFile.set('fps', fps)
|
||||||
|
@ -63,6 +65,7 @@ async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFi
|
||||||
*/
|
*/
|
||||||
async function transcodeOriginalVideofile (video: VideoModel, resolution: VideoResolution, isPortrait: boolean) {
|
async function transcodeOriginalVideofile (video: VideoModel, resolution: VideoResolution, isPortrait: boolean) {
|
||||||
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
|
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
|
||||||
|
const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
|
||||||
const extname = '.mp4'
|
const extname = '.mp4'
|
||||||
|
|
||||||
// We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed
|
// We are sure it's x264 in mp4 because optimizeOriginalVideofile was already executed
|
||||||
|
@ -75,18 +78,21 @@ async function transcodeOriginalVideofile (video: VideoModel, resolution: VideoR
|
||||||
videoId: video.id
|
videoId: video.id
|
||||||
})
|
})
|
||||||
const videoOutputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(newVideoFile))
|
const videoOutputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(newVideoFile))
|
||||||
|
const videoTranscodedPath = join(transcodeDirectory, video.getVideoFilename(newVideoFile))
|
||||||
|
|
||||||
const transcodeOptions = {
|
const transcodeOptions = {
|
||||||
inputPath: videoInputPath,
|
inputPath: videoInputPath,
|
||||||
outputPath: videoOutputPath,
|
outputPath: videoTranscodedPath,
|
||||||
resolution,
|
resolution,
|
||||||
isPortraitMode: isPortrait
|
isPortraitMode: isPortrait
|
||||||
}
|
}
|
||||||
|
|
||||||
await transcode(transcodeOptions)
|
await transcode(transcodeOptions)
|
||||||
|
|
||||||
const stats = await stat(videoOutputPath)
|
const stats = await stat(videoTranscodedPath)
|
||||||
const fps = await getVideoFileFPS(videoOutputPath)
|
const fps = await getVideoFileFPS(videoTranscodedPath)
|
||||||
|
|
||||||
|
await move(videoTranscodedPath, videoOutputPath)
|
||||||
|
|
||||||
newVideoFile.set('size', stats.size)
|
newVideoFile.set('size', stats.size)
|
||||||
newVideoFile.set('fps', fps)
|
newVideoFile.set('fps', fps)
|
||||||
|
|
Loading…
Reference in New Issue