diff --git a/src/backend/model/threading/MetadataLoader.ts b/src/backend/model/threading/MetadataLoader.ts index e95b734a..d8168125 100644 --- a/src/backend/model/threading/MetadataLoader.ts +++ b/src/backend/model/threading/MetadataLoader.ts @@ -50,6 +50,12 @@ export class MetadataLoader { metadata.size.width = data.streams[i].width; metadata.size.height = data.streams[i].height; + if (Utils.isInt32(parseInt(data.streams[i].rotation, 10)) && + (Math.abs(parseInt(data.streams[i].rotation, 10)) / 90) % 2 === 1) { + metadata.size.width = data.streams[i].height; + metadata.size.height = data.streams[i].width; + } + if (Utils.isInt32(Math.floor(parseFloat(data.streams[i].duration) * 1000))) { metadata.duration = Math.floor(parseFloat(data.streams[i].duration) * 1000); } diff --git a/test/backend/assets/video_rotate.json b/test/backend/assets/video_rotate.json new file mode 100644 index 00000000..e72fac1b --- /dev/null +++ b/test/backend/assets/video_rotate.json @@ -0,0 +1,11 @@ +{ + "bitRate": 11464, + "creationDate": 1550265200000, + "duration": 13666, + "fileSize": 242601, + "fps": 15, + "size": { + "height": 80, + "width": 60 + } +} diff --git a/test/backend/assets/video_rotate.mp4 b/test/backend/assets/video_rotate.mp4 new file mode 100644 index 00000000..42ade182 Binary files /dev/null and b/test/backend/assets/video_rotate.mp4 differ diff --git a/test/backend/unit/model/threading/DiskMangerWorker.spec.ts b/test/backend/unit/model/threading/DiskMangerWorker.spec.ts index cc245dc5..fa060a7c 100644 --- a/test/backend/unit/model/threading/DiskMangerWorker.spec.ts +++ b/test/backend/unit/model/threading/DiskMangerWorker.spec.ts @@ -11,7 +11,7 @@ describe('DiskMangerWorker', () => { Config.Server.Media.folder = path.join(__dirname, '/../../../assets'); ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets'); const dir = await DiskMangerWorker.scanDirectory('/'); - expect(dir.media.length).to.be.equals(5); + expect(dir.media.length).to.be.equals(6); const expected = require(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.json')); expect(Utils.clone(dir.media[2].name)).to.be.deep.equal('test image öüóőúéáű-.,.jpg'); expect(Utils.clone(dir.media[2].metadata)).to.be.deep.equal(expected); diff --git a/test/backend/unit/model/threading/MetaDataLoader.spec.ts b/test/backend/unit/model/threading/MetaDataLoader.spec.ts index 8687e878..7a09c5dd 100644 --- a/test/backend/unit/model/threading/MetaDataLoader.spec.ts +++ b/test/backend/unit/model/threading/MetaDataLoader.spec.ts @@ -44,5 +44,10 @@ describe('MetadataLoader', () => { expect(Utils.clone(data)).to.be.deep.equal(expected); }); + it('should respect mp4 rotate transformation', async () => { + const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video_rotate.mp4')); + const expected = require(path.join(__dirname, '/../../../assets/video_rotate.json')); + expect(Utils.clone(data)).to.be.deep.equal(expected); + }); });