AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1702149
Accepted
Gramrock
Gramrock
Asked: 2022-01-30 20:02:59 +0800 CST2022-01-30 20:02:59 +0800 CST 2022-01-30 20:02:59 +0800 CST

为什么 1920x1080p 的视频在我 concat 后仍然会被拉伸和扭曲?

  • 772

我有几个不同纵横比的视频。

我使用此命令将它们全部放在 1920x1080p 帧内:

ffmpeg -i input -vcodec libx264 -s 1920x1080 -r 30 -strict experimental output

这很有效,所有视频在 1080p 分辨率下保持其纵横比。

完成之后,我将它们与此连接起来,我看到了两个意想不到的行为:

ffmpeg -f concat -safe 0 -i videolist.txt -vcodec libx264 -s 1920x1080 -r 30 -strict experimental -c copy 1080p_merged\output.mp4

首先,垂直视频被水平拉伸,即使它们已经在 1920x1080p 帧中,同时保持其纵横比。这怎么可能?

其次,我看到帧速率从我在每个实例中设置的 30fps(原始视频也有 30fps,到 29.95 或 29.81 或其他内容)下降。

我究竟做错了什么?

ffmpeg concatenation
  • 2 2 个回答
  • 697 Views

2 个回答

  • Voted
  1. Lex
    2022-01-31T04:20:20+08:002022-01-31T04:20:20+08:00

    该选项-s 1920x1080没有定义将这些视频放入的“帧边界”。它定义了输出视频的分辨率,并且间接地,输出视频的预期宽高比为 16:9。

    当您合并具有某些不同纵横比的视频时,它们将被拉伸以达到相同的纵横比。

    为了防止这种情况,您可以在将输入视频缩放为 1920x1080 之前,以 16:9 以外的宽高比向输入视频添加一些填充(水平或垂直黑条)。

    以下是一些如何添加此类黑条的示例。

    • 3
  2. Best Answer
    Rotem
    2022-01-31T14:44:47+08:002022-01-31T14:44:47+08:00

    奇怪的纵横比的原因与 SAR- Sample Aspect Ratio有关。

    通常 SAR 是 1:1,应用方形像素。
    非 1:1 的 SAR 值适用于非平方像素。
    您的第一个命令修改了 SAR 属性,这就是奇怪结果的原因。


    让我们从构建几个合成视频样本开始:

    ffmpeg -y -f lavfi -i testsrc=size=320x240:rate=30:duration=5 -vcodec libx264 -pix_fmt yuv420p -crf 17 in1.mkv
    ffmpeg -y -f lavfi -i testsrc=size=640x120:rate=30:duration=5 -vcodec libx264 -pix_fmt yuv420p -crf 17 in2.mkv
    ffmpeg -y -f lavfi -i testsrc=size=240x320:rate=30:duration=5 -vcodec libx264 -pix_fmt yuv420p -crf 17 in3.mkv
    

    使用您的命令将分辨率转换为 1920x1080:

    ffmpeg -i in1.mkv -vcodec libx264 -pix_fmt yuv420p -crf 17 -s 1920x1080 -r 30 out1.mp4
    ffmpeg -i in2.mkv -vcodec libx264 -pix_fmt yuv420p -crf 17 -s 1920x1080 -r 30 out2.mp4
    ffmpeg -i in3.mkv -vcodec libx264 -pix_fmt yuv420p -crf 17 -s 1920x1080 -r 30 out3.mp4
    

    查询width,height和使用SARFFprobe :DAR

    ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of default=noprint_wrappers=1 in1.mkv
    ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of default=noprint_wrappers=1 in2.mkv
    ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of default=noprint_wrappers=1 in3.mkv
    
    ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of default=noprint_wrappers=1 out1.mp4
    ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of default=noprint_wrappers=1 out2.mp4
    ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of default=noprint_wrappers=1 out3.mp4
    

    FF探针输出:

    in1.mkv
    width=320
    height=240
    sample_aspect_ratio=1:1
    display_aspect_ratio=4:3
    
    in2.mkv
    width=640
    height=120
    sample_aspect_ratio=1:1
    display_aspect_ratio=16:3
    
    in3.mkv
    width=240
    height=320
    sample_aspect_ratio=1:1
    display_aspect_ratio=3:4
    
    out1.mp4
    width=1920
    height=1080
    sample_aspect_ratio=3:4
    display_aspect_ratio=4:3
    
    out2.mp4
    width=1920
    height=1080
    sample_aspect_ratio=3:1
    display_aspect_ratio=16:3
    
    out3.mp4
    width=1920
    height=1080
    sample_aspect_ratio=27:64
    display_aspect_ratio=3:4
    

    如您所见,输入视频1:1的 SAR 是,但输出视频的 SAR 受原始输入视频分辨率的影响。

    1:1SAR 不会导致奇怪的纵横比问题的事实。
    注意:我不知道为什么FFmpeg默认修改SAR,但它是这样工作的。


    为了解决它,您可以使用scale带有过滤器的过滤器,setsar如下所述:

    ffmpeg -y -i in1.mkv -vf scale=1920:1080,setsar=1:1 -vcodec libx264 -pix_fmt yuv420p -crf 17 -s 1920x1080 -r 30 out1.mp4
    ffmpeg -y -i in2.mkv -vf scale=1920:1080,setsar=1:1 -vcodec libx264 -pix_fmt yuv420p -crf 17 -s 1920x1080 -r 30 out2.mp4
    ffmpeg -y -i in3.mkv -vf scale=1920:1080,setsar=1:1 -vcodec libx264 -pix_fmt yuv420p -crf 17 -s 1920x1080 -r 30 out3.mp4
    

    FF探针输出:

    width=1920
    height=1080
    sample_aspect_ratio=1:1
    display_aspect_ratio=16:9
    
    width=1920
    height=1080
    sample_aspect_ratio=1:1
    display_aspect_ratio=16:9
    
    width=1920
    height=1080
    sample_aspect_ratio=1:1
    display_aspect_ratio=16:9
    

    现在 SAR 是1:1,DAR 是16:9。

    您可以连接上述文件,而无需修改纵横比。


    修复 FPS:

    平均 FPS 是一个估计值,不准确的原因不止一个。
    很难说出现细微误差的原因。

    根据 concat demuxer文档:

    所有文件必须具有相同的流(相同的编解码器、相同的时基等)

    我们可以尝试用-r 30fps过滤器替换(设置​​时基,并修复时间以防万一……):

    ffmpeg -y -i in1.mkv -vf scale=1920:1080,setsar=1:1,fps=fps=30,settb=AVTB,setpts=PTS-STARTPTS -vcodec libx264 -pix_fmt yuv420p -crf 17 out1.mp4
    ffmpeg -y -i in2.mkv -vf scale=1920:1080,setsar=1:1,fps=fps=30,settb=AVTB,setpts=PTS-STARTPTS -vcodec libx264 -pix_fmt yuv420p -crf 17 out2.mp4
    ffmpeg -y -i in3.mkv -vf scale=1920:1080,setsar=1:1,fps=fps=30,settb=AVTB,setpts=PTS-STARTPTS -vcodec libx264 -pix_fmt yuv420p -crf 17 out3.mp4
    

    我不确定它是否会解决 FPS 问题。


    注意:
    准备输入文件然后重新编码不是最好的解决方案,因为您将视频重新编码两次,并且质量下降。

    我建议您使用concat filter,而不是 concat demuxer,并在一个命令中完成所有操作(以防它不太困难)。

    • 2

相关问题

  • -map_metadata 抓取多个音频流元数据

  • 最低比特率 ffmpeg 输出的编解码器和设置

  • 如何用ffmpeg 2.0.2保存TS视频流?

  • 快速提取 I 帧到图像

  • 压缩视频可以解码回未压缩的原始格式吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve