Fix audio only transcoding
This commit is contained in:
parent
c7c6afc66d
commit
482b26231b
|
@ -19,15 +19,16 @@ import { buildNextVideoState } from '@server/lib/video-state'
|
||||||
import { openapiOperationDoc } from '@server/middlewares/doc'
|
import { openapiOperationDoc } from '@server/middlewares/doc'
|
||||||
import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'
|
import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'
|
||||||
import { getLowercaseExtension, uuidToShort } from '@shared/core-utils'
|
import { getLowercaseExtension, uuidToShort } from '@shared/core-utils'
|
||||||
|
import { isAudioFile } from '@shared/extra-utils'
|
||||||
import { VideoCreate, VideoState } from '../../../../shared'
|
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 { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
|
||||||
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
||||||
import { createReqFiles } from '../../../helpers/express-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 { logger, loggerTagsFactory } from '../../../helpers/logger'
|
||||||
import { CONFIG } from '../../../initializers/config'
|
import { CONFIG } from '../../../initializers/config'
|
||||||
import { DEFAULT_AUDIO_RESOLUTION, MIMETYPES } from '../../../initializers/constants'
|
import { MIMETYPES } from '../../../initializers/constants'
|
||||||
import { sequelizeTypescript } from '../../../initializers/database'
|
import { sequelizeTypescript } from '../../../initializers/database'
|
||||||
import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
|
import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
|
||||||
import { Notifier } from '../../../lib/notifier'
|
import { Notifier } from '../../../lib/notifier'
|
||||||
|
@ -252,11 +253,13 @@ async function buildNewFile (videoPhysicalFile: express.VideoUploadFile) {
|
||||||
metadata: await getMetadataFromFile(videoPhysicalFile.path)
|
metadata: await getMetadataFromFile(videoPhysicalFile.path)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (videoFile.isAudio()) {
|
const probe = await ffprobePromise(videoPhysicalFile.path)
|
||||||
videoFile.resolution = DEFAULT_AUDIO_RESOLUTION
|
|
||||||
|
if (await isAudioFile(videoPhysicalFile.path, probe)) {
|
||||||
|
videoFile.resolution = VideoResolution.H_NOVIDEO
|
||||||
} else {
|
} else {
|
||||||
videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path)
|
videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path, probe)
|
||||||
videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).resolution
|
videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path, probe)).resolution
|
||||||
}
|
}
|
||||||
|
|
||||||
videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname)
|
videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname)
|
||||||
|
|
|
@ -21,9 +21,9 @@ import {
|
||||||
VideoImportYoutubeDLPayloadType,
|
VideoImportYoutubeDLPayloadType,
|
||||||
VideoState
|
VideoState
|
||||||
} from '../../../../shared'
|
} from '../../../../shared'
|
||||||
import { VideoImportState } from '../../../../shared/models/videos'
|
import { VideoImportState, VideoResolution } from '../../../../shared/models/videos'
|
||||||
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
|
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 { logger } from '../../../helpers/logger'
|
||||||
import { getSecureTorrentName } from '../../../helpers/utils'
|
import { getSecureTorrentName } from '../../../helpers/utils'
|
||||||
import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '../../../helpers/webtorrent'
|
import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '../../../helpers/webtorrent'
|
||||||
|
@ -36,6 +36,7 @@ import { MThumbnail } from '../../../types/models/video/thumbnail'
|
||||||
import { federateVideoIfNeeded } from '../../activitypub/videos'
|
import { federateVideoIfNeeded } from '../../activitypub/videos'
|
||||||
import { Notifier } from '../../notifier'
|
import { Notifier } from '../../notifier'
|
||||||
import { generateVideoMiniature } from '../../thumbnail'
|
import { generateVideoMiniature } from '../../thumbnail'
|
||||||
|
import { isAudioFile } from '@shared/extra-utils'
|
||||||
|
|
||||||
async function processVideoImport (job: Job) {
|
async function processVideoImport (job: Job) {
|
||||||
const payload = job.data as VideoImportPayload
|
const payload = job.data as VideoImportPayload
|
||||||
|
@ -114,9 +115,14 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
|
||||||
throw new Error('The user video quota is exceeded with this video to import.')
|
throw new Error('The user video quota is exceeded with this video to import.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const { resolution } = await getVideoFileResolution(tempVideoPath)
|
const probe = await ffprobePromise(tempVideoPath)
|
||||||
const fps = await getVideoFileFPS(tempVideoPath)
|
|
||||||
const duration = await getDurationFromVideoFile(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
|
// Prepare video file object for creation in database
|
||||||
const fileExt = getLowercaseExtension(tempVideoPath)
|
const fileExt = getLowercaseExtension(tempVideoPath)
|
||||||
|
|
|
@ -169,6 +169,7 @@ function mergeAudioVideofile (video: MVideoFullLight, resolution: VideoResolutio
|
||||||
|
|
||||||
// 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.extname = newExtname
|
inputVideoFile.extname = newExtname
|
||||||
|
inputVideoFile.resolution = resolution
|
||||||
inputVideoFile.filename = generateWebTorrentVideoFilename(inputVideoFile.resolution, newExtname)
|
inputVideoFile.filename = generateWebTorrentVideoFilename(inputVideoFile.resolution, newExtname)
|
||||||
|
|
||||||
const videoOutputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, inputVideoFile)
|
const videoOutputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, inputVideoFile)
|
||||||
|
|
|
@ -26,8 +26,8 @@ import { extractVideo } from '@server/helpers/video'
|
||||||
import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage'
|
import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage'
|
||||||
import { getFSTorrentFilePath } from '@server/lib/paths'
|
import { getFSTorrentFilePath } from '@server/lib/paths'
|
||||||
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models'
|
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models'
|
||||||
|
import { VideoResolution, VideoStorage } from '@shared/models'
|
||||||
import { AttributesOnly } from '@shared/typescript-utils'
|
import { AttributesOnly } from '@shared/typescript-utils'
|
||||||
import { VideoStorage } from '@shared/models'
|
|
||||||
import {
|
import {
|
||||||
isVideoFileExtnameValid,
|
isVideoFileExtnameValid,
|
||||||
isVideoFileInfoHashValid,
|
isVideoFileInfoHashValid,
|
||||||
|
@ -39,7 +39,6 @@ import {
|
||||||
LAZY_STATIC_PATHS,
|
LAZY_STATIC_PATHS,
|
||||||
MEMOIZE_LENGTH,
|
MEMOIZE_LENGTH,
|
||||||
MEMOIZE_TTL,
|
MEMOIZE_TTL,
|
||||||
MIMETYPES,
|
|
||||||
STATIC_DOWNLOAD_PATHS,
|
STATIC_DOWNLOAD_PATHS,
|
||||||
STATIC_PATHS,
|
STATIC_PATHS,
|
||||||
WEBSERVER
|
WEBSERVER
|
||||||
|
@ -448,7 +447,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
|
||||||
}
|
}
|
||||||
|
|
||||||
isAudio () {
|
isAudio () {
|
||||||
return !!MIMETYPES.AUDIO.EXT_MIMETYPE[this.extname]
|
return this.resolution === VideoResolution.H_NOVIDEO
|
||||||
}
|
}
|
||||||
|
|
||||||
isLive () {
|
isLive () {
|
||||||
|
|
|
@ -17,6 +17,12 @@ function ffprobePromise (path: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isAudioFile (path: string, existingProbe?: FfprobeData) {
|
||||||
|
const videoStream = await getVideoStreamFromFile(path, existingProbe)
|
||||||
|
|
||||||
|
return !videoStream
|
||||||
|
}
|
||||||
|
|
||||||
async function getAudioStream (videoPath: string, existingProbe?: FfprobeData) {
|
async function getAudioStream (videoPath: string, existingProbe?: FfprobeData) {
|
||||||
// without position, ffprobe considers the last input only
|
// without position, ffprobe considers the last input only
|
||||||
// we make it consider the first input only
|
// we make it consider the first input only
|
||||||
|
@ -174,6 +180,7 @@ export {
|
||||||
getDurationFromVideoFile,
|
getDurationFromVideoFile,
|
||||||
getAudioStream,
|
getAudioStream,
|
||||||
getVideoFileFPS,
|
getVideoFileFPS,
|
||||||
|
isAudioFile,
|
||||||
ffprobePromise,
|
ffprobePromise,
|
||||||
getVideoFileBitrate,
|
getVideoFileBitrate,
|
||||||
canDoQuickAudioTranscode
|
canDoQuickAudioTranscode
|
||||||
|
|
Loading…
Reference in New Issue
Block a user