help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
surveillance-video
RSK World
surveillance-video
Surveillance Video Dataset - Security Camera + Person Detection + Anomaly Detection + OpenCV + YOLO
surveillance-video
  • __pycache__
  • annotations
  • config
  • frames
  • models
  • output
  • videos
  • .gitignore713 B
  • GITHUB_DEPLOYMENT.md3.5 KB
  • LICENSE1.3 KB
  • README.md13 KB
  • RELEASE_NOTES.md5.6 KB
  • alert_system.py12 KB
  • analytics.js9.2 KB
  • analytics_dashboard.html9.3 KB
  • api_server.py10.7 KB
  • batch_processor.py8.3 KB
  • config.py1.2 KB
  • create_sample_video.py7.4 KB
  • create_zip.py2.6 KB
  • detect_anomalies.py7.2 KB
  • detect_persons.py6.3 KB
  • download_sample_videos.py2.5 KB
  • extract_frames.py4.5 KB
  • index.html62.2 KB
  • multi_camera_system.py12.5 KB
  • package.json1.2 KB
  • process_video.py4.4 KB
  • project_data.json1.3 KB
  • project_data.php1.6 KB
  • project_data.py1.7 KB
  • requirements.txt372 B
  • script.js6.6 KB
  • setup.py2 KB
  • styles.css13.4 KB
  • surveillance-video.zip1.2 MB
  • train_ml_model.py9 KB
  • verify_project.py5 KB
  • video_quality_analyzer.py9.5 KB
  • video_search.py10.7 KB
batch_processor.py
batch_processor.py
Raw Download
Find: Go to:
# Project: Surveillance Video Dataset
# Author: Molla Samser
# Website: https://rskworld.in/
# Contact: help@rskworld.in
# Phone: +91 93305 39277
# Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147

"""
Advanced batch processing system for multiple surveillance videos.
Supports parallel processing, progress tracking, and error handling.
"""

import os
import json
import cv2
from pathlib import Path
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor, as_completed
import argparse


class BatchProcessor:
    """Batch processor for surveillance videos."""
    
    def __init__(self, max_workers=4):
        self.max_workers = max_workers
        self.results = []
        self.errors = []
    
    def process_video(self, video_path, operations=['detection', 'anomaly', 'frames']):
        """
        Process a single video with specified operations.
        
        Args:
            video_path: Path to video file
            operations: List of operations to perform
        """
        result = {
            'video_path': video_path,
            'filename': os.path.basename(video_path),
            'status': 'processing',
            'start_time': datetime.now().isoformat(),
            'operations': {}
        }
        
        try:
            # Import processing modules
            from detect_persons import detect_persons_yolo, detect_persons_opencv
            from detect_anomalies import detect_anomalies_motion
            from extract_frames import extract_frames
            
            # Person detection
            if 'detection' in operations:
                try:
                    output_file = f"annotations/person_detections_{os.path.basename(video_path).replace('.mp4', '')}.json"
                    detect_persons_yolo(video_path, output_file=output_file)
                    result['operations']['detection'] = 'completed'
                except Exception as e:
                    result['operations']['detection'] = f'error: {str(e)}'
            
            # Anomaly detection
            if 'anomaly' in operations:
                try:
                    output_file = f"annotations/anomalies_{os.path.basename(video_path).replace('.mp4', '')}.json"
                    detect_anomalies_motion(video_path, output_file=output_file)
                    result['operations']['anomaly'] = 'completed'
                except Exception as e:
                    result['operations']['anomaly'] = f'error: {str(e)}'
            
            # Frame extraction
            if 'frames' in operations:
                try:
                    output_dir = f"frames/extracted_frames_{os.path.basename(video_path).replace('.mp4', '')}"
                    extract_frames(video_path, output_dir=output_dir, interval=30)
                    result['operations']['frames'] = 'completed'
                except Exception as e:
                    result['operations']['frames'] = f'error: {str(e)}'
            
            result['status'] = 'completed'
            result['end_time'] = datetime.now().isoformat()
            
        except Exception as e:
            result['status'] = 'failed'
            result['error'] = str(e)
            result['end_time'] = datetime.now().isoformat()
            self.errors.append(result)
        
        return result
    
    def process_batch(self, video_paths, operations=['detection', 'anomaly', 'frames']):
        """
        Process multiple videos in parallel.
        
        Args:
            video_paths: List of video file paths
            operations: List of operations to perform on each video
        """
        print(f"Starting batch processing of {len(video_paths)} videos...")
        print(f"Operations: {', '.join(operations)}")
        print(f"Max workers: {self.max_workers}\n")
        
        with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
            # Submit all tasks
            future_to_video = {
                executor.submit(self.process_video, video_path, operations): video_path
                for video_path in video_paths
            }
            
            # Process completed tasks
            completed = 0
            for future in as_completed(future_to_video):
                video_path = future_to_video[future]
                try:
                    result = future.result()
                    self.results.append(result)
                    completed += 1
                    
                    status_icon = "✓" if result['status'] == 'completed' else "✗"
                    print(f"{status_icon} [{completed}/{len(video_paths)}] {os.path.basename(video_path)} - {result['status']}")
                except Exception as e:
                    error_result = {
                        'video_path': video_path,
                        'status': 'failed',
                        'error': str(e)
                    }
                    self.errors.append(error_result)
                    completed += 1
                    print(f"✗ [{completed}/{len(video_paths)}] {os.path.basename(video_path)} - failed: {str(e)}")
        
        return self.generate_report()
    
    def generate_report(self):
        """Generate processing report."""
        total = len(self.results) + len(self.errors)
        completed = len([r for r in self.results if r.get('status') == 'completed'])
        failed = len(self.errors)
        
        report = {
            'summary': {
                'total_videos': total,
                'completed': completed,
                'failed': failed,
                'success_rate': round((completed / total * 100) if total > 0 else 0, 2)
            },
            'results': self.results,
            'errors': self.errors,
            'timestamp': datetime.now().isoformat()
        }
        
        # Save report
        report_file = f"output/batch_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
        os.makedirs('output', exist_ok=True)
        
        with open(report_file, 'w') as f:
            json.dump(report, f, indent=2)
        
        print("\n" + "=" * 60)
        print("Batch Processing Report")
        print("=" * 60)
        print(f"Total Videos: {total}")
        print(f"Completed: {completed}")
        print(f"Failed: {failed}")
        print(f"Success Rate: {report['summary']['success_rate']}%")
        print(f"Report saved to: {report_file}")
        print("=" * 60)
        
        return report


def find_videos(directory='videos', extensions=['.mp4', '.avi', '.mov', '.mkv']):
    """Find all video files in directory."""
    video_paths = []
    
    if os.path.exists(directory):
        for root, dirs, files in os.walk(directory):
            for file in files:
                if any(file.lower().endswith(ext) for ext in extensions):
                    video_paths.append(os.path.join(root, file))
    
    return video_paths


def main():
    parser = argparse.ArgumentParser(description='Batch process surveillance videos')
    parser.add_argument('--directory', '-d', default='videos', help='Directory containing videos')
    parser.add_argument('--operations', '-o', nargs='+', 
                       choices=['detection', 'anomaly', 'frames', 'all'],
                       default=['all'],
                       help='Operations to perform')
    parser.add_argument('--workers', '-w', type=int, default=4, 
                       help='Number of parallel workers')
    parser.add_argument('--videos', '-v', nargs='+', help='Specific video files to process')
    
    args = parser.parse_args()
    
    # Determine operations
    if 'all' in args.operations:
        operations = ['detection', 'anomaly', 'frames']
    else:
        operations = args.operations
    
    # Get video paths
    if args.videos:
        video_paths = [v if os.path.exists(v) else os.path.join(args.directory, v) 
                      for v in args.videos]
    else:
        video_paths = find_videos(args.directory)
    
    if not video_paths:
        print(f"No videos found in {args.directory}")
        return
    
    # Process batch
    processor = BatchProcessor(max_workers=args.workers)
    processor.process_batch(video_paths, operations)


if __name__ == '__main__':
    main()

221 lines•8.3 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer