-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
73 lines (63 loc) · 2.23 KB
/
model.py
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
"""
Main model coordination and integration.
"""
from typing import List, Optional, Callable
import logging
from core.errors import VideoError
from models.metadata import FrameMetadata, VideoMetadata
from analysis.analyzer import FrameAnalyzer
from video import VideoReader
from processor import VideoProcessor
class FrameExtractionModel:
"""
Main model coordinating frame extraction and analysis.
This class serves as the main integration point, coordinating:
- Video I/O
- Frame analysis
- Processing decisions
- Result management
"""
def __init__(self, config):
"""Initialize model components."""
logger = logging.getLogger(__name__)
self.config = config
self.analyzer = FrameAnalyzer(config)
self.processor = VideoProcessor(config)
self._metadata: Optional[VideoMetadata] = None
logger.debug(f"FrameExtractionModel instantiated with config: {self.config}")
async def process_video(
self,
input_path: str,
output_dir: str,
progress_callback: Optional[Callable[[float], None]]
) -> List[str]:
"""
Process video file and extract frames.
Args:
input_path: Path to input video
output_dir: Directory for output frames
progress_callback: Optional progress reporting function
Returns:
List of paths to extracted frames
Raises:
VideoError: If processing fails
"""
logger = logging.getLogger(__name__)
try:
# Read video metadata
with VideoReader(input_path) as reader:
self._metadata = reader.get_metadata()
# Process video
output_files = await self.processor.process_video(
input_path,
output_dir,
progress_callback
)
logger.debug(f"process_video completed with files {output_files} based on {self.config}")
return output_files
except Exception as e:
raise VideoError(f"Video processing failed: {e}") from e
@property
def metadata(self) -> Optional[VideoMetadata]:
"""Get video metadata if available."""
return self._metadata