为什么 ffmpeg -filter_complex hstack 会扭曲图像?

为什么 ffmpeg -filter_complex hstack 会扭曲图像?

我准备了两个视频——

obamap.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'obamap.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : Movie Test
    artist          : Matplotlib
    encoder         : Lavf57.83.100
    comment         : Movie support!
  Duration: 00:00:02.07, start: 0.000000, bitrate: 173 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 500x500, 106 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler

obamapl.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'obamapl.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:00:02.00, start: 0.000000, bitrate: 143 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 500x500 [SAR 4:3 DAR 4:3], 137 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler

接下来将它们水平堆叠 -

ffmpeg -i obamap.mp4 -i obamapl.mp4 -filter_complex hstack=inputs=2 combined_1.mp4


ffprobe combined_1.mp4                                                                     
ffprobe version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2007-2019 the FFmpeg developers
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'combined_1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : Movie Test
    artist          : Matplotlib
    encoder         : Lavf57.83.100
    comment         : Movie support!
  Duration: 00:00:02.12, start: 0.000000, bitrate: 294 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1000x500, 228 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler

在生成的文件中combined_1.mp4,右侧obamapl.mp4看起来被水平挤压了

当堆叠顺序反转时 -

!ffmpeg -i obamapl.mp4 -i obamap.mp4 -filter_complex hstack=inputs=2 combined_2.mp4

ffprobe combined_2.mp4
ffprobe version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2007-2019 the FFmpeg developers
...

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'combined_2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:00:02.10, start: 0.000000, bitrate: 290 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 1000x500 [SAR 4:3 DAR 8:3], 222 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler

在生成的文件中combined_2.mp4,右侧obamap.mp4看起来是水平拉伸的。

我怎样才能避免这种挤压和拉伸?

答案1

视频的有效显示尺寸是视频存储的分辨率通过样本/像素宽高比调节而来。

obamapl.mp4因此SAR 4:3兼容的播放器会将其转换为500*4/3x500=,667x500从而产生 4:3 的 DAR。

您应该在堆叠之前将其缩放为方形像素。

ffmpeg -i obamap.mp4 -i obamapl.mp4 -filter_complex "[1]scale=2*trunc(iw*sar/2):ih[r];[0][r]hstack=inputs=2" combined_1.mp4

相关内容