More precise storyboard

Prefer to have unused black sprites at the end of the image instead of
missing sprites of the end of the video
This commit is contained in:
Chocobozzz 2024-09-11 14:29:51 +02:00
parent 78149322ee
commit be7bc3a6a9
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 4 additions and 22 deletions

View File

@ -941,7 +941,7 @@ export const ACTOR_IMAGES_SIZE: { [key in ActorImageType_Type]: { width: number,
export const STORYBOARD = {
SPRITE_MAX_SIZE: 192,
SPRITES_MAX_EDGE_COUNT: 10
SPRITES_MAX_EDGE_COUNT: 11
}
export const EMBED_SIZE = {

View File

@ -73,7 +73,7 @@ async function processGenerateStoryboard (job: Job): Promise<void> {
logger.debug(
'Generating storyboard from video of %s to %s', video.uuid, destination,
{ ...lTags, spritesCount, spriteDuration, videoDuration: video.duration, spriteHeight, spriteWidth }
{ ...lTags, totalSprites, spritesCount, spriteDuration, videoDuration: video.duration, spriteHeight, spriteWidth }
)
await ffmpeg.generateStoryboardFromVideo({
@ -148,7 +148,7 @@ function buildSpritesMetadata (options: {
// We can generate a single line so we don't need a prime number
if (totalSprites <= STORYBOARD.SPRITES_MAX_EDGE_COUNT) return { spriteDuration, totalSprites }
return { spriteDuration, totalSprites: findNearestGridPrime(totalSprites, STORYBOARD.SPRITES_MAX_EDGE_COUNT) }
return { spriteDuration, totalSprites }
}
function findGridSize (options: {
@ -159,27 +159,9 @@ function findGridSize (options: {
for (let i = 1; i <= maxEdgeCount; i++) {
for (let j = i; j <= maxEdgeCount; j++) {
if (toFind === i * j) return { width: j, height: i }
if (toFind <= i * j) return { width: j, height: i }
}
}
throw new Error(`Could not find grid size (to find: ${toFind}, max edge count: ${maxEdgeCount}`)
}
function findNearestGridPrime (value: number, maxMultiplier: number) {
for (let i = value; i--; i > 0) {
if (!isPrimeWithin(i, maxMultiplier)) return i
}
throw new Error('Could not find prime number below ' + value)
}
function isPrimeWithin (value: number, maxMultiplier: number) {
if (value < 2) return false
for (let i = 2, end = Math.min(Math.sqrt(value), maxMultiplier); i <= end; i++) {
if (value % i === 0 && value / i <= maxMultiplier) return false
}
return true
}