Skip to main content

A Python library to embed invisible watermarks into video frames

Project description

README

Video Watermarking with DCT

This project provides a simple way to embed and extract watermarks from video frames using the Discrete Cosine Transform (DCT). The watermark image is embedded in the luminance component (Y) of the YUV color space of each video frame.

Requirements

To install the required packages, use the following command:

pip install -r requirements.txt

Contents of requirements.txt:

opencv-python
Pillow
scipy

Usage

Embedding a Watermark in a Video

To embed a watermark in a video, use the embed_watermark_to_video function. This function takes the input video path, output video path, watermark image path, duration in seconds, and frames per second (fps) as arguments.

Example:

embed_watermark_to_video('input_video.mp4', 'output_video_with_watermark.mp4', 'watermark.png', duration=10, fps=30)

Extracting a Watermark from a Video

To extract a watermark from a video, use the extract_watermark_from_video function. This function takes the output video path, the prefix for the directory where extracted images will be saved, and the duration in seconds as arguments.

Example:

extract_watermark_from_video('output_video_with_watermark.mp4', prefix='result/post_compression', duration=10)

Functions

load_image(image_path, size=(100, 100))

Loads an image and resizes it to the specified size.

embed_watermark_to_frame(frame, img)

Embeds a watermark image into a video frame using DCT.

extract_watermark_from_frame(frame, img_size=(100, 100))

Extracts the embedded watermark image from a video frame using DCT.

video_to_frames(video_path, duration=10, fps=30)

Splits a video into frames for the specified duration and frames per second (fps).

frames_to_video(frames, output_path, fps, size)

Combines frames into a video with the specified frames per second (fps) and output size.

save_images(images, prefix='result/pre_compression')

Saves images to the specified directory with a given prefix.

embed_watermark_to_video(input_video_path, output_video_path, watermark_path, duration=10, fps=30)

Embeds a watermark into a video for the specified duration and frames per second (fps).

extract_watermark_from_video(output_video_path, prefix='compression', duration=10)

Extracts the watermark from a video for the specified duration and saves the extracted images to the specified directory.

Example Workflow

  1. Embed a watermark into a video:

    embed_watermark_to_video('input_video.mp4', 'output_video_with_watermark.mp4', 'watermark.png', duration=10, fps=30)
    
  2. Extract the watermark from the video:

    extract_watermark_from_video('output_video_with_watermark.mp4', prefix='result/post_compression', duration=10)
    

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgments

Feel free to customize this README further based on your specific needs and usage of the project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

video_invisible_watermark-0.1.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

video_invisible_watermark-0.1.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file video_invisible_watermark-0.1.2.tar.gz.

File metadata

File hashes

Hashes for video_invisible_watermark-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f5cb594b0894538b583b741d764e758d6c53951c92d797d3ce3ddad3520e9d30
MD5 d86a6177f9cbafe3804767c2691727c8
BLAKE2b-256 fe455c0407894f0db54718f825d7f3667ad0b53555b23741b29befdb74952d92

See more details on using hashes here.

File details

Details for the file video_invisible_watermark-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for video_invisible_watermark-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 78414fc7f83a903e5a3bed64577b97bc8e69b836978a1f13c9c61660b0d6ec5b
MD5 c2c9ef17b85d16e937b67625f4527d7b
BLAKE2b-256 93539b2412cbfbfc0eb79467a94ed3c1f1a063cf2129b3994060d9455bffd450

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page