Advertisement
DeaD_EyE

watermark.py

Nov 18th, 2021
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. import subprocess
  2. import sys
  3. from argparse import ArgumentParser
  4. from pathlib import Path
  5.  
  6.  
  7. # filter_top_right = "overlay=main_w-overlay_w-5:5"
  8. # filter_top_right = "overlay=main_w-overlay_w-5:5:format=auto,format=yuv420p"
  9. filter_top_right = "[1]format=rgba,colorchannelmixer=aa=0.5[logo];[0][logo]overlay=main_w-overlay_w-5:5:format=auto,format=yuv420p"
  10.  
  11.  
  12. def add_watermark(
  13.     input_video: Path, output_video: Path, watermark: Path, overwrite: bool = True
  14. ) -> bool:
  15.     if not input_video.exists() or not watermark.exists():
  16.         return False
  17.  
  18.     if overwrite:
  19.         output_video.unlink(missing_ok=True)
  20.     elif output_video.exists():
  21.         return False
  22.  
  23.     cmd = [
  24.         "ffmpeg",
  25.         "-i",
  26.         input_video,
  27.         "-i",
  28.         watermark,
  29.         "-filter_complex",
  30.         filter_top_right,
  31.         "-codec:a",
  32.         "copy",
  33.         output_video,
  34.     ]
  35.  
  36.     return subprocess.run(cmd).returncode == 0
  37.  
  38.  
  39. def get_args():
  40.     parser = ArgumentParser()
  41.     parser.add_argument("input", type=Path, help="Input Video")
  42.     parser.add_argument("watermark", type=Path, help="Watermark picture")
  43.     parser.add_argument("output", type=Path, help="Output Video")
  44.     return parser.parse_args()
  45.  
  46.  
  47. if __name__ == "__main__":
  48.     args = get_args()
  49.     add_watermark(args.input, args.output, args.watermark)
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement