使用 FFMPEG 在具有所需角度的视频上叠加文本 [英] Overlaying text on video with required angle using FFMPEG

查看:35
本文介绍了使用 FFMPEG 在具有所需角度的视频上叠加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ffmpeg 在视频上叠加一些文本.我可以通过波纹管命令覆盖文本.

I am trying to overlay some text on video using ffmpeg. I am able to overlay text by the bellow command.

ffmpeg -i input1.mp4 -filter_complex "[0:v]transpose=2[anticlockwiserotated];[anticlockwiserotated]drawtext=fontfile=../../public/fonts/Roboto-Regular-webfont.ttf: text='Test Text':x=100: y=50: fontsize=36: fontcolor=white:[textapplied];[textapplied]transpose=1" output_video.mp4

它允许我仅水平或垂直叠加.

It is allowing me to overlay horizontally or vertically only.

但我想附加一个像 45 度这样的角度.

But I want to append it with some angle like 45 degrees.

为此,如果我将命令修改为

For that if I modify the command as

ffmpeg -i input1.mp4 -filter_complex "[0:v]rotate=45*PI/180[anticlockwiserotated];[anticlockwiserotated]drawtext=fontfile=../../public/fonts/Roboto-Regular-webfont.ttf: text='Test Text':x=100: y=50: fontsize=36: fontcolor=white:[textapplied];[textapplied]rotate=315*PI/180" output_video.mp4

由此我得到的叠加视频为:

By this I am getting overlay video as:

因为在这第一次我将视频旋转到 45 度,附加文本并将其恢复到原始位置.所以我正在失去边界.

Because in this first I am rotating video to 45 degrees, appending text and bringing it back to original position. So I am loosing borders.

请建议我在视频上以所需角度叠加文字的最佳方式.

Please suggest me the best way to overlay text with required angle on video.

提前致谢.

推荐答案

基本方法是在空白画布上生成文本,然后为文本添加 alpha 层,旋转结果并将其叠加在主视频上.

Basic method is to generate text on a blank canvas, then an alpha layer for the text, rotating the result and overlaying that on the main video.

在下面的命令中,a 应替换为角度.绘图文本的坐标用于覆盖.根据文本的长度,如果逆时针旋转,其中一些可能会被剪掉.因此,请相应地检查并调整 Y 偏移.

In the command below, a should be replaced by the angle. The co-ordinates for the drawtext are used in the overlay instead. Depending on the length of your text, some of it may get clipped if you've rotated it anticlockwise. So check and adjust the Y offset accordingly.

ffmpeg -i input1.mp4 -filter_complex 
        "color=black:100x100[c];
         [c][0]scale2ref[ct][mv];
         [ct]setsar=1,drawtext=fontfile=../../public/fonts/Roboto-Regular-webfont.ttf:
             text='Test Text':fontsize=36:fontcolor=white,split[text][alpha];
         [text][alpha]alphamerge,rotate=a:ow=rotw(a):oh=roth(a):c=black@0[txta];
         [mv][txta]overlay=x='min(0,-H*sin(a))+100':y='min(0,W*sin(a))+50':shortest=1"
      output_video.mp4

这篇关于使用 FFMPEG 在具有所需角度的视频上叠加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆