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

William C Bonner wimbonner at gmail.com
Fri Jun 14 00:08:40 EEST 2024


On Thu, Jun 13, 2024 at 1:06 PM <iburman at compuscience.com> wrote:

> 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.
>
>
 I believe that the concatenation commands don't automatically deal with
differing video types, Different framerate, resolution,etc will all cause
unknown results. I don't see the ffmpeg command of how you created the
concatenated video.

When you are playing a vertical video and getting black bars on the sides,
that's the player recognizing the shape of the video and adding the bars.
Similar if you get bars at the top and bottom if your video is a different
perspective than the screen.

You need to preprocess each file to be the same format, then you can
concatenate them together.


More information about the ffmpeg-user mailing list