feat(api): fps tabanlı altyazı eşleştirmesi ekle
Video ve altyazı FPS değerlerini karşılaştırarak daha doğru eşleştirme yapar. Tam eşleşme ve token eşleşmesi bulunamadığında FPS uyumlu altyazıları önceliklendirir. FFprobe çıktısından FPS değerini normalize eder ve karşılaştırma için kullanır.
This commit is contained in:
@@ -3,6 +3,25 @@ import { promisify } from 'node:util';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
function parseFraction(raw?: string): number | null {
|
||||
if (!raw) return null;
|
||||
const parts = raw.split('/');
|
||||
if (parts.length === 2) {
|
||||
const n = Number(parts[0]);
|
||||
const d = Number(parts[1]);
|
||||
if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) return null;
|
||||
return n / d;
|
||||
}
|
||||
const v = Number(raw);
|
||||
return Number.isFinite(v) ? v : null;
|
||||
}
|
||||
|
||||
function normalizeFpsValue(raw?: string): number | null {
|
||||
const v = parseFraction(raw);
|
||||
if (v === null) return null;
|
||||
return Number(v.toFixed(3));
|
||||
}
|
||||
|
||||
export async function analyzeWithFfprobe(path: string): Promise<any> {
|
||||
const { stdout } = await execFileAsync('ffprobe', [
|
||||
'-v',
|
||||
@@ -25,7 +44,8 @@ export async function analyzeWithFfprobe(path: string): Promise<any> {
|
||||
codec_name: video.codec_name,
|
||||
width: video.width,
|
||||
height: video.height,
|
||||
r_frame_rate: video.r_frame_rate
|
||||
r_frame_rate: video.r_frame_rate,
|
||||
fps: normalizeFpsValue(video.avg_frame_rate || video.r_frame_rate)
|
||||
}
|
||||
: null,
|
||||
audio,
|
||||
@@ -39,7 +59,7 @@ export async function analyzeWithFfprobe(path: string): Promise<any> {
|
||||
|
||||
export function fallbackMediaInfo(): any {
|
||||
return {
|
||||
video: { codec_name: 'unknown', width: 1920, height: 1080, r_frame_rate: '24/1' },
|
||||
video: { codec_name: 'unknown', width: 1920, height: 1080, r_frame_rate: '24/1', fps: 24 },
|
||||
audio: [{ codec_name: 'unknown', channels: 2, language: 'und' }],
|
||||
format: { duration: '0', bit_rate: '0', format_name: 'matroska' }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user