async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): await update.message.reply_text( "Send me a video, and I'll remove the watermark from the center-bottom area.\n" "⚠️ Works best on simple logos/text. Processing may take 10–30 sec." )
import cv2 import numpy as np import ffmpeg def remove_watermark_from_video(input_path, output_path, watermark_region=(0.3, 0.85, 0.4, 0.15)): """ watermark_region: (x_norm, y_norm, width_norm, height_norm) where 0,0 = top-left, 1,1 = bottom-right Example: (0.3, 0.85, 0.4, 0.15) = 40% wide, 15% tall, starts 30% from left, 85% from top. """ cap = cv2.VideoCapture(input_path) if not cap.isOpened(): return False
# apply inpainting inpainted = cv2.inpaint(frame, mask, inpaintRadius=7, flags=cv2.INPAINT_TELEA) out.write(inpainted) telegram bot to remove watermark from video
cap.release() out.release()
# watermark box in pixels x = int(watermark_region[0] * width) y = int(watermark_region[1] * height) w = int(watermark_region[2] * width) h = int(watermark_region[3] * height) async def start(update: Update, context: ContextTypes
frame_count += 1 if frame_count % 50 == 0: print(f"Processed frame_count/total_frames frames")
# cleanup for p in [input_path, output_path]: if os.path.exists(p): os.remove(p) async def main(): app = Application.builder().token(TOKEN).build() app.add_handler(CommandHandler("start", start)) app.add_handler(MessageHandler(filters.VIDEO, handle_video)) print("Bot running...") await app.run_polling() async def start(update: Update
await video_file.download_to_drive(input_path) await msg.edit_text("🖌️ Removing watermark (inpainting)...")