0

How can I create the mirrored value of a video using mp4Parser. If it is possible what value for matrix will work. Please help me..

Mahesh
  • 974
  • 6
  • 12

1 Answers1

0

The matrix is:

-1  0  0 
 0  1  0
 0  0  1

This code sets the matrix to the first track in the file:

    IsoFile isoFile = new IsoFile("input.mp4");
    TrackHeaderBox tkhd = 
           (TrackHeaderBox) Path.getPath(isoFile, "/moov[0]/trak[0]/tkhd[0]");
    tkhd.setMatrix(new Matrix(-1, 0, 0, 1, 0, 0, 1, 0, 0));
    FileOutputStream fos = new FileOutputStream("output.mp4");
    isoFile.getBox(fos.getChannel());

But be aware that not all players support matrix tranformations.

Have a look here to see how to make VideoView respect the matrix .

Community
  • 1
  • 1
Sebastian Annies
  • 2,438
  • 1
  • 20
  • 38
  • First of all thank you so much for providing us with this great library. I tried the above code with android and made video preview in android VideoView, it seems that video doesn't show any change. – Mahesh Aug 14 '14 at 05:54
  • Video rotation using Matrix.ROTATE_270 and Matrix.ROTATE_90 is working fine with me. – Mahesh Aug 14 '14 at 06:01
  • Please try it with quicktime if you can. My test with quicktime worked (vlc didn't) – Sebastian Annies Aug 14 '14 at 13:58
  • Sorry it didn't work. I need the videos to be played in android VideoView. Am using library in android application. Any other alternative? – Mahesh Aug 25 '14 at 09:18
  • I didn't mean to use quicktime completely. I just suggested to use quicktime - as its known to support the matrix settings - to verify that the file was written correctly. – Sebastian Annies Aug 25 '14 at 14:22
  • Another chance for you might setting the matrix at the Movie Header Box (/moov/mvhd) - perhaps VideoView respects it there. – Sebastian Annies Aug 25 '14 at 14:23
  • Hi Mahesh, would you please vote up for my answer? My matrix mirrors the video, unfortunately your VideoView doesn't seem to support it. – Sebastian Annies Sep 07 '14 at 08:40
  • I'm having a bit of trouble getting the matrix right for rotating 90 and then flipping horizontally. What would that matrix constructor look like? I find it a bit confusing that the matrix order differs so from android.graphics.matrix. – colintheshots Jun 12 '15 at 16:32