Im attempting to rotate a video that is in landscape into portrait using MP4Parser (or any other method if you know of one) currently playing with the TrackHeaderBox but unable to get the orientation to change at all, has anyone used this before that can spot the mistake I may of made? any help will go a long way thanks
IsoFile out = new DefaultMp4Builder().build(result);
// test
double[] m = null;
m = new double[] { 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
TrackBox tb = out.getMovieBox().getBoxes(TrackBox.class).get(0);
TrackHeaderBox box = tb.getTrackHeaderBox();
box.setMatrix(m);
Embedding Information about Rotation in the MP4
Are you really changing the orientation of the video track? If you change the orientation of the audio track you will not see any change.
From my experience it's easier to change the orientation of the whole file (1.0.4.2 API Version):
alternatively if you want to change the orientation directly without going via a
Movie
object:The file
result.mp4
is now rotated by 180 degrees as you can verify by playing back the file in a desktop player such as QuickTime or VLC.Typical Problems on Android
When you playback the video on Android with the help of the VideoView you might notice that the matrix is not taken into account. I'm not entirely sure if this is done on purpose or not but the workaround is to use a
TextureView
that applies the transformation.In order to do so you have to
setScaleX
,setScaleY
,setPivotX
,setPivotY
andsetRotation
with values according to the resulting matrix from the step before.