Can we use mp4box to read mp4 metadata and get resolution #601

Closed
opened 2025-12-23 09:56:17 +00:00 by GLlgGL · 4 comments
GLlgGL commented 2025-12-23 09:56:17 +00:00 (Migrated from github.com)

Hi

Can we use smth like this to read mp4 metadata and get the resolution(streamtape for example or others)
https://github.com/gpac/gpac/wiki/mp4box

If not can't be done why not guess by filesize?

Something like

`function estimateHeightFromSize(bytes: number): number | undefined {
const gb = bytes / 1024 ** 3;

// Heuristic thresholds for ~90–120 min movies
if (gb >= 1.7) return 1080;
if (gb >= 1.1) return 720;
if (gb >= 0.6) return 480;
return undefined;
}
`

Hi Can we use smth like this to read mp4 metadata and get the resolution(streamtape for example or others) https://github.com/gpac/gpac/wiki/mp4box If not can't be done why not guess by filesize? Something like `function estimateHeightFromSize(bytes: number): number | undefined { const gb = bytes / 1024 ** 3; // Heuristic thresholds for ~90–120 min movies if (gb >= 1.7) return 1080; if (gb >= 1.1) return 720; if (gb >= 0.6) return 480; return undefined; } `
webstreamr commented 2025-12-23 10:41:35 +00:00 (Migrated from github.com)

it would work with ffmpg directly and I thought about that too, but it's not really doable. I can't download the full mp4 obviously and to do that we would need to download at least 10-20MB which is also not something I can do IMO, it will cause webstreamr to grind to a halt most likely. I think I can't do this.

it would work with ffmpg directly and I thought about that too, but it's not really doable. I can't download the full mp4 obviously and to do that we would need to download at least 10-20MB which is also not something I can do IMO, it will cause webstreamr to grind to a halt most likely. I think I can't do this.
GLlgGL commented 2025-12-23 11:54:48 +00:00 (Migrated from github.com)

why not do this

function estimateHeightFromSize(bytesSize: number): number | undefined {
const gb = bytesSize / 1024 ** 3;

if (gb >= 1.7) return 1080;
if (gb >= 1.1) return 720;
if (gb >= 0.6) return 480;
return undefined;
}

why not do this function estimateHeightFromSize(bytesSize: number): number | undefined { const gb = bytesSize / 1024 ** 3; if (gb >= 1.7) return 1080; if (gb >= 1.1) return 720; if (gb >= 0.6) return 480; return undefined; }
webstreamr commented 2025-12-23 12:46:42 +00:00 (Migrated from github.com)

I don't think this is reliable, normally more factors like e.g. bitrate, duration and compression are needed. maybe some can be estimated or assumed, but not sure. e.g. how to make that work somewhat reliable for both a 20m show episode and a 2h movie?

but I'm open for ideas and suggestions here, didn't spend too much time with it.

I don't think this is reliable, normally more factors like e.g. bitrate, duration and compression are needed. maybe some can be estimated or assumed, but not sure. e.g. how to make that work somewhat reliable for both a 20m show episode and a 2h movie? but I'm open for ideas and suggestions here, didn't spend too much time with it.
GLlgGL commented 2025-12-23 13:18:00 +00:00 (Migrated from github.com)

Look we can estimate the duration too...I think is better have this(estimated accuracy for around 70-80%) than nothing at all...

function estimateHeightFromSize(
bytesSize: number,
contentType?: 'movie' | 'series'
): number | undefined {
const gb = bytesSize / 1024 ** 3;

const isEpisode = contentType === 'series';

if (!isEpisode) {
// movie (~100–120 min)
if (gb >= 1.7) return 1080;
if (gb >= 1.1) return 720;
if (gb >= 0.6) return 480;
} else {
// episode (~40–60 min)
if (gb >= 0.85) return 1080;
if (gb >= 0.45) return 720;
if (gb >= 0.25) return 480;
}

return undefined;
}

Look we can estimate the duration too...I think is better have this(estimated accuracy for around 70-80%) than nothing at all... function estimateHeightFromSize( bytesSize: number, contentType?: 'movie' | 'series' ): number | undefined { const gb = bytesSize / 1024 ** 3; const isEpisode = contentType === 'series'; if (!isEpisode) { // movie (~100–120 min) if (gb >= 1.7) return 1080; if (gb >= 1.1) return 720; if (gb >= 0.6) return 480; } else { // episode (~40–60 min) if (gb >= 0.85) return 1080; if (gb >= 0.45) return 720; if (gb >= 0.25) return 480; } return undefined; }
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Creepso/webstreamr-github#601
No description provided.