You have a video recording but its been shot with the lens at the wrong angle. The result is that you have to slant your head to watch it! Here are some solutions to save your neck!!
There are many reasons why a video may have been shot at the wrong angle but the most common seems to be from cellphones or small sports cameras.
Windows explorer identifies this piece of video with a 720P Resolution. It has a height of 720px and a width of 1280px. The problem though, as can be seen from the thumbnail, is that the person recording has positioned the camera to fit in the door. It was recorded in portrait mode.
Windows Media Player is able to decode and play the video – but its difficult to watch due to the recording angle.
The easiest option for review and playback is to utilise a player that is able to rotate video – such as SMplayer. The rotate options are held under the Video menu.
This is all well and good for playback, but what if we need to utilise this video in some way. Perhaps we need to send this to someone else.
The first, and easiest solution comes when the video forms part of a bigger project, perhaps with other video from other sources. In these circumstances a Non Linear Editor would be utilised such as Grass Valley Edius, Adobe Premiere Pro or Avid Media Composer. All of these have video layout tools that can manipulate the video and change its shape / size etc.
If you only have this single piece then it may be easier to use a quicker tool for single video files, such as Virtualdub. I have a version of Vdub preconfigured with various input drivers and filters. It in my shared BOX down the right. SpreadysVDubPack.Zip
After importing the video, the first filter applied is Rotate. I have then chosen 90 degrees counter clockwise.
I could leave it here and just output this as a new correctly rotated video. For the purpose of this example though, what if we wanted to prepare this for an NTSC DVD Encoding and Authoring tool? We will need to resize the video and then adjust the frame to the correct resolution. For this we need to add on the Resize filter AFTER the Rotate filter.
I have retained the Aspect Ratio and then adjusted the Height to that of the NTSC standard. As a result the Width automatically adjusts. Under Framing options, I have Letterboxed to 720×480 and chosen the fill colour. The result being……
After adjusting the frame rate to ensure DVD compatibility, this can be output as an uncompressed interim video file, ready for authoring to Video DVD in your software of choice.
You may find that you get these a lot and automating the rotate and resize may be useful. For this FFmpeg is one of the easiest routes.
So, what is required?
- Identify rotate direction (Clockwise / Counter Clockwise etc.)
- Choose Output size and Format
For the purpose of this example, I have identified that my video needs to be rotated counter clockwise and I wish to resize and output to a PAL Video DVD standard Mpeg2. I can then author this to Video DVD with no extra transcoding.
ffmpeg -i INPUTVIDEO -vf "transpose=2:portrait,scale=w=-1:ih=576,pad=720:576:(ow-iw)/2:(oh-ih)/2" -c:v mpeg2video -b:v 6000k -minrate 4000k -maxrate 6000k -bufsize 2000k -dc 9 -flags +ilme+ildct -alternate_scan 1 -top 1 -r 25 -c:a copy OUTPUTVIDEO.mpg
Before I go into the important parts of this command, here is the result: A PAL Video DVD Compliant MPEG2 File with the video in the correct angle.
The Video Filter Chain is the part doing most of the work.
The first filter is TRANSPOSE. 1 is rotate clockwise and 2 is rotate counter clockwise. I needed counter clockwise.
The next Filter is SCALE. I knew that the Height should be 576 (for PAL) and wanted to set the Width to keep original aspect ratio. As a result I have entered the input height and set the width to the -1 parameter. This parameter tells the filter to adjust the Width by the same percentage of the Height.
If your original files are smaller in height than 576 then you can just remove the scale part of the filter.
The last filter is PAD. I needed to make my video resolution as 720 x 576 without distorting the footage. As result we need to pad out the video, keeping the actual footage in the centre.
You can change the Padding colour if required, by adding :color=Blue at the end of the pad filter. See http://ffmpeg.org/ffmpeg-utils.html#Color for more colour options.
After the filter chain, comes the encoding options. I have chosen PAL Video DVD here but you could obviously go out to whatever you required. If you only needed to rotate and not resize or pad, and wanted to go out to WMV for immediate playback in Windows Media Player then something like this would do the trick.
ffmpeg -i INPUTVIDEO -vf transpose=2:portrait -qscale 2 OUTPUTVIDEO.wmv
Having all these saved as presets in something like AnotherGUI will save you a lot of time and effort when greeted with wonky files! You could add 4 in:
- Rotate Clockwise for DVD
- Rotate Counter Clockwise for DVD
- Rotate Clockwise for WMV
- Rotate Counter Clockwise for WMV
As always, hope it helps….
Update: I have been reminded of another Open Source tool that may assist in the process – Avidemux. See the link below for details: