diff --git a/src/backend/model/threading/MetadataLoader.ts b/src/backend/model/threading/MetadataLoader.ts index 7fc48770..22b42f63 100644 --- a/src/backend/model/threading/MetadataLoader.ts +++ b/src/backend/model/threading/MetadataLoader.ts @@ -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) { } diff --git a/test/backend/assets/video.json b/test/backend/assets/video.json index 6fac57f1..8fa866c0 100644 --- a/test/backend/assets/video.json +++ b/test/backend/assets/video.json @@ -1,5 +1,5 @@ { - "bitRate": 11464, + "bitRate": 146656, "creationDate": 1550265200000, "duration": 13666, "fileSize": 251571, diff --git a/test/backend/assets/video_mkv.json b/test/backend/assets/video_mkv.json new file mode 100644 index 00000000..dfbceb9c --- /dev/null +++ b/test/backend/assets/video_mkv.json @@ -0,0 +1,11 @@ +{ + "bitRate": 186114, + "creationDate": 1548316884000, + "duration": 13699, + "fileSize": 318697, + "fps": 15, + "size": { + "height": 44, + "width": 80 + } +} diff --git a/test/backend/assets/video_mkv.mkv b/test/backend/assets/video_mkv.mkv new file mode 100644 index 00000000..f6ec1427 Binary files /dev/null and b/test/backend/assets/video_mkv.mkv differ diff --git a/test/backend/assets/video_rotate.json b/test/backend/assets/video_rotate.json index e72fac1b..47f6c445 100644 --- a/test/backend/assets/video_rotate.json +++ b/test/backend/assets/video_rotate.json @@ -1,5 +1,5 @@ { - "bitRate": 11464, + "bitRate": 142006, "creationDate": 1550265200000, "duration": 13666, "fileSize": 242601, diff --git a/test/backend/unit/model/threading/DiskManagerWorker.spec.ts b/test/backend/unit/model/threading/DiskManagerWorker.spec.ts index cf4387a4..513a3c09 100644 --- a/test/backend/unit/model/threading/DiskManagerWorker.spec.ts +++ b/test/backend/unit/model/threading/DiskManagerWorker.spec.ts @@ -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'); diff --git a/test/backend/unit/model/threading/MetaDataLoader.spec.ts b/test/backend/unit/model/threading/MetaDataLoader.spec.ts index 0b475873..22488475 100644 --- a/test/backend/unit/model/threading/MetaDataLoader.spec.ts +++ b/test/backend/unit/model/threading/MetaDataLoader.spec.ts @@ -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); + }); });