1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-10 04:07:35 +02:00

Merge pull request #710 from GenericGuy/master

Matroska container header meta data parsing
This commit is contained in:
Patrik J. Braun 2023-09-03 18:58:28 +02:00 committed by GitHub
commit 1086bc13a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 3 deletions

View File

@ -79,6 +79,36 @@ export class MetadataLoader {
break;
}
}
// For some filetypes (for instance Matroska), bitrate and duration are stored in
// the format section, not in the stream section.
// Only use duration from container header if necessary (stream duration is usually more accurate)
if (
metadata.duration === 0 &&
data.format.duration !== undefined &&
Utils.isInt32(Math.floor(data.format.duration * 1000))
) {
metadata.duration = Math.floor(data.format.duration * 1000);
}
// Prefer bitrate from container header (includes video and audio)
if (
data.format.bit_rate !== undefined &&
Utils.isInt32(data.format.bit_rate)
) {
metadata.bitRate = data.format.bit_rate;
}
if (
data.format.tags !== undefined &&
typeof data.format.tags.creation_time === 'string'
) {
metadata.creationDate =
Date.parse(data.format.tags.creation_time) ||
metadata.creationDate;
}
// eslint-disable-next-line no-empty
} catch (err) {
}

View File

@ -1,5 +1,5 @@
{
"bitRate": 11464,
"bitRate": 146656,
"creationDate": 1550265200000,
"duration": 13666,
"fileSize": 251571,

View File

@ -0,0 +1,11 @@
{
"bitRate": 186114,
"creationDate": 1548316884000,
"duration": 13699,
"fileSize": 318697,
"fps": 15,
"size": {
"height": 44,
"width": 80
}
}

Binary file not shown.

View File

@ -1,5 +1,5 @@
{
"bitRate": 11464,
"bitRate": 142006,
"creationDate": 1550265200000,
"duration": 13666,
"fileSize": 242601,

View File

@ -23,7 +23,7 @@ describe('DiskMangerWorker', () => {
ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets');
const dir = await DiskMangerWorker.scanDirectory('/');
// should match the number of media (photo/video) files in the assets folder
expect(dir.media.length).to.be.equals(9);
expect(dir.media.length).to.be.equals(10);
const expected = require(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.json'));
const i = dir.media.findIndex(m => m.name === 'test image öüóőúéáű-.,.jpg');
expect(Utils.clone(dir.media[i].name)).to.be.deep.equal('test image öüóőúéáű-.,.jpg');

View File

@ -144,4 +144,10 @@ describe('MetadataLoader', () => {
expect(Utils.clone(data)).to.be.deep.equal(expected);
});
it('should load mkv', async () => {
const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video_mkv.mkv'));
const expected = require(path.join(__dirname, '/../../../assets/video_mkv.json'));
expect(Utils.clone(data)).to.be.deep.equal(expected);
});
});