FFmpeg AVFilter 以编程方式覆盖/水印

发布于 2025-01-02 08:40:16 字数 267 浏览 1 评论 0原文

我正在尝试使用 FFmpeg 以编程方式将图像或视频叠加在另一个视频的顶部。看来AVFilter可以做到这一点。

有很多关于如何使用命令行执行此操作或类似操作的示例,但是,除了 doc/examples/filtering.c 之外,我没有找到以编程方式使用 AVFilter 的示例,这对我有帮助,但还不够。 我已经可以对视频进行解码和编码,我只需要学习如何过滤解码的帧并添加水印。

有没有以编程方式使用 libavfilter 的示例?

有使用叠加或电影滤镜的示例吗?

I'm trying to programmatically overlay either images or a video on the top of another video using FFmpeg. It seems that AVFilter can do this.

There are lots of examples of how to do this or similar things with the command line however, I have found no examples of using AVFilter programmatically apart from doc/examples/filtering.c which helps me but not really enough.
I can already decode and encode a video, I just need to learn how to filter the decoded frames and add a watermark.

Are there any examples of using libavfilter programmatically?

Are there examples of using the overlay or movie filters?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转瞬即逝 2025-01-09 08:40:16

命令:

ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:10 [out]" outputvideo.flv

生成左上角带有图像“watermarklogo.png”的视频。从另一个程序调用这个命令应该很简单。

一点一点地分解来理解它:

ffmpeg 是您将用来添加水印的程序。

-i 用于指定输入文件。

inputvideo.avi 是由-i 指定的输入文件。

-vf 用于指定视频滤镜。在本例中,这就是引号中的所有内容。

movie=watermarklogo.png 将加载您想要用作水印的文件。在这里,我们将文件作为视频源加载(通过使用movie),无论文件是否是视频。在本例中它是一个图像。

[watermark] 为您刚刚加载的文件添加标签。该标签将在代码的其余部分中使用。

[in][out]分别指视频的输入流和输出流。

overlay 紧接在 [watermark] 标签之后使用,以便引用它。在这个简单的例子中,我们将叠加层放置在10:10处。这意味着水印将从顶部和左侧偏移 10 个像素。如果您想要右下角,则可以使用 overlay=main_w-overlay_w-10:main_h-overlay_h-10 其中 main_w 是输入流的宽度,overlay_h 是覆盖文件的高度,依此类推。

最后,outputvideo.flv 显然是您希望将结果保存到的文件。

其他信息:

我通过找到了此信息网站 Dmitry 在评论中提到。亚历克斯曾提到,对于刚接触此类事物的人来说,此页面可能过于复杂。然而,我从来没有做过这样的事情,在短短几分钟内我就得到了我相信正在寻求的结果。

注意:当我收到错误时,我遇到了一些麻烦:

error while opening encoder for output stream #0.1

如果您遇到同样的问题,您可能需要使用 -ar 参数(例如 -ar 22050)手动设置采样频率。

The command:

ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:10 [out]" outputvideo.flv

produces the video with the image "watermarklogo.png" in the top left hand corner. Calling this command from another program should be simple enough.

Breaking this down bit by bit to understand it:

ffmpeg is the program you'll be using to add the watermark.

-i is used to specify the input files.

inputvideo.avi is your input file specified by -i.

-vf is used to specify the video filter. In this case, this is everything in the quotes.

movie=watermarklogo.png will load the file you want to use as the watermark. Here we load the file as a video source (by using movie) regardless of whether or not the file is an video. In this case it is an image.

[watermark] labels the file you just loaded. This label will be used in the rest of the code.

[in] and [out] refer to the input stream and the output stream of the video.

overlay is used right after the [watermark] label so that it refers to it. In this simple case we place the overlay at 10:10. This means the watermark will be offset by 10 pixels from the top and from the left. If you wanted bottom right you would use overlay=main_w-overlay_w-10:main_h-overlay_h-10 where main_w is the input stream's width, overlay_h is the height of the overlay file, and so on.

Lastly, outputvideo.flv is clearly the file you wish to save the results to.

Additional information:

I found this information through the site Dmitry had mentioned in the comments. Alex had mentioned that this page might be too complex for someone who's new to such things. However, I've never done anything like this and within just a couple minutes I had the results I believe are being sought.

Note: I had a moment of trouble when I was getting the error:

error while opening encoder for output stream #0.1

If you have the same problem you likely need to manually set the sampling frequency using the -ar parameter (e.g. -ar 22050).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文