Add a Watermark to a Video Using VideoAlchemy

Mohammad Hossein Gerami - Sep 10 - - Dev Community

Watermarking videos is a common task, especially when you want to protect your content. In this post, I'll walk you through how to easily add a watermark to a video using VideoAlchemy, a YAML-driven FFmpeg wrapper that simplifies video processing tasks.

Why VideoAlchemy?
VideoAlchemy allows you to write clean, readable YAML configurations for video processing tasks, making it easier to handle FFmpeg commands without getting lost in complex syntax. Here's how you can add a watermark to your video using VideoAlchemy.

YAML Configuration for Watermarking
The YAML file to add a watermark is straightforward. You define your input video, the watermark image, and the positioning of the watermark on the video. Below is a sample viddo-compose.yaml file:

version: 1

generate_path: "./generated"

tasks:
  - name: Adding a Watermark to a Video
    command: ffmpeg
    inputs:
      - id: input_1
        source: 'input.mp4'
      - id: watermark
        source: 'watermark.png'
    codecs:
      - video_filters:
          - name: overlay
            value: "10:10"
    outputs:
      - id: output_1
        overwrite: true
        source: 'output.mp4'
Enter fullscreen mode Exit fullscreen mode

Explanation of the YAML File:

  • version: Specifies the version of the YAML configuration.
  • generate_path: Defines where the generated ffmpeg command and log will be saved.

  • tasks: Contains a list of video processing tasks, in this case, adding a watermark.

  • inputs:

    • input_1: The source video file (input.mp4).
    • watermark: The image file (watermark.png) that will be overlaid on the video.
  • codecs:

    • video_filters: Applies the overlay filter, which positions the watermark image at coordinates 10:10 (10 pixels from the top and 10 pixels from the left).
  • outputs:

    • output_1: The output video file (output.mp4), with overwrite set to true in case the file already exists.

Steps to Add the Watermark

  1. Install VideoAlchemy: Follow the installation steps in the VideoAlchemy repository.

  2. Create Your YAML File: Save the above YAML configuration as viddo-compose.yaml.

  3. Run the Command: Use VideoAlchemy’s command to execute the YAML file.

  videoalchemy compose -f viddo-compose.yaml
Enter fullscreen mode Exit fullscreen mode

Conclusion
With VideoAlchemy, adding a watermark to a video becomes as simple as writing a few lines of YAML. The overlay filter lets you control the position of the watermark, and you can easily tweak the positioning as needed. This tool is great for developers who want to simplify their video processing workflows while keeping it flexible and powerful.

Feel free to explore other video processing features in VideoAlchemy and experiment with more complex configurations!

.
Terabox Video Player