[FFmpeg-user] ffmpeg - compressing an mp4 creates a video distortion (horizontal stretch)

iburman at compuscience.com iburman at compuscience.com
Thu Jun 13 23:06:09 EEST 2024


I have a mp4 file that was created by concatenating several videos taken
with a cellphone. Some of the videos were taken horizontally and others
vertically.

The concatenated video plays fine but when I try to compress it so it can be
placed in a web site I have the following problem with the segments that
were taken vertically:

 

In the original file (before compression) the segments taken vertically look
good (no distortion) but they have black areas on the sides, which I believe
is expected as the width of the vertical video is smaller than the width of
the horizontal ones. 

 

In the compressed file, the segments coming from the vertical videos are
distorted. The compression removed the black areas on each side and
stretched the frame to have the full width of final video. In other words,
it made the width of the vertical segments equal to the width of the
horizontal ones, creating the distortion (stretching).

 

Why is this happening and how can I avoid it?

 

I uploaded the video to youtube to check if the compression they use results
in the same problem, and it did. So it looks like the ffmpeg command I am
using is similar to what YouTube does.

 

Here is the command I used:

Ffmpeg  -i concatenated_Final.mp4 -c:v libx264 -preset slow -crf 20 -r 30
-c:a copy -pix_fmt yuv420p concatenated_Final_Compressed.mp4

 

I tried with crf 20 and crf 31 but the problem was the same.

 

Thanks

 



More information about the ffmpeg-user mailing list