From 482b26231b4e39234f107b8400ef606c5f003c55 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 23 Dec 2021 10:57:55 +0100 Subject: Fix audio only transcoding --- server/lib/job-queue/handlers/video-import.ts | 16 +++++++++++----- server/lib/transcoding/video-transcoding.ts | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'server/lib') diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index e5730e746..11ccd47ed 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts @@ -21,9 +21,9 @@ import { VideoImportYoutubeDLPayloadType, VideoState } from '../../../../shared' -import { VideoImportState } from '../../../../shared/models/videos' +import { VideoImportState, VideoResolution } from '../../../../shared/models/videos' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' -import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' +import { ffprobePromise, getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' import { logger } from '../../../helpers/logger' import { getSecureTorrentName } from '../../../helpers/utils' import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '../../../helpers/webtorrent' @@ -36,6 +36,7 @@ import { MThumbnail } from '../../../types/models/video/thumbnail' import { federateVideoIfNeeded } from '../../activitypub/videos' import { Notifier } from '../../notifier' import { generateVideoMiniature } from '../../thumbnail' +import { isAudioFile } from '@shared/extra-utils' async function processVideoImport (job: Job) { const payload = job.data as VideoImportPayload @@ -114,9 +115,14 @@ async function processFile (downloader: () => Promise, videoImport: MVid throw new Error('The user video quota is exceeded with this video to import.') } - const { resolution } = await getVideoFileResolution(tempVideoPath) - const fps = await getVideoFileFPS(tempVideoPath) - const duration = await getDurationFromVideoFile(tempVideoPath) + const probe = await ffprobePromise(tempVideoPath) + + const { resolution } = await isAudioFile(tempVideoPath, probe) + ? await getVideoFileResolution(tempVideoPath) + : { resolution: VideoResolution.H_NOVIDEO } + + const fps = await getVideoFileFPS(tempVideoPath, probe) + const duration = await getDurationFromVideoFile(tempVideoPath, probe) // Prepare video file object for creation in database const fileExt = getLowercaseExtension(tempVideoPath) diff --git a/server/lib/transcoding/video-transcoding.ts b/server/lib/transcoding/video-transcoding.ts index d0db05216..9942a067b 100644 --- a/server/lib/transcoding/video-transcoding.ts +++ b/server/lib/transcoding/video-transcoding.ts @@ -169,6 +169,7 @@ function mergeAudioVideofile (video: MVideoFullLight, resolution: VideoResolutio // Important to do this before getVideoFilename() to take in account the new file extension inputVideoFile.extname = newExtname + inputVideoFile.resolution = resolution inputVideoFile.filename = generateWebTorrentVideoFilename(inputVideoFile.resolution, newExtname) const videoOutputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, inputVideoFile) -- cgit v1.2.3