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:
commit
1086bc13a5
src/backend/model/threading
test/backend
assets
unit/model/threading
@ -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) {
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"bitRate": 11464,
|
||||
"bitRate": 146656,
|
||||
"creationDate": 1550265200000,
|
||||
"duration": 13666,
|
||||
"fileSize": 251571,
|
||||
|
11
test/backend/assets/video_mkv.json
Normal file
11
test/backend/assets/video_mkv.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"bitRate": 186114,
|
||||
"creationDate": 1548316884000,
|
||||
"duration": 13699,
|
||||
"fileSize": 318697,
|
||||
"fps": 15,
|
||||
"size": {
|
||||
"height": 44,
|
||||
"width": 80
|
||||
}
|
||||
}
|
BIN
test/backend/assets/video_mkv.mkv
Normal file
BIN
test/backend/assets/video_mkv.mkv
Normal file
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
{
|
||||
"bitRate": 11464,
|
||||
"bitRate": 142006,
|
||||
"creationDate": 1550265200000,
|
||||
"duration": 13666,
|
||||
"fileSize": 242601,
|
||||
|
@ -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');
|
||||
|
@ -143,5 +143,11 @@ describe('MetadataLoader', () => {
|
||||
delete expected.duration;
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user