earlier duration check

This commit is contained in:
mertalev 2026-04-22 16:03:39 -04:00
parent 1b414b341c
commit 164f0aa331
No known key found for this signature in database
GPG Key ID: 0603AE056AA39037
2 changed files with 19 additions and 13 deletions

View File

@ -315,7 +315,11 @@ export class MediaRepository {
streamIndex: number,
timeBase: number,
formatDuration: number,
): Promise<VideoPacketInfo> {
): Promise<VideoPacketInfo | null> {
if (formatDuration <= 0) {
return null;
}
const { stdout } = await execFile('ffprobe', [
'-v',
'error',
@ -356,18 +360,20 @@ export class MediaRepository {
}
}
if (packetCount === 0) {
return null;
}
postDiscard.sort((a, b) => a.pts - b.pts);
const firstPts = postDiscard[0].pts;
const slotsPerTick = packetCount / formatDuration / timeBase;
let outputFrames = 0;
if (packetCount > 0 && formatDuration > 0) {
postDiscard.sort((a, b) => a.pts - b.pts);
const firstPts = postDiscard[0].pts;
const slotsPerTick = packetCount / formatDuration / timeBase;
let nextPts = 0;
for (const pkt of postDiscard) {
const delta = (pkt.pts - firstPts) * slotsPerTick - nextPts + pkt.duration * slotsPerTick;
const nb = delta < -1.1 ? 0 : delta > 1.1 ? Math.round(delta) : 1;
outputFrames += nb;
nextPts += nb;
}
let nextPts = 0;
for (const pkt of postDiscard) {
const delta = (pkt.pts - firstPts) * slotsPerTick - nextPts + pkt.duration * slotsPerTick;
const nb = delta < -1.1 ? 0 : delta > 1.1 ? Math.round(delta) : 1;
outputFrames += nb;
nextPts += nb;
}
return {

View File

@ -1086,7 +1086,7 @@ export class MetadataService extends BaseService {
const packets =
video && video.timeBase
? await this.mediaRepository.probePackets(originalPath, video.index, video.timeBase, format.duration)
: undefined;
: null;
const tags: Pick<ImmichTags, 'Duration' | 'Orientation' | 'ImageWidth' | 'ImageHeight'> = {};