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
-
Embed a watermark into a video:
embed_watermark_to_video('input_video.mp4', 'output_video_with_watermark.mp4', 'watermark.png', duration=10, fps=30)
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file video_invisible_watermark-0.1.2.tar.gz.
File metadata
- Download URL: video_invisible_watermark-0.1.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5cb594b0894538b583b741d764e758d6c53951c92d797d3ce3ddad3520e9d30
|
|
| MD5 |
d86a6177f9cbafe3804767c2691727c8
|
|
| BLAKE2b-256 |
fe455c0407894f0db54718f825d7f3667ad0b53555b23741b29befdb74952d92
|
File details
Details for the file video_invisible_watermark-0.1.2-py3-none-any.whl.
File metadata
- Download URL: video_invisible_watermark-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78414fc7f83a903e5a3bed64577b97bc8e69b836978a1f13c9c61660b0d6ec5b
|
|
| MD5 |
c2c9ef17b85d16e937b67625f4527d7b
|
|
| BLAKE2b-256 |
93539b2412cbfbfc0eb79467a94ed3c1f1a063cf2129b3994060d9455bffd450
|