5

Basically I would like to rotate video, depending on which camera was used to take it.

Front camera is mirrored with 90 degrees, whereas back camera is displayed properly. Currently it will set Matrix according to the first clip. If the first clip was made with front camera, it will rotate all clips to 270 degrees and vice a versa.

Here is a sample code (rotations is an ArrayList which contains clip rotations):

for (TrackBox trackBox : trackBoxes) {
       Log.d("TRACKBOX", String.valueOf(rotations.get(i)));
       //trackBox.getTrackHeaderBox().setMatrix(Matrix.ROTATE_90);
       if (rotations.get(i) == 90) { //if clip was made with back camera
              trackBox.getTrackHeaderBox().setMatrix(Matrix.ROTATE_90);
              Log.d("Rotating to:", "90 degrees");

       } else if (rotations.get(i) == 270) { // if clip was made with front camera
              trackBox.getTrackHeaderBox().setMatrix(Matrix.ROTATE_270);
              Log.d("Rotating to:", "270 degrees");
       }
       m.addTrack(new Mp4TrackImpl(trackBox));

}
inMovies[i] = m;
informatik01
  • 16,038
  • 10
  • 74
  • 104
Torsten Ojaperv
  • 1,014
  • 17
  • 24
  • Hi Torsten, Me to facing same issue. Did you resolve orientation issue? If you resolved issues, Please help me – Murali Ganesan Oct 13 '14 at 04:51
  • 1
    @MuraliGanesan I'm sorry but I haven't dealt with this project a long time. I finally used Instagram tactic where you disable switching camera after you've recorded one clip with back/front camera. – Torsten Ojaperv Oct 14 '14 at 17:06

1 Answers1

-1

Actually, you can rotate video with these codes, no need use mp4 parser library, so complex.

/**
 *
 * @param mMediaRecorder
 * @return
 */
public static MediaRecorder rotateBackVideo(MediaRecorder mMediaRecorder) {
    /**
     * Define Orientation of video in here,
     * if in portrait mode, use value = 90,
     * if in landscape mode, use value = 0
     */
    switch (CustomCamera.current_orientation) {
        case 0:
            mMediaRecorder.setOrientationHint(90);
            break;
        case 90:
            mMediaRecorder.setOrientationHint(180);
            break;
        case 180:
            mMediaRecorder.setOrientationHint(270);
            break;
        case 270:
            mMediaRecorder.setOrientationHint(0);
            break;
    }

    return mMediaRecorder;
}

/**
 *
 * @param mMediaRecorder
 * @return
 */
public static MediaRecorder rotateFrontVideo(MediaRecorder mMediaRecorder) {
    /**
     * Define Orientation of video in here,
     * if in portrait mode, use value = 90,
     * if in landscape mode, use value = 0
     */
    switch (CustomCamera.current_orientation) {
        case 0:
            mMediaRecorder.setOrientationHint(270);
            break;
        case 90:
            mMediaRecorder.setOrientationHint(180);
            break;
        case 180:
            mMediaRecorder.setOrientationHint(90);
            break;
        case 270:
            mMediaRecorder.setOrientationHint(0);
            break;
    }

    return mMediaRecorder;
}
Huy Tower
  • 7,769
  • 16
  • 61
  • 86