From 62f8bd80f437f0564b76e953b829ff102a4fba8b Mon Sep 17 00:00:00 2001 From: Mert <101130780+mertalev@users.noreply.github.com> Date: Sat, 8 Jun 2024 05:55:05 -0400 Subject: [PATCH] fix(server): add fallback for video thumbnail generation (#10034) they called me a madman --- server/src/services/media.service.spec.ts | 6 +++--- server/src/utils/media.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/server/src/services/media.service.spec.ts b/server/src/services/media.service.spec.ts index 1b935b19b7..ef08f059a3 100644 --- a/server/src/services/media.service.spec.ts +++ b/server/src/services/media.service.spec.ts @@ -300,7 +300,7 @@ describe(MediaService.name, () => { '-frames:v 1', '-update 1', '-v verbose', - `-vf fps=12,thumbnail=12,select=gt(scene\\,0.1)+gt(n\\,20),scale=-2:1440:flags=lanczos+accurate_rnd+full_chroma_int:out_color_matrix=601:out_range=pc,format=gbrpf32le`, + String.raw`-vf fps=12:round=up,thumbnail=12,select=gt(scene\,0.1)-eq(prev_selected_n\,n)+isnan(prev_selected_n)+gt(n\,20),trim=end_frame=2,reverse,scale=-2:1440:flags=lanczos+accurate_rnd+full_chroma_int:out_color_matrix=601:out_range=pc,format=yuv420p`, ], twoPass: false, }, @@ -327,7 +327,7 @@ describe(MediaService.name, () => { '-frames:v 1', '-update 1', '-v verbose', - `-vf fps=12,thumbnail=12,select=gt(scene\\,0.1)+gt(n\\,20),zscale=t=linear:npl=100,tonemap=hable:desat=0,zscale=p=bt709:t=601:m=bt470bg:range=pc,format=gbrpf32le`, + String.raw`-vf fps=12:round=up,thumbnail=12,select=gt(scene\,0.1)-eq(prev_selected_n\,n)+isnan(prev_selected_n)+gt(n\,20),trim=end_frame=2,reverse,zscale=t=linear:npl=100,tonemap=hable:desat=0,zscale=p=bt709:t=601:m=bt470bg:range=pc,format=yuv420p`, ], twoPass: false, }, @@ -356,7 +356,7 @@ describe(MediaService.name, () => { '-frames:v 1', '-update 1', '-v verbose', - `-vf fps=12,thumbnail=12,select=gt(scene\\,0.1)+gt(n\\,20),zscale=t=linear:npl=100,tonemap=hable:desat=0,zscale=p=bt709:t=601:m=bt470bg:range=pc,format=gbrpf32le`, + String.raw`-vf fps=12:round=up,thumbnail=12,select=gt(scene\,0.1)-eq(prev_selected_n\,n)+isnan(prev_selected_n)+gt(n\,20),trim=end_frame=2,reverse,zscale=t=linear:npl=100,tonemap=hable:desat=0,zscale=p=bt709:t=601:m=bt470bg:range=pc,format=yuv420p`, ], twoPass: false, }, diff --git a/server/src/utils/media.ts b/server/src/utils/media.ts index cbbb754611..ea8994d934 100644 --- a/server/src/utils/media.ts +++ b/server/src/utils/media.ts @@ -392,12 +392,18 @@ export class ThumbnailConfig extends BaseConfig { } getFilterOptions(videoStream: VideoStreamInfo): string[] { - const options = ['fps=12', 'thumbnail=12', `select=gt(scene\\,0.1)+gt(n\\,20)`]; + const options = [ + 'fps=12:round=up', + 'thumbnail=12', + String.raw`select=gt(scene\,0.1)-eq(prev_selected_n\,n)+isnan(prev_selected_n)+gt(n\,20)`, + 'trim=end_frame=2', + 'reverse', + ]; if (this.shouldScale(videoStream)) { options.push(`scale=${this.getScaling(videoStream)}`); } - options.push(...this.getToneMapping(videoStream), 'format=gbrpf32le'); + options.push(...this.getToneMapping(videoStream), 'format=yuv420p'); return options; }