aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-23 10:57:55 +0100
committerChocobozzz <me@florianbigard.com>2021-12-23 10:57:55 +0100
commit482b26231b4e39234f107b8400ef606c5f003c55 (patch)
tree1a50f292b77b9b297f0885867da9f20c02582706 /server
parentc7c6afc66d7611d4c02572d63801beca26c45204 (diff)
downloadPeerTube-482b26231b4e39234f107b8400ef606c5f003c55.tar.gz
PeerTube-482b26231b4e39234f107b8400ef606c5f003c55.tar.zst
PeerTube-482b26231b4e39234f107b8400ef606c5f003c55.zip
Fix audio only transcoding
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/upload.ts17
-rw-r--r--server/lib/job-queue/handlers/video-import.ts16
-rw-r--r--server/lib/transcoding/video-transcoding.ts1
-rw-r--r--server/models/video/video-file.ts5
4 files changed, 24 insertions, 15 deletions
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts
index 9f620c04d..ecc4dfa37 100644
--- a/server/controllers/api/videos/upload.ts
+++ b/server/controllers/api/videos/upload.ts
@@ -19,15 +19,16 @@ import { buildNextVideoState } from '@server/lib/video-state'
19import { openapiOperationDoc } from '@server/middlewares/doc' 19import { openapiOperationDoc } from '@server/middlewares/doc'
20import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' 20import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'
21import { getLowercaseExtension, uuidToShort } from '@shared/core-utils' 21import { getLowercaseExtension, uuidToShort } from '@shared/core-utils'
22import { isAudioFile } from '@shared/extra-utils'
22import { VideoCreate, VideoState } from '../../../../shared' 23import { VideoCreate, VideoState } from '../../../../shared'
23import { HttpStatusCode } from '../../../../shared/models' 24import { HttpStatusCode, VideoResolution } from '../../../../shared/models'
24import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' 25import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
25import { retryTransactionWrapper } from '../../../helpers/database-utils' 26import { retryTransactionWrapper } from '../../../helpers/database-utils'
26import { createReqFiles } from '../../../helpers/express-utils' 27import { createReqFiles } from '../../../helpers/express-utils'
27import { getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' 28import { ffprobePromise, getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
28import { logger, loggerTagsFactory } from '../../../helpers/logger' 29import { logger, loggerTagsFactory } from '../../../helpers/logger'
29import { CONFIG } from '../../../initializers/config' 30import { CONFIG } from '../../../initializers/config'
30import { DEFAULT_AUDIO_RESOLUTION, MIMETYPES } from '../../../initializers/constants' 31import { MIMETYPES } from '../../../initializers/constants'
31import { sequelizeTypescript } from '../../../initializers/database' 32import { sequelizeTypescript } from '../../../initializers/database'
32import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' 33import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
33import { Notifier } from '../../../lib/notifier' 34import { Notifier } from '../../../lib/notifier'
@@ -252,11 +253,13 @@ async function buildNewFile (videoPhysicalFile: express.VideoUploadFile) {
252 metadata: await getMetadataFromFile(videoPhysicalFile.path) 253 metadata: await getMetadataFromFile(videoPhysicalFile.path)
253 }) 254 })
254 255
255 if (videoFile.isAudio()) { 256 const probe = await ffprobePromise(videoPhysicalFile.path)
256 videoFile.resolution = DEFAULT_AUDIO_RESOLUTION 257
258 if (await isAudioFile(videoPhysicalFile.path, probe)) {
259 videoFile.resolution = VideoResolution.H_NOVIDEO
257 } else { 260 } else {
258 videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path) 261 videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path, probe)
259 videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).resolution 262 videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path, probe)).resolution
260 } 263 }
261 264
262 videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname) 265 videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname)
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 {
21 VideoImportYoutubeDLPayloadType, 21 VideoImportYoutubeDLPayloadType,
22 VideoState 22 VideoState
23} from '../../../../shared' 23} from '../../../../shared'
24import { VideoImportState } from '../../../../shared/models/videos' 24import { VideoImportState, VideoResolution } from '../../../../shared/models/videos'
25import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 25import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
26import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' 26import { ffprobePromise, getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
27import { logger } from '../../../helpers/logger' 27import { logger } from '../../../helpers/logger'
28import { getSecureTorrentName } from '../../../helpers/utils' 28import { getSecureTorrentName } from '../../../helpers/utils'
29import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '../../../helpers/webtorrent' 29import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '../../../helpers/webtorrent'
@@ -36,6 +36,7 @@ import { MThumbnail } from '../../../types/models/video/thumbnail'
36import { federateVideoIfNeeded } from '../../activitypub/videos' 36import { federateVideoIfNeeded } from '../../activitypub/videos'
37import { Notifier } from '../../notifier' 37import { Notifier } from '../../notifier'
38import { generateVideoMiniature } from '../../thumbnail' 38import { generateVideoMiniature } from '../../thumbnail'
39import { isAudioFile } from '@shared/extra-utils'
39 40
40async function processVideoImport (job: Job) { 41async function processVideoImport (job: Job) {
41 const payload = job.data as VideoImportPayload 42 const payload = job.data as VideoImportPayload
@@ -114,9 +115,14 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
114 throw new Error('The user video quota is exceeded with this video to import.') 115 throw new Error('The user video quota is exceeded with this video to import.')
115 } 116 }
116 117
117 const { resolution } = await getVideoFileResolution(tempVideoPath) 118 const probe = await ffprobePromise(tempVideoPath)
118 const fps = await getVideoFileFPS(tempVideoPath) 119
119 const duration = await getDurationFromVideoFile(tempVideoPath) 120 const { resolution } = await isAudioFile(tempVideoPath, probe)
121 ? await getVideoFileResolution(tempVideoPath)
122 : { resolution: VideoResolution.H_NOVIDEO }
123
124 const fps = await getVideoFileFPS(tempVideoPath, probe)
125 const duration = await getDurationFromVideoFile(tempVideoPath, probe)
120 126
121 // Prepare video file object for creation in database 127 // Prepare video file object for creation in database
122 const fileExt = getLowercaseExtension(tempVideoPath) 128 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
169 169
170 // Important to do this before getVideoFilename() to take in account the new file extension 170 // Important to do this before getVideoFilename() to take in account the new file extension
171 inputVideoFile.extname = newExtname 171 inputVideoFile.extname = newExtname
172 inputVideoFile.resolution = resolution
172 inputVideoFile.filename = generateWebTorrentVideoFilename(inputVideoFile.resolution, newExtname) 173 inputVideoFile.filename = generateWebTorrentVideoFilename(inputVideoFile.resolution, newExtname)
173 174
174 const videoOutputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, inputVideoFile) 175 const videoOutputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, inputVideoFile)
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index 2b5ec3a20..6f03fae3a 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -26,8 +26,8 @@ import { extractVideo } from '@server/helpers/video'
26import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage' 26import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage'
27import { getFSTorrentFilePath } from '@server/lib/paths' 27import { getFSTorrentFilePath } from '@server/lib/paths'
28import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models' 28import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models'
29import { VideoResolution, VideoStorage } from '@shared/models'
29import { AttributesOnly } from '@shared/typescript-utils' 30import { AttributesOnly } from '@shared/typescript-utils'
30import { VideoStorage } from '@shared/models'
31import { 31import {
32 isVideoFileExtnameValid, 32 isVideoFileExtnameValid,
33 isVideoFileInfoHashValid, 33 isVideoFileInfoHashValid,
@@ -39,7 +39,6 @@ import {
39 LAZY_STATIC_PATHS, 39 LAZY_STATIC_PATHS,
40 MEMOIZE_LENGTH, 40 MEMOIZE_LENGTH,
41 MEMOIZE_TTL, 41 MEMOIZE_TTL,
42 MIMETYPES,
43 STATIC_DOWNLOAD_PATHS, 42 STATIC_DOWNLOAD_PATHS,
44 STATIC_PATHS, 43 STATIC_PATHS,
45 WEBSERVER 44 WEBSERVER
@@ -448,7 +447,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
448 } 447 }
449 448
450 isAudio () { 449 isAudio () {
451 return !!MIMETYPES.AUDIO.EXT_MIMETYPE[this.extname] 450 return this.resolution === VideoResolution.H_NOVIDEO
452 } 451 }
453 452
454 isLive () { 453 isLive () {