没有vhook的ffmpeg水印?

发布于 2024-08-07 02:21:57 字数 77 浏览 5 评论 0 原文

由于 vhook 子系统已从最新版本的 FFMPEG 中删除,如何为视频添加水印?

我需要能够覆盖具有背景透明度的 PNG。

Since the vhook subsystem has been removed from the latest version of FFMPEG, how can I add a watermark to a video?

I need to be able to overlay a PNG with background transparency.

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

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

发布评论

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

评论(4

櫻之舞 2024-08-14 02:21:57

使用 Xuggler 我们可以在 java 中做到这一点。
使用 IMediaTool 编码视频时,您将获得图像序列。使用这些图像在每个图像上放置水印并生成输出视频。以下是代码块

BufferedImage imageB = event.getImage();

/*....................... water mark .........................*/
Graphics2D g2d = (Graphics2D) imageB.getGraphics();
g2d.drawImage(imageB, 0, 0, null);

//Create an alpha composite of 50%
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
g2d.setComposite(alpha); 

g2d.setColor(Color.YELLOW);


g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

g2d.setFont(new Font("Arial", Font.BOLD, 30));

String watermark = "Sample water mark";

FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(watermark, g2d);
yScrolling = imageB.getHeight() - (int) rect.getHeight() / 2;

g2d.drawString(watermark, (imageB.getWidth() - (int) rect.getWidth()) / 2,
                         (imageB.getHeight() - (int) rect.getHeight()) / 2);
g2d.drawString(watermark, xScrolling,yScrolling);

//Free graphic resources
g2d.dispose(); 

 /*....................... water mark .........................*/

Using Xuggler we can do this in java.
while encoding the video using IMediaTool, you will be getting sequence of images. Using these images place water mark on each of these images and generate a output video. Following is the code block

BufferedImage imageB = event.getImage();

/*....................... water mark .........................*/
Graphics2D g2d = (Graphics2D) imageB.getGraphics();
g2d.drawImage(imageB, 0, 0, null);

//Create an alpha composite of 50%
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
g2d.setComposite(alpha); 

g2d.setColor(Color.YELLOW);


g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

g2d.setFont(new Font("Arial", Font.BOLD, 30));

String watermark = "Sample water mark";

FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(watermark, g2d);
yScrolling = imageB.getHeight() - (int) rect.getHeight() / 2;

g2d.drawString(watermark, (imageB.getWidth() - (int) rect.getWidth()) / 2,
                         (imageB.getHeight() - (int) rect.getHeight()) / 2);
g2d.drawString(watermark, xScrolling,yScrolling);

//Free graphic resources
g2d.dispose(); 

 /*....................... water mark .........................*/
七分※倦醒 2024-08-14 02:21:57

如果您从官方 git 存储库编译 ffmpeg,您可能需要注意语法,因为它在新版本中发生了一些变化。

ffmpeg -i input.mp4 -acodec copy -vf "movie=0:png:watermark.png [wm];[in][wm] overlay=5:5:1 [out]" -f mp4 -b 2500k -vcodec libx264 -vpre fast -ac 1 -y output.mp4

ffmpeg -i input.mp4 -acodec copy -vf "movie=watermark.png [wm];[in][wm] overlay=5:5 [out]" -f mp4 -b 2500k -vcodec libx264 -vpre fast -ac 1 -y output.mp4

If you compile ffmpeg from official git repository, you probably need to pay attention to the syntax because it has changed a little bit in newer versions.

Old

ffmpeg -i input.mp4 -acodec copy -vf "movie=0:png:watermark.png [wm];[in][wm] overlay=5:5:1 [out]" -f mp4 -b 2500k -vcodec libx264 -vpre fast -ac 1 -y output.mp4

New

ffmpeg -i input.mp4 -acodec copy -vf "movie=watermark.png [wm];[in][wm] overlay=5:5 [out]" -f mp4 -b 2500k -vcodec libx264 -vpre fast -ac 1 -y output.mp4
爱给你人给你 2024-08-14 02:21:57

我能达到的最好的是 http://www.corbellconsulting.com/2010/07/using-ffmpeg-to-add-and-watermark-overlay-on-a-video-2/

但是,我无法让它与 ffmpeg 0.6.2 一起工作。

祝你好运。

The best I could reach was http://www.corbellconsulting.com/2010/07/using-ffmpeg-to-add-and-watermark-overlay-on-a-video-2/

However, I am unable to get it to work with ffmpeg 0.6.2.

Good luck.

〗斷ホ乔殘χμё〖 2024-08-14 02:21:57

如果您熟悉 Java,则可以使用 Xuggler 来完成此操作。特别是 Xuggler 的 MediaTool API 的教程向您展示了如何解码和编码视频,并分别如何使用您创建的图像从头开始制作视频。将这些概念结合起来制作一个可以解码视频、在视频上覆盖 PNG,然后重新编码的程序并不难。

If you're familiar with Java, you can do this with Xuggler. In particular the tutorials for the MediaTool API of Xuggler show you how to decode and encode a video, and separately how to make a video from scratch using images you create. It's not hard to combine those too concepts to make a program that can decode a video, overlay a PNG on the video, and then re-encode.

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