Spaces:
Running on Zero
Running on Zero
| #!/usr/bin/env python3 | |
| """ | |
| Video Blur AI - Command Line Interface | |
| Usage: | |
| python cli.py input.mp4 --prompt "face. license plate." --output blurred.mp4 | |
| python cli.py input.mp4 --prompt "hand." --blur-type pixelate --strength 15 | |
| """ | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| from config import get_config | |
| from pipeline import VideoBlurPipeline | |
| def main(): | |
| parser = argparse.ArgumentParser( | |
| description="🎬 Video Blur AI - Text-prompted video object blurring", | |
| formatter_class=argparse.RawDescriptionHelpFormatter, | |
| epilog=""" | |
| Examples: | |
| %(prog)s video.mp4 --prompt "face." | |
| %(prog)s video.mp4 --prompt "face. license plate." --blur-type pixelate | |
| %(prog)s video.mp4 --prompt "hand." --strength 99 --mode frame_by_frame | |
| %(prog)s video.mp4 --prompt "person." --blur-type black --output censored.mp4 | |
| """ | |
| ) | |
| parser.add_argument("video", help="Input video file path") | |
| parser.add_argument("-p", "--prompt", required=True, | |
| help="Text prompt describing what to blur (e.g., 'face. hand.')") | |
| parser.add_argument("-o", "--output", default=None, | |
| help="Output video path (default: input_blurred.mp4)") | |
| # Blur settings | |
| parser.add_argument("--blur-type", choices=["gaussian", "pixelate", "black"], | |
| default="gaussian", help="Type of blur effect") | |
| parser.add_argument("--strength", type=int, default=51, | |
| help="Blur strength (odd number, default: 51)") | |
| parser.add_argument("--feather", type=int, default=11, | |
| help="Edge feathering (odd number, default: 11)") | |
| # Processing settings | |
| parser.add_argument("--mode", choices=["video_tracking", "frame_by_frame"], | |
| default="video_tracking", help="Processing mode") | |
| parser.add_argument("--keyframe-interval", type=int, default=5, | |
| help="Keyframe detection interval (frame_by_frame mode)") | |
| parser.add_argument("--threshold", type=float, default=0.3, | |
| help="Detection confidence threshold (0.1-0.9)") | |
| args = parser.parse_args() | |
| # Validate input | |
| if not Path(args.video).exists(): | |
| print(f"❌ Video not found: {args.video}") | |
| sys.exit(1) | |
| # Generate output path if not specified | |
| if args.output is None: | |
| p = Path(args.video) | |
| args.output = str(p.parent / f"{p.stem}_blurred{p.suffix}") | |
| # Run pipeline | |
| print("\n" + "="*60) | |
| print(" 🎬 Video Blur AI - CLI Mode") | |
| print("="*60) | |
| print(f" Input: {args.video}") | |
| print(f" Prompt: {args.prompt}") | |
| print(f" Blur: {args.blur_type} (strength={args.strength})") | |
| print(f" Mode: {args.mode}") | |
| print(f" Output: {args.output}") | |
| print("="*60 + "\n") | |
| config = get_config() | |
| pipeline = VideoBlurPipeline(config) | |
| def cli_progress(value, text): | |
| bar_length = 30 | |
| filled = int(bar_length * value) | |
| bar = "█" * filled + "░" * (bar_length - filled) | |
| print(f"\r [{bar}] {value*100:5.1f}% | {text}", end="", flush=True) | |
| if value >= 1.0: | |
| print() | |
| try: | |
| output = pipeline.process_video( | |
| video_path=args.video, | |
| text_prompt=args.prompt, | |
| output_path=args.output, | |
| blur_type=args.blur_type, | |
| blur_strength=args.strength, | |
| edge_feather=args.feather, | |
| processing_mode=args.mode, | |
| keyframe_interval=args.keyframe_interval, | |
| detection_threshold=args.threshold, | |
| progress_callback=cli_progress, | |
| ) | |
| print(f"\n✅ Output saved to: {output}") | |
| except KeyboardInterrupt: | |
| print("\n\n⚠️ Processing cancelled by user") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"\n\n❌ Error: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |