mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-28 04:46:07 -08:00
perf(subsync): cache retried local embedded tracks across runs
- Add cacheEmbeddedSubtitleTrack to store non-empty individually extracted embedded tracks in the single-pass cache for local media - Picker no longer skips embedded extraction just because a combined pass ran, so omitted and zero-event tracks get retried and evaluated - Later auto-sync runs and picker opens reuse cached retries without spawning ffmpeg again
This commit is contained in:
4 files changed
+419
-4
No files matched your search
@@ -4,12 +4,15 @@ import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import {
|
||||
cacheEmbeddedSubtitleTrack,
|
||||
clearAudioSpeechCache,
|
||||
detectSpeechSpansFromPcm,
|
||||
extractAudioSpeechSpans,
|
||||
extractSinglePassRipMedia,
|
||||
getCachedAudioSpeechSpans,
|
||||
parseRawSileroVadSegments,
|
||||
} from './audio-speech';
|
||||
import { parseSubtitleFileContent } from './subtitle-lines';
|
||||
|
||||
test('detectSpeechSpansFromPcm detects voice-band bursts separated by quiet background', () => {
|
||||
const sampleRate = 8000;
|
||||
@@ -140,3 +143,35 @@ exit 0
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('cacheEmbeddedSubtitleTrack populates single-pass cache and ignores zero-event parses', async () => {
|
||||
clearAudioSpeechCache();
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-embedded-cache-'));
|
||||
try {
|
||||
const videoPath = path.join(tmpDir, 'episode.mkv');
|
||||
fs.writeFileSync(videoPath, 'video');
|
||||
|
||||
const validParsed = parseSubtitleFileContent(
|
||||
'1\n00:00:01,000 --> 00:00:02,500\nHello world\n',
|
||||
'track_3.srt',
|
||||
);
|
||||
const emptyParsed = parseSubtitleFileContent('', 'track_3.srt');
|
||||
|
||||
cacheEmbeddedSubtitleTrack(videoPath, 3, validParsed);
|
||||
cacheEmbeddedSubtitleTrack(videoPath, 3, emptyParsed);
|
||||
|
||||
const rip = await extractSinglePassRipMedia({
|
||||
ffmpegPath: '/nonexistent/ffmpeg',
|
||||
videoPath,
|
||||
audioStreamIndex: 1,
|
||||
embeddedTracks: [{ ffIndex: 3, extension: 'srt' }],
|
||||
includeAudio: false,
|
||||
});
|
||||
|
||||
assert.ok(rip !== null);
|
||||
assert.equal(rip.embeddedSubtitles.get(3)?.events.length, 1);
|
||||
} finally {
|
||||
clearAudioSpeechCache();
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -122,6 +122,20 @@ function rememberAudioSpeech(key: string | null, result: AudioSpeechResult): voi
|
||||
rememberLru(audioSpeechCache, key, result);
|
||||
}
|
||||
|
||||
export function cacheEmbeddedSubtitleTrack(
|
||||
videoPath: string,
|
||||
ffIndex: number,
|
||||
parsed: ParsedSubtitleFile,
|
||||
): void {
|
||||
if (parsed.events.length === 0) return;
|
||||
const fileKey = buildFileSignatureKey(videoPath);
|
||||
if (!fileKey) return;
|
||||
const existing = embeddedSubtitlesCache.get(fileKey);
|
||||
const updated = new Map<number, ParsedSubtitleFile>(existing);
|
||||
updated.set(ffIndex, parsed);
|
||||
rememberLru(embeddedSubtitlesCache, fileKey, updated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure-TypeScript voice-band speech activity detector operating on 16-bit mono
|
||||
* PCM (expected 8 kHz, voice band-passed 200 to 3400 Hz). Uses a global dynamic-range
|
||||
|
||||
Reference in new issue
Block a user