import { openapiOperationDoc } from '@server/middlewares/doc'
import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'
import { getLowercaseExtension, uuidToShort } from '@shared/core-utils'
+import { isAudioFile } from '@shared/extra-utils'
import { VideoCreate, VideoState } from '../../../../shared'
-import { HttpStatusCode } from '../../../../shared/models'
+import { HttpStatusCode, VideoResolution } from '../../../../shared/models'
import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { createReqFiles } from '../../../helpers/express-utils'
-import { getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
+import { ffprobePromise, getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
import { logger, loggerTagsFactory } from '../../../helpers/logger'
import { CONFIG } from '../../../initializers/config'
-import { DEFAULT_AUDIO_RESOLUTION, MIMETYPES } from '../../../initializers/constants'
+import { MIMETYPES } from '../../../initializers/constants'
import { sequelizeTypescript } from '../../../initializers/database'
import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
import { Notifier } from '../../../lib/notifier'
metadata: await getMetadataFromFile(videoPhysicalFile.path)
})
- if (videoFile.isAudio()) {
- videoFile.resolution = DEFAULT_AUDIO_RESOLUTION
+ const probe = await ffprobePromise(videoPhysicalFile.path)
+
+ if (await isAudioFile(videoPhysicalFile.path, probe)) {
+ videoFile.resolution = VideoResolution.H_NOVIDEO
} else {
- videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path)
- videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).resolution
+ videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path, probe)
+ videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path, probe)).resolution
}
videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname)
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'
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
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)
// 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)
import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage'
import { getFSTorrentFilePath } from '@server/lib/paths'
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models'
+import { VideoResolution, VideoStorage } from '@shared/models'
import { AttributesOnly } from '@shared/typescript-utils'
-import { VideoStorage } from '@shared/models'
import {
isVideoFileExtnameValid,
isVideoFileInfoHashValid,
LAZY_STATIC_PATHS,
MEMOIZE_LENGTH,
MEMOIZE_TTL,
- MIMETYPES,
STATIC_DOWNLOAD_PATHS,
STATIC_PATHS,
WEBSERVER
}
isAudio () {
- return !!MIMETYPES.AUDIO.EXT_MIMETYPE[this.extname]
+ return this.resolution === VideoResolution.H_NOVIDEO
}
isLive () {
})
}
+async function isAudioFile (path: string, existingProbe?: FfprobeData) {
+ const videoStream = await getVideoStreamFromFile(path, existingProbe)
+
+ return !videoStream
+}
+
async function getAudioStream (videoPath: string, existingProbe?: FfprobeData) {
// without position, ffprobe considers the last input only
// we make it consider the first input only
getDurationFromVideoFile,
getAudioStream,
getVideoFileFPS,
+ isAudioFile,
ffprobePromise,
getVideoFileBitrate,
canDoQuickAudioTranscode