diff --git a/index.js b/index.js index b2e37d5..ae4186a 100644 --- a/index.js +++ b/index.js @@ -19,11 +19,19 @@ module.exports = async (input, opts = []) => { .find((stream) => stream.codec_type === 'video') || probe.streams[0] probe.duration = Math.round(stream.duration * 1000) - probe.width = stream.width - probe.height = stream.height + probe.rotate = stream.tags && stream.tags.rotate + ? parseInt(stream.tags.rotate) : 0 + if ([90, 270].includes(Math.abs(probe.rotate))) { + probe.width = stream.height + probe.height = stream.width + } else { + probe.width = stream.width + probe.height = stream.height + } const fpsFraction = stream.avg_frame_rate.split('/') probe.fps = fpsFraction[0] / fpsFraction[1] + probe.primaryStream = stream } else { probe.duration = undefined probe.width = undefined diff --git a/index.test.js b/index.test.js index fd51e02..6100c65 100644 --- a/index.test.js +++ b/index.test.js @@ -13,21 +13,32 @@ const fixtures = [ width: 640, height: 360, duration: 4000, - fps: 25 + fps: 25, + rotate: 0 }, { file: '1.mp4', width: 640, height: 360, duration: 4000, - fps: 25 + fps: 25, + rotate: 0 }, { file: '2.mp4', width: 640, height: 360, duration: 4000, - fps: 25 + fps: 25, + rotate: 0 + }, + { + file: '3.MOV', + width: 240, + height: 426, + duration: 5072, + fps: 29.97002997002997, + rotate: 90 } ] @@ -40,5 +51,6 @@ fixtures.forEach((fixture) => { t.deepEqual(probe.height, fixture.height) t.deepEqual(probe.duration, fixture.duration) t.deepEqual(probe.fps, fixture.fps) + t.deepEqual(probe.rotate, fixture.rotate) }) }) diff --git a/media/3.MOV b/media/3.MOV new file mode 100644 index 0000000..129e69b Binary files /dev/null and b/media/3.MOV differ diff --git a/package.json b/package.json index 7b49b5f..1dc6cfe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ffmpeg-probe", - "version": "1.0.6", + "version": "1.0.7", "description": "Wrapper around ffprobe for getting info about media files.", "main": "index.js", "repository": "transitive-bullshit/ffmpeg-probe",