remotion-dev / remotion

šŸŽ„ Make videos programmatically with React
https://remotion.dev
Other
20.53k stars 1.03k forks source link

Failed to parse MP4 with flip orientation in metadata #4208

Closed renambot closed 2 months ago

renambot commented 2 months ago

Crashes when loading an MP4:

const result = await parseMedia({
  src: "./video.mp4",
  fields: {
    durationInSeconds: true,
    dimensions: true,
    fps: true,
    videoCodec: true,
    audioCodec: true,
  },
  reader: nodeReader,
});
/vid/node_modules/@remotion/media-parser/dist/buffer-iterator.js:27
            throw new Error('Cannot increment by a negative amount: ' + amount);
                  ^

Error: Cannot increment by a negative amount: -7
    at OffsetCounter.increment (vid/node_modules/@remotion/media-parser/dist/buffer-iterator.js:27:19)
    at Object.discard (vid/node_modules/@remotion/media-parser/dist/buffer-iterator.js:231:21)
    at parseMdat (vid/node_modules/@remotion/media-parser/dist/boxes/iso-base-media/mdat/mdat.js:8:14)
    at processBox (vid/node_modules/@remotion/media-parser/dist/boxes/iso-base-media/process-box.js:400:48)
    at parseBoxes (vid/node_modules/@remotion/media-parser/dist/boxes/iso-base-media/process-box.js:449:44)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async parseMedia (vid/node_modules/@remotion/media-parser/dist/parse-media.js:48:27)
    at async file:///Users/luc/Desktop/vid/ex1.js:4:16

Every other video tools can load the file (including mp4box.js). File produced from Android phone with a 'flip' orientation in the metadata.

ffmpeg

  Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s (default)
    Metadata:
      rotate          : 180
exiftool

Matrix Structure                : -1 0 0 0 -1 0 0 0 1
Rotation                        : 180
JonnyBurger commented 2 months ago

Are you allowed to share the file? Would help fixing it.

Also possible privately (jonny@remotion.dev)

renambot commented 2 months ago

Sent a link, thanks.

JonnyBurger commented 2 months ago

Thanks, I managed to fix it! It now parses correctly and even returns the rotation of 180.

For all of this we didn't have a testcase before, so thank you!

renambot commented 2 months ago

Cool. Exciting project!