Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an MP4 video that was filmed on my Android phone, but the guy filmed it holding my phone some weird way.

When viewing it in QuickTime I have to rotate my laptop 90 degrees and then I will see it as a regular wide screen video and everything looks good.

In VLC the video is already widescreen with proper dimensions but its upside down so I have to flip my laptop upside down.

When I imported it into iMovie, I rotated it 90 degrees and it was the right side up but the video was squished and still taller then wide.

Not sure what's going on but how can I make it widescreen and right side up?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

MP4 files can have a rotate flag, which tells the player to rotate the video during playback, without changing the way the actual video bitstream is encoded and oriented. VLC does not support this flag, so if it shows the video upside down, then it actually is upside down and needs to be rotated.

The question is what you want to do with the video. You basically have two choices:

  • Keep it as-is and remove the rotation flag. If you want to edit the video later, flip it in whatever program you use to do so. If you want to play it, choose a player that supports on-the-fly rotation.
  • Rotate and transcode the video so it has a proper orientation. This will degrade the video quality a little though.

You can do all of that with ffmpeg. Download a static build for your operating system, and extract it to a directory, e.g. so that the ffmpeg executable file is in ~/Downloads. Then open up a terminal window and navigate to said directory:

cd ~/Downloads
./ffmpeg

This should run the ffmpeg binary. For more info read our blog article on ffmpeg.


Here are the actual commands you can use. If you want to keep the actual video bitstream and remove the rotation flag, you only need to remove the metadata for the first video stream v:0, and copy the video and audio bitstreams (-c copy):

ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=0 output.mp4

If you want to transcode the video, flipping it by 180°, you need to specify a video encoder (here, libx264) and the flipping filter. The audio stream will be copied over.

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -filter:v "hflip,vflip" -c:a copy output.mp4

You can adjust the CRF (Constant Rate Factor) to change the quality of the video. Sane values are anywhere between 18 and 28, depending on your input quality. Lower means better quality, so if your video ends up looking worse than the original, try a lower CRF value.

share|improve this answer
    
So if my video is upside down in VLC then it is actually upside down. Does that mean removing the rotation flag will do nothing and I will have to do option number 2? –  yoyo May 13 '13 at 11:56
    
Removing the rotation flag would only cause it to display like it was actually recorded in QuickTime, and thus make it easier to import in video editing programs, but in essence you probably just want to re-encode and flip it. –  slhck May 13 '13 at 11:57
    
Im on Mac OSX. When I type ./ffmpeg it sais Permission Denied, Im on admin and it sais it has read and write priviledges. The file doesn't have a extention though. –  yoyo May 13 '13 at 22:15
    
Try chmod +x ./ffmpeg before. This makes the file executable. –  slhck May 14 '13 at 4:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.