File size: 3,968 Bytes
86e3fda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/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()