使用FFMPEG在视频上以所需角度覆盖文本 [英] Overlaying text on video with required angle using FFMPEG

查看:155
本文介绍了使用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天全站免登陆