sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.76k stars 566 forks source link

No effect for the TrackMetaData setMatrix() method #286

Open Aissa-H opened 6 years ago

Aissa-H commented 6 years ago

Hello @sannies and thanks for this great lib!

I'm currently using it in an app where the user can take videos from the front and the back camera. As it was mentioned in this issue, when we want to merge videos with different rotations, we find in the result upside down sequences.

To fix it, my idea was to change the Matrix of the video track just before merging to the rotation angle I want in order to obtain a collection of videos with the same rotation value. So I used the TrackMetaData attribute of the tracks as follows:

Track t = ......
if(t.getTrackMetaData().getMatrix().equals(Matrix.ROTATE_270)){
    t.getTrackMetaData().setMatrix(Matrix.ROTATE_90);
}

Here, I'm getting the video Track which was taken from the front camera (Rotation=270) and trying to rotate it. By doing this I hope that the merge will return again the video from 90 to 270 (+180°) and so the video will not be upside down.

My problem now: the method setMatrix() seems to have no effect, I have no changes in my final merged video.

Have you any idea about it? It will be very useful I think for the lib, we will maybe be able to fix the upside down issue mentioned before!

Thank you in advance!

andrevdk commented 6 years ago

Hi, Did you manage to fix this issue?

shaojin8864 commented 5 years ago

i have the same issue,did you solve it?

andrevdk commented 5 years ago

@shaojin8864 This solution will never work because setMatrix is used only by video players eventually. This merge library is not aware of the rotation info. The only way is to rotate the video pre-merge with some video tools like ffmpeg.

mendax92 commented 5 years ago

I hope to help you. I am trying to encode video from the camera and audio from the microphone using MediaCodec and MediaMuxer. Rendering with OpenGL.

https://github.com/lumyus/FlexCam