Skip to content

Commit

Permalink
Fix upload with chapters having non int timecode
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Oct 12, 2023
1 parent ed0852f commit 58fda6d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
14 changes: 10 additions & 4 deletions packages/ffmpeg/src/ffprobe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,21 @@ async function getVideoStream (path: string, existingProbe?: FfprobeData) {
// Chapters
// ---------------------------------------------------------------------------

async function getChaptersFromContainer (path: string, existingProbe?: FfprobeData) {
const metadata = existingProbe || await ffprobePromise(path)
async function getChaptersFromContainer (options: {
path: string
maxTitleLength: number
ffprobe?: FfprobeData
}) {
const { path, maxTitleLength, ffprobe } = options

const metadata = ffprobe || await ffprobePromise(path)

if (!Array.isArray(metadata?.chapters)) return []

return metadata.chapters
.map(c => ({
timecode: c.start_time,
title: c['TAG:title']
timecode: Math.round(c.start_time),
title: (c['TAG:title'] || '').slice(0, maxTitleLength)
}))
}

Expand Down
7 changes: 5 additions & 2 deletions server/core/controllers/api/videos/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { HttpStatusCode, VideoCreate, VideoPrivacy, VideoState } from '@peertube
import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger.js'
import { createReqFiles } from '../../../helpers/express-utils.js'
import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
import { MIMETYPES } from '../../../initializers/constants.js'
import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { Hooks } from '../../../lib/plugins/hooks.js'
import { generateLocalVideoMiniature } from '../../../lib/thumbnail.js'
Expand Down Expand Up @@ -145,7 +145,10 @@ async function addVideo (options: {
const videoFile = await buildNewFile({ path: videoPhysicalFile.path, mode: 'web-video' })
const originalFilename = videoPhysicalFile.originalname

const containerChapters = await getChaptersFromContainer(videoPhysicalFile.path)
const containerChapters = await getChaptersFromContainer({
path: videoPhysicalFile.path,
maxTitleLength: CONSTRAINTS_FIELDS.VIDEO_CHAPTERS.TITLE.max
})
logger.debug(`Got ${containerChapters.length} chapters from video "${video.name}" container`, { containerChapters, ...lTags(video.uuid) })

// Move physical file
Expand Down
18 changes: 11 additions & 7 deletions server/core/lib/job-queue/handlers/video-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
import { logger } from '../../../helpers/logger.js'
import { getSecureTorrentName } from '../../../helpers/utils.js'
import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '../../../helpers/webtorrent.js'
import { JOB_TTL } from '../../../initializers/constants.js'
import { CONSTRAINTS_FIELDS, JOB_TTL } from '../../../initializers/constants.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { VideoFileModel } from '../../../models/video/video-file.js'
import { VideoImportModel } from '../../../models/video/video-import.js'
Expand Down Expand Up @@ -143,16 +143,20 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
throw new Error('The user video quota is exceeded with this video to import.')
}

const probe = await ffprobePromise(tempVideoPath)
const ffprobe = await ffprobePromise(tempVideoPath)

const { resolution } = await isAudioFile(tempVideoPath, probe)
const { resolution } = await isAudioFile(tempVideoPath, ffprobe)
? { resolution: VideoResolution.H_NOVIDEO }
: await getVideoStreamDimensionsInfo(tempVideoPath, probe)
: await getVideoStreamDimensionsInfo(tempVideoPath, ffprobe)

const fps = await getVideoStreamFPS(tempVideoPath, probe)
const duration = await getVideoStreamDuration(tempVideoPath, probe)
const fps = await getVideoStreamFPS(tempVideoPath, ffprobe)
const duration = await getVideoStreamDuration(tempVideoPath, ffprobe)

const containerChapters = await getChaptersFromContainer(tempVideoPath, probe)
const containerChapters = await getChaptersFromContainer({
path: tempVideoPath,
maxTitleLength: CONSTRAINTS_FIELDS.VIDEO_CHAPTERS.TITLE.max,
ffprobe
})

// Prepare video file object for creation in database
const fileExt = getLowercaseExtension(tempVideoPath)
Expand Down

0 comments on commit 58fda6d

Please sign in to comment.