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 / 问题 / 1839619
Accepted
Aneesh
Aneesh
Asked: 2024-04-19 14:29:53 +0800 CST2024-04-19 14:29:53 +0800 CST 2024-04-19 14:29:53 +0800 CST

FFMPeg:在图像中心旋转图像

  • 772

我试图将图像叠加在视频的 X,Y 位置,然后将其旋转任意角度,其中 x,y = 150,100

然而,这并没有按预期工作。

下面是我正在使用的命令。

ffmpeg -i input_video.mp4 -i Crown.png -filter_complex "[1:v]format=rgba, 旋转=-30 PI/180:ow='rotw(-30 PI/180)':oh='roth(- 30*PI/180)' [旋转];[0:v][旋转]覆盖=150:100" -编解码器:复制sample.mp4

问题是它绕角上的点而不是中间的点旋转。以图像为例:

下面显示了背景视频(网格)顶部的叠加层(狗图像)。这是位于 150,100 且旋转 0 度的正常图像。

在此输入图像描述

现在将其旋转 -90 度应给出以下输出:**这是正确的预期输出**

在此输入图像描述

但它实际上给出了输出:**错误的输出**

在此输入图像描述

看起来发生这种情况是因为 FFMPEG 处理旋转的方式,而我期望它绕中心旋转,它绕角锚点之一旋转。我怎样才能在这里实现我需要的轮换?

ffmpeg
  • 1 1 个回答
  • 23 Views

1 个回答

  • Voted
  1. Best Answer
    Rotem
    2024-04-19T18:13:07+08:002024-04-19T18:13:07+08:00

    为了保留中心,我们必须通过中心的移动来调整左上角坐标(中心坐标由于旋转而移动):

    ffmpeg -y -i input_video.mp4 -i crown.png -filter_complex "[1:v]format=rgba,rotate=-30*PI/180:ow='rotw(-30*PI/180)':oh='roth(-30*PI/180)':c=none[rotate];[0:v][rotate]overlay=150+(600-overlay_w)/2:100+(400-overlay_h)/2" -codec:a copy sample_fix.mp4

    将 替换600为 的水平尺寸crown.png。
    将 替换400为 的垂直尺寸crown.png。
    注意:该示例手动使用输入图像的宽度和高度。我们可以使用一个脚本来自动化该过程,该脚本将宽度和高度值提取到变量(在执行 FFmpeg 之前),并在执行命令时使用变量。


    计算旋转 90 度的 x、y 调整的示例:

    假设crown.png的分辨率为600x400。

          600
     -------------
    |             |
    |      x      | 400
    |             |
     -------------
     Center coordinate before rotation:
     cx, cy = [(600-1)/2, (400-1)/2] = [(orig_w-1)/2, (orig_h-1)/2]
    
        600
     --------
    |        | 
    |        |
    |   x    | 400
    |        |
    |        |
     --------
    Center coordinate after rotation:
    cx, cy = [(400-1)/2, (600-1)/2] = [(rot_w-1)/2, (rot_h-1)/2]
    
    For keeping the center, we have to add the following offsets:
    delta_cx, delta_cy = [(600-1)/2, (400-1)/2] - [(400-1)/2, (600-1)/2] = [100, -100]
    
    Generally, we have to add the following offsets:
    Horizontal offset: (orig_w-rot_w)/2
    Vertical offset: (orig_h-rot_h)/2
    

    测试:

    创建分辨率为 600x400 的示例输入crown.png(用于测试):
    ffmpeg -y -f lavfi -i testsrc=size=600x400:rate=1:duration=1 -update 1 crown.png

    使用table.png作为“主”图像。

    零旋转叠加:
    ffmpeg -y -i table.png -i crown.png -filter_complex "[1:v]format=rgba,rotate=0*PI/180:ow='rotw(0*PI/180)':oh='roth(0*PI/180)':c=none[rotate];[0:v][rotate]overlay=150:100" -update 1 sample0.png

    30 度旋转叠加:
    ffmpeg -y -i table.png -i crown.png -filter_complex "[1:v]format=rgba,rotate=-30*PI/180:ow='rotw(-30*PI/180)':oh='roth(-30*PI/180)':c=none[rotate];[0:v][rotate]overlay=150+(600-overlay_w)/2:100+(400-overlay_h)/2" -update 1 sample30.png


    输出:
    sample0.png和sample30.png:
    在此输入图像描述 在此输入图像描述

    我们可以看到,旋转后的中心位置与没有旋转的中心位置相同。

    • 1

相关问题

  • -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
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • 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
    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