Vanilagy / mp4-muxer

MP4 multiplexer in pure TypeScript with support for WebCodecs API, video & audio.
https://vanilagy.github.io/mp4-muxer/demo
MIT License
401 stars 31 forks source link

Rotation metadata #13

Closed TheForsakenSpirit closed 11 months ago

TheForsakenSpirit commented 1 year ago

Hi is there a way to add rotation metadata to final file?

I found, that safari always record video in landscape, but for portrait adds rotation metadata, and that add weird issue to final file. ffprobe for source file: image

Vanilagy commented 1 year ago

Could you send me a demo file with the weird issue? You think this rotation metadata is included directly in the encoded video chunks? I'm new to this topic as well - we'll need to see I need to add more metadata options to this library to support these cases.

TheForsakenSpirit commented 1 year ago

I try to build transcoder for safari, that transcode recorded from camera or native camera video. And they always record video in landscape resolution. (for example 640w x 480h) In case when user record video in portrait format, what is required for my case, safari just add that rotation metadata to file. (it 640 x 480, when I expect 480 x 640)

Source: https://github.com/Vanilagy/mp4-muxer/assets/37292419/e0443586-d405-4048-ab7b-ef034cc08d6c

And when it transcoded, i get: https://github.com/Vanilagy/mp4-muxer/assets/37292419/4bf6f020-30d1-41be-8b71-f1dfc90f8de3

So, to avoid performance heavy calculations, it there a way to add same metadata as in source file? Thanks!

Vanilagy commented 1 year ago

Sorry for the late response! Thanks for the demo files. I still need a bit more context: Could you share the code you use to transcode the source file, or how you're using the muxer specifically?

TheForsakenSpirit commented 12 months ago

@Vanilagy My demo: https://github.com/TheForsakenSpirit/Transcoder-demo-for-webcodecs You can pass source video to input and push buttons Start Worker -> Start Transcoding and get same result as I get.

Vanilagy commented 11 months ago

I've published v2.3.0, which solves this issue with a new rotation option when creating the muxer! You can now do something like this:

new Muxer({
    // ...
    video: {
        // ...
        rotation: 90
    }
});

This will add metadata to the file which will rotate the entire video 90 degrees clockwise. This should solve your problem, since you can now transcode to landscape video and simply set this rotation option.

If you have the time, please verify this feature works :)