User Tools

Site Tools


doc:appunti:linux:video:fix_smartphone_portrait_videos

This is an old revision of the document!


Convert a Smartphone's Portrait Video into Landscape, with ffmpeg

We have a problem: nowday too much people have a smartphone which is capable to take videos of very good quality. But very few of them realize that we have (generally) two eyes: one on the right and the other on the left; they think that we have one eye above and the other to the bottom, so they keep to take videos with the smartphone in the portrait orientation.

This is not a really problem, if we keep that videos in the phone and we watch at them in that miniature screen (until the phone is lost/broken/stolen). But it is really unacceptable if we want to watch at them using a normal, modern screen, which has inevitably a 16:9 aspect ratio. We will face at two equally unacceptable situations: the video player does not apply the rotation metatag contained into the video, or the video player adds two lateral black bands:

Original video, viewd with no rotation The video viewd with lateral black bands

The Compromise Solution

A compromise solution is to cut out a central area of the video and add to the sides some artifact that simulates the presence of a portion of video that does not actually exist. I find that solution by far more acceptable than the original video:

The interpolated video

So we have to:

  1. Choose a region to crop from the original video. It can vary from a square to the full portrait rectangle.
  2. Make a fake background blurring the cropped region and stretching it to the 16:9 aspect ratio.
  3. Overlay the cropped region over the fake background.

Choose the crop area

We wrote a Python script to assist in step #1, which calculate all the required numbers just provinding two parameters: the crop_aspect and the offset_y.

Adjust the crop_aspect from 0.0 (which selects a square) to 1.0 (which selects the full rectangle of the picture). Using a square-shaped crop area we will get the highest zoom level into the video, but we will cut-out a greather part of the frames, above and below the cropped region.

We can move the cropped region to the top of the image by setting offset_y to 0.0. Move it to te bottom by setting it to 1.0. To crop the image at the center of the screen, use an offset_y of 0.5. If you use a crop_aspect equal to 1.0 (full frame rectangle), the offset_y will be ignored.

Cropped Region and Fake Background

Once selected the cropped region, a fake background is created by simply stretching the region to 16:9 aspect ratio and applying a blur effect.

The Cropped Region The Fake Background

The Overlay Mask

The ffmpeg Recipe

doc/appunti/linux/video/fix_smartphone_portrait_videos.1523101012.txt.gz · Last modified: 2018/04/07 13:36 by niccolo