Update config/app_config.py
Browse files- config/app_config.py +181 -0
config/app_config.py
CHANGED
@@ -161,6 +161,108 @@ class ProcessingConfig:
|
|
161 |
max_model_size: int = int(os.getenv('MAX_MODEL_SIZE', '0'))
|
162 |
max_model_size_bytes: int = int(os.getenv('MAX_MODEL_SIZE_BYTES', '0'))
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
# Output settings
|
165 |
output_dir: str = os.getenv('OUTPUT_DIR', 'outputs')
|
166 |
output_format: str = os.getenv('OUTPUT_FORMAT', 'mp4')
|
@@ -343,6 +445,85 @@ def _validate_config(self):
|
|
343 |
if self.video_codec not in valid_codecs:
|
344 |
self.video_codec = 'mp4v'
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
# Validate output settings
|
347 |
valid_formats = ['mp4', 'avi', 'mov', 'webm', 'mkv']
|
348 |
if self.output_format not in valid_formats:
|
|
|
161 |
max_model_size: int = int(os.getenv('MAX_MODEL_SIZE', '0'))
|
162 |
max_model_size_bytes: int = int(os.getenv('MAX_MODEL_SIZE_BYTES', '0'))
|
163 |
|
164 |
+
# Temporal consistency and smoothing (COMPREHENSIVE)
|
165 |
+
temporal_ema_alpha: float = float(os.getenv('TEMPORAL_EMA_ALPHA', '0.7'))
|
166 |
+
temporal_window_size: int = int(os.getenv('TEMPORAL_WINDOW_SIZE', '5'))
|
167 |
+
temporal_blend_factor: float = float(os.getenv('TEMPORAL_BLEND_FACTOR', '0.5'))
|
168 |
+
temporal_consistency_threshold: float = float(os.getenv('TEMPORAL_CONSISTENCY_THRESHOLD', '0.8'))
|
169 |
+
use_temporal_smoothing: bool = os.getenv('USE_TEMPORAL_SMOOTHING', 'true').lower() == 'true'
|
170 |
+
temporal_buffer_frames: int = int(os.getenv('TEMPORAL_BUFFER_FRAMES', '10'))
|
171 |
+
|
172 |
+
# Mask post-processing (COMPREHENSIVE)
|
173 |
+
mask_min_area: int = int(os.getenv('MASK_MIN_AREA', '100'))
|
174 |
+
mask_max_area: int = int(os.getenv('MASK_MAX_AREA', '0'))
|
175 |
+
mask_fill_holes: bool = os.getenv('MASK_FILL_HOLES', 'true').lower() == 'true'
|
176 |
+
mask_convex_hull: bool = os.getenv('MASK_CONVEX_HULL', 'false').lower() == 'true'
|
177 |
+
mask_largest_component: bool = os.getenv('MASK_LARGEST_COMPONENT', 'true').lower() == 'true'
|
178 |
+
mask_smooth_radius: int = int(os.getenv('MASK_SMOOTH_RADIUS', '0'))
|
179 |
+
mask_binary_threshold: float = float(os.getenv('MASK_BINARY_THRESHOLD', '0.5'))
|
180 |
+
mask_confidence_threshold: float = float(os.getenv('MASK_CONFIDENCE_THRESHOLD', '0.7'))
|
181 |
+
|
182 |
+
# Contour processing (COMPREHENSIVE)
|
183 |
+
contour_approx_epsilon: float = float(os.getenv('CONTOUR_APPROX_EPSILON', '0.01'))
|
184 |
+
contour_min_points: int = int(os.getenv('CONTOUR_MIN_POINTS', '4'))
|
185 |
+
contour_max_points: int = int(os.getenv('CONTOUR_MAX_POINTS', '0'))
|
186 |
+
contour_smoothing: bool = os.getenv('CONTOUR_SMOOTHING', 'false').lower() == 'true'
|
187 |
+
contour_simplification: bool = os.getenv('CONTOUR_SIMPLIFICATION', 'false').lower() == 'true'
|
188 |
+
|
189 |
+
# Trimap generation (COMPREHENSIVE)
|
190 |
+
trimap_dilation_size: int = int(os.getenv('TRIMAP_DILATION_SIZE', '10'))
|
191 |
+
trimap_erosion_size: int = int(os.getenv('TRIMAP_EROSION_SIZE', '5'))
|
192 |
+
trimap_unknown_width: int = int(os.getenv('TRIMAP_UNKNOWN_WIDTH', '20'))
|
193 |
+
trimap_confidence_threshold: float = float(os.getenv('TRIMAP_CONFIDENCE_THRESHOLD', '0.5'))
|
194 |
+
use_trimap: bool = os.getenv('USE_TRIMAP', 'false').lower() == 'true'
|
195 |
+
|
196 |
+
# SAM2 specific parameters (COMPREHENSIVE)
|
197 |
+
sam2_points_per_side: int = int(os.getenv('SAM2_POINTS_PER_SIDE', '32'))
|
198 |
+
sam2_pred_iou_thresh: float = float(os.getenv('SAM2_PRED_IOU_THRESH', '0.88'))
|
199 |
+
sam2_stability_score_thresh: float = float(os.getenv('SAM2_STABILITY_SCORE_THRESH', '0.95'))
|
200 |
+
sam2_crop_n_layers: int = int(os.getenv('SAM2_CROP_N_LAYERS', '0'))
|
201 |
+
sam2_crop_n_points_downscale_factor: int = int(os.getenv('SAM2_CROP_N_POINTS_DOWNSCALE_FACTOR', '1'))
|
202 |
+
sam2_min_mask_region_area: int = int(os.getenv('SAM2_MIN_MASK_REGION_AREA', '0'))
|
203 |
+
sam2_use_m2m: bool = os.getenv('SAM2_USE_M2M', 'false').lower() == 'true'
|
204 |
+
sam2_multimask_output: bool = os.getenv('SAM2_MULTIMASK_OUTPUT', 'true').lower() == 'true'
|
205 |
+
|
206 |
+
# Background processing (COMPREHENSIVE)
|
207 |
+
bg_blur_radius: int = int(os.getenv('BG_BLUR_RADIUS', '0'))
|
208 |
+
bg_blur_type: str = os.getenv('BG_BLUR_TYPE', 'gaussian')
|
209 |
+
bg_fill_mode: str = os.getenv('BG_FILL_MODE', 'stretch')
|
210 |
+
bg_color: str = os.getenv('BG_COLOR', '#000000')
|
211 |
+
bg_opacity: float = float(os.getenv('BG_OPACITY', '1.0'))
|
212 |
+
|
213 |
+
# Green screen / chroma key (COMPREHENSIVE)
|
214 |
+
chroma_tolerance: float = float(os.getenv('CHROMA_TOLERANCE', '0.3'))
|
215 |
+
chroma_softness: float = float(os.getenv('CHROMA_SOFTNESS', '0.1'))
|
216 |
+
chroma_defringe: bool = os.getenv('CHROMA_DEFRINGE', 'true').lower() == 'true'
|
217 |
+
chroma_despill: bool = os.getenv('CHROMA_DESPILL', 'true').lower() == 'true'
|
218 |
+
chroma_key_color: str = os.getenv('CHROMA_KEY_COLOR', '#00FF00')
|
219 |
+
|
220 |
+
# Motion detection (COMPREHENSIVE)
|
221 |
+
motion_detect: bool = os.getenv('MOTION_DETECT', 'false').lower() == 'true'
|
222 |
+
motion_threshold_percent: float = float(os.getenv('MOTION_THRESHOLD_PERCENT', '5.0'))
|
223 |
+
motion_blur_kernel: int = int(os.getenv('MOTION_BLUR_KERNEL', '21'))
|
224 |
+
motion_min_area: int = int(os.getenv('MOTION_MIN_AREA', '500'))
|
225 |
+
|
226 |
+
# Stabilization (COMPREHENSIVE)
|
227 |
+
stabilize: bool = os.getenv('STABILIZE', 'false').lower() == 'true'
|
228 |
+
stabilize_smoothing: float = float(os.getenv('STABILIZE_SMOOTHING', '30.0'))
|
229 |
+
stabilize_crop_percent: float = float(os.getenv('STABILIZE_CROP_PERCENT', '0.05'))
|
230 |
+
|
231 |
+
# Advanced processing flags (COMPREHENSIVE)
|
232 |
+
use_guided_filter: bool = os.getenv('USE_GUIDED_FILTER', 'false').lower() == 'true'
|
233 |
+
guided_filter_radius: int = int(os.getenv('GUIDED_FILTER_RADIUS', '8'))
|
234 |
+
guided_filter_eps: float = float(os.getenv('GUIDED_FILTER_EPS', '0.2'))
|
235 |
+
use_grabcut: bool = os.getenv('USE_GRABCUT', 'false').lower() == 'true'
|
236 |
+
grabcut_iterations: int = int(os.getenv('GRABCUT_ITERATIONS', '5'))
|
237 |
+
use_watershed: bool = os.getenv('USE_WATERSHED', 'false').lower() == 'true'
|
238 |
+
watershed_markers: int = int(os.getenv('WATERSHED_MARKERS', '10'))
|
239 |
+
|
240 |
+
# Frame sampling (COMPREHENSIVE)
|
241 |
+
sample_rate: int = int(os.getenv('SAMPLE_RATE', '1'))
|
242 |
+
start_frame: int = int(os.getenv('START_FRAME', '0'))
|
243 |
+
end_frame: int = int(os.getenv('END_FRAME', '-1'))
|
244 |
+
process_every_nth_frame: int = int(os.getenv('PROCESS_EVERY_NTH_FRAME', '1'))
|
245 |
+
interpolate_frames: bool = os.getenv('INTERPOLATE_FRAMES', 'false').lower() == 'true'
|
246 |
+
|
247 |
+
# Preview and debug (COMPREHENSIVE)
|
248 |
+
preview_enabled: bool = os.getenv('PREVIEW_ENABLED', 'false').lower() == 'true'
|
249 |
+
preview_scale: float = float(os.getenv('PREVIEW_SCALE', '0.5'))
|
250 |
+
debug_masks: bool = os.getenv('DEBUG_MASKS', 'false').lower() == 'true'
|
251 |
+
debug_contours: bool = os.getenv('DEBUG_CONTOURS', 'false').lower() == 'true'
|
252 |
+
save_debug_frames: bool = os.getenv('SAVE_DEBUG_FRAMES', 'false').lower() == 'true'
|
253 |
+
|
254 |
+
# Threading and parallelization (COMPREHENSIVE)
|
255 |
+
num_threads: int = int(os.getenv('NUM_THREADS', '4'))
|
256 |
+
use_multiprocessing: bool = os.getenv('USE_MULTIPROCESSING', 'false').lower() == 'true'
|
257 |
+
chunk_size: int = int(os.getenv('CHUNK_SIZE', '10'))
|
258 |
+
prefetch_frames: int = int(os.getenv('PREFETCH_FRAMES', '5'))
|
259 |
+
|
260 |
+
# Memory optimization (COMPREHENSIVE)
|
261 |
+
low_memory_mode: bool = os.getenv('LOW_MEMORY_MODE', 'false').lower() == 'true'
|
262 |
+
cache_frames: bool = os.getenv('CACHE_FRAMES', 'true').lower() == 'true'
|
263 |
+
max_cache_size_mb: int = int(os.getenv('MAX_CACHE_SIZE_MB', '1024'))
|
264 |
+
clear_cache_interval: int = int(os.getenv('CLEAR_CACHE_INTERVAL', '100'))
|
265 |
+
|
266 |
# Output settings
|
267 |
output_dir: str = os.getenv('OUTPUT_DIR', 'outputs')
|
268 |
output_format: str = os.getenv('OUTPUT_FORMAT', 'mp4')
|
|
|
445 |
if self.video_codec not in valid_codecs:
|
446 |
self.video_codec = 'mp4v'
|
447 |
|
448 |
+
# Validate temporal consistency (COMPREHENSIVE)
|
449 |
+
self.temporal_ema_alpha = max(0.0, min(1.0, self.temporal_ema_alpha))
|
450 |
+
self.temporal_window_size = max(1, min(100, self.temporal_window_size))
|
451 |
+
self.temporal_blend_factor = max(0.0, min(1.0, self.temporal_blend_factor))
|
452 |
+
self.temporal_consistency_threshold = max(0.0, min(1.0, self.temporal_consistency_threshold))
|
453 |
+
self.temporal_buffer_frames = max(1, min(300, self.temporal_buffer_frames))
|
454 |
+
|
455 |
+
# Validate mask post-processing
|
456 |
+
self.mask_min_area = max(0, self.mask_min_area)
|
457 |
+
self.mask_binary_threshold = max(0.0, min(1.0, self.mask_binary_threshold))
|
458 |
+
self.mask_confidence_threshold = max(0.0, min(1.0, self.mask_confidence_threshold))
|
459 |
+
self.mask_smooth_radius = max(0, min(50, self.mask_smooth_radius))
|
460 |
+
|
461 |
+
# Validate contour processing
|
462 |
+
self.contour_approx_epsilon = max(0.0, min(1.0, self.contour_approx_epsilon))
|
463 |
+
self.contour_min_points = max(3, self.contour_min_points)
|
464 |
+
|
465 |
+
# Validate trimap
|
466 |
+
self.trimap_dilation_size = max(0, min(50, self.trimap_dilation_size))
|
467 |
+
self.trimap_erosion_size = max(0, min(50, self.trimap_erosion_size))
|
468 |
+
self.trimap_unknown_width = max(1, min(100, self.trimap_unknown_width))
|
469 |
+
self.trimap_confidence_threshold = max(0.0, min(1.0, self.trimap_confidence_threshold))
|
470 |
+
|
471 |
+
# Validate SAM2 parameters
|
472 |
+
self.sam2_points_per_side = max(1, min(100, self.sam2_points_per_side))
|
473 |
+
self.sam2_pred_iou_thresh = max(0.0, min(1.0, self.sam2_pred_iou_thresh))
|
474 |
+
self.sam2_stability_score_thresh = max(0.0, min(1.0, self.sam2_stability_score_thresh))
|
475 |
+
self.sam2_crop_n_layers = max(0, min(10, self.sam2_crop_n_layers))
|
476 |
+
self.sam2_crop_n_points_downscale_factor = max(1, min(16, self.sam2_crop_n_points_downscale_factor))
|
477 |
+
self.sam2_min_mask_region_area = max(0, self.sam2_min_mask_region_area)
|
478 |
+
|
479 |
+
# Validate background processing
|
480 |
+
self.bg_blur_radius = max(0, min(100, self.bg_blur_radius))
|
481 |
+
valid_blur_types = ['gaussian', 'box', 'median', 'bilateral']
|
482 |
+
if self.bg_blur_type not in valid_blur_types:
|
483 |
+
self.bg_blur_type = 'gaussian'
|
484 |
+
valid_fill_modes = ['stretch', 'fit', 'fill', 'tile']
|
485 |
+
if self.bg_fill_mode not in valid_fill_modes:
|
486 |
+
self.bg_fill_mode = 'stretch'
|
487 |
+
self.bg_opacity = max(0.0, min(1.0, self.bg_opacity))
|
488 |
+
|
489 |
+
# Validate chroma key
|
490 |
+
self.chroma_tolerance = max(0.0, min(1.0, self.chroma_tolerance))
|
491 |
+
self.chroma_softness = max(0.0, min(1.0, self.chroma_softness))
|
492 |
+
|
493 |
+
# Validate motion detection
|
494 |
+
self.motion_threshold_percent = max(0.0, min(100.0, self.motion_threshold_percent))
|
495 |
+
self.motion_blur_kernel = max(1, min(99, self.motion_blur_kernel))
|
496 |
+
if self.motion_blur_kernel % 2 == 0:
|
497 |
+
self.motion_blur_kernel += 1
|
498 |
+
self.motion_min_area = max(0, self.motion_min_area)
|
499 |
+
|
500 |
+
# Validate stabilization
|
501 |
+
self.stabilize_smoothing = max(1.0, min(100.0, self.stabilize_smoothing))
|
502 |
+
self.stabilize_crop_percent = max(0.0, min(0.5, self.stabilize_crop_percent))
|
503 |
+
|
504 |
+
# Validate guided filter
|
505 |
+
self.guided_filter_radius = max(1, min(50, self.guided_filter_radius))
|
506 |
+
self.guided_filter_eps = max(0.0, min(1.0, self.guided_filter_eps))
|
507 |
+
self.grabcut_iterations = max(1, min(20, self.grabcut_iterations))
|
508 |
+
self.watershed_markers = max(2, min(100, self.watershed_markers))
|
509 |
+
|
510 |
+
# Validate frame sampling
|
511 |
+
self.sample_rate = max(1, self.sample_rate)
|
512 |
+
self.start_frame = max(0, self.start_frame)
|
513 |
+
self.process_every_nth_frame = max(1, self.process_every_nth_frame)
|
514 |
+
|
515 |
+
# Validate preview
|
516 |
+
self.preview_scale = max(0.1, min(2.0, self.preview_scale))
|
517 |
+
|
518 |
+
# Validate threading
|
519 |
+
self.num_threads = max(1, min(32, self.num_threads))
|
520 |
+
self.chunk_size = max(1, min(1000, self.chunk_size))
|
521 |
+
self.prefetch_frames = max(0, min(100, self.prefetch_frames))
|
522 |
+
|
523 |
+
# Validate memory
|
524 |
+
self.max_cache_size_mb = max(0, self.max_cache_size_mb)
|
525 |
+
self.clear_cache_interval = max(1, self.clear_cache_interval)
|
526 |
+
|
527 |
# Validate output settings
|
528 |
valid_formats = ['mp4', 'avi', 'mov', 'webm', 'mkv']
|
529 |
if self.output_format not in valid_formats:
|