fix: 场景检测
This commit is contained in:
parent
ca56349de0
commit
0b7e3fb07a
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
场景检测服务模块
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .types import (
|
||||||
|
DetectorType, SceneInfo, VideoSceneResult,
|
||||||
|
BatchDetectionConfig, BatchDetectionResult, DetectionStats
|
||||||
|
)
|
||||||
|
from .detector import SceneDetectionService
|
||||||
|
from .cli import SceneDetectionCommander
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
# 数据类型
|
||||||
|
"DetectorType",
|
||||||
|
"SceneInfo",
|
||||||
|
"VideoSceneResult",
|
||||||
|
"BatchDetectionConfig",
|
||||||
|
"BatchDetectionResult",
|
||||||
|
"DetectionStats",
|
||||||
|
|
||||||
|
# 服务
|
||||||
|
"SceneDetectionService",
|
||||||
|
|
||||||
|
# 命令行接口
|
||||||
|
"SceneDetectionCommander"
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
场景检测相关的数据类型定义
|
||||||
|
"""
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import List, Optional
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
class DetectorType(Enum):
|
||||||
|
"""检测器类型"""
|
||||||
|
CONTENT = "content"
|
||||||
|
THRESHOLD = "threshold"
|
||||||
|
ADAPTIVE = "adaptive"
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class SceneInfo:
|
||||||
|
"""场景信息"""
|
||||||
|
index: int
|
||||||
|
start_time: float
|
||||||
|
end_time: float
|
||||||
|
duration: float
|
||||||
|
confidence: float = 0.0
|
||||||
|
frame_count: int = 0
|
||||||
|
thumbnail_path: Optional[str] = None
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class VideoSceneResult:
|
||||||
|
"""单个视频的场景检测结果"""
|
||||||
|
video_path: str
|
||||||
|
filename: str
|
||||||
|
success: bool
|
||||||
|
total_scenes: int
|
||||||
|
total_duration: float
|
||||||
|
scenes: List[SceneInfo]
|
||||||
|
detection_time: float
|
||||||
|
detector_type: str
|
||||||
|
threshold: float
|
||||||
|
error: Optional[str] = None
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BatchDetectionConfig:
|
||||||
|
"""批量检测配置"""
|
||||||
|
detector_type: DetectorType = DetectorType.CONTENT
|
||||||
|
threshold: float = 30.0
|
||||||
|
min_scene_length: float = 1.0
|
||||||
|
adaptive_threshold: bool = False
|
||||||
|
generate_thumbnails: bool = False
|
||||||
|
output_format: str = "json" # json, csv, txt
|
||||||
|
save_scenes: bool = False
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BatchDetectionResult:
|
||||||
|
"""批量检测结果"""
|
||||||
|
total_files: int
|
||||||
|
processed_files: int
|
||||||
|
failed_files: int
|
||||||
|
total_scenes: int
|
||||||
|
total_duration: float
|
||||||
|
average_scenes_per_video: float
|
||||||
|
detection_time: float
|
||||||
|
results: List[VideoSceneResult]
|
||||||
|
failed_list: List[dict]
|
||||||
|
config: BatchDetectionConfig
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class DetectionStats:
|
||||||
|
"""检测统计信息"""
|
||||||
|
total_videos: int
|
||||||
|
total_scenes: int
|
||||||
|
total_duration: float
|
||||||
|
average_duration_per_scene: float
|
||||||
|
shortest_scene: float
|
||||||
|
longest_scene: float
|
||||||
|
most_scenes_video: str
|
||||||
|
least_scenes_video: str
|
||||||
|
|
@ -69,7 +69,7 @@ pub async fn get_segments_by_video_id(app: AppHandle, video_id: String) -> Resul
|
||||||
pub async fn upload_video_file(app: AppHandle, request: UploadVideoRequest) -> Result<String, String> {
|
pub async fn upload_video_file(app: AppHandle, request: UploadVideoRequest) -> Result<String, String> {
|
||||||
let mut args = vec![
|
let mut args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"upload_video_file".to_string(),
|
"upload_video_file".to_string(),
|
||||||
request.source_path,
|
request.source_path,
|
||||||
];
|
];
|
||||||
|
|
@ -96,7 +96,7 @@ pub async fn upload_video_file(app: AppHandle, request: UploadVideoRequest) -> R
|
||||||
pub async fn batch_upload_video_files(app: AppHandle, request: BatchUploadVideoRequest) -> Result<String, String> {
|
pub async fn batch_upload_video_files(app: AppHandle, request: BatchUploadVideoRequest) -> Result<String, String> {
|
||||||
let mut args = vec![
|
let mut args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"batch_upload_video_files".to_string(),
|
"batch_upload_video_files".to_string(),
|
||||||
request.source_directory,
|
request.source_directory,
|
||||||
];
|
];
|
||||||
|
|
@ -120,7 +120,7 @@ pub async fn add_segment_tags(app: AppHandle, request: TagsRequest) -> Result<St
|
||||||
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"add_segment_tags".to_string(),
|
"add_segment_tags".to_string(),
|
||||||
request.segment_id,
|
request.segment_id,
|
||||||
tags_json,
|
tags_json,
|
||||||
|
|
@ -137,7 +137,7 @@ pub async fn remove_segment_tags(app: AppHandle, request: TagsRequest) -> Result
|
||||||
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"remove_segment_tags".to_string(),
|
"remove_segment_tags".to_string(),
|
||||||
request.segment_id,
|
request.segment_id,
|
||||||
tags_json,
|
tags_json,
|
||||||
|
|
@ -151,7 +151,7 @@ pub async fn remove_segment_tags(app: AppHandle, request: TagsRequest) -> Result
|
||||||
pub async fn increment_segment_usage(app: AppHandle, segment_id: String) -> Result<String, String> {
|
pub async fn increment_segment_usage(app: AppHandle, segment_id: String) -> Result<String, String> {
|
||||||
let args = vec![
|
let args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"increment_segment_usage".to_string(),
|
"increment_segment_usage".to_string(),
|
||||||
segment_id,
|
segment_id,
|
||||||
];
|
];
|
||||||
|
|
@ -170,7 +170,7 @@ pub async fn get_segments_by_tags(app: AppHandle, request: SearchTagsRequest) ->
|
||||||
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"get_segments_by_tags".to_string(),
|
"get_segments_by_tags".to_string(),
|
||||||
tags_json,
|
tags_json,
|
||||||
match_all_json,
|
match_all_json,
|
||||||
|
|
@ -184,7 +184,7 @@ pub async fn get_segments_by_tags(app: AppHandle, request: SearchTagsRequest) ->
|
||||||
pub async fn get_popular_segments(app: AppHandle, limit: Option<i32>) -> Result<String, String> {
|
pub async fn get_popular_segments(app: AppHandle, limit: Option<i32>) -> Result<String, String> {
|
||||||
let mut args = vec![
|
let mut args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"get_popular_segments".to_string(),
|
"get_popular_segments".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -200,7 +200,7 @@ pub async fn get_popular_segments(app: AppHandle, limit: Option<i32>) -> Result<
|
||||||
pub async fn search_segments(app: AppHandle, keyword: String) -> Result<String, String> {
|
pub async fn search_segments(app: AppHandle, keyword: String) -> Result<String, String> {
|
||||||
let args = vec![
|
let args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"pypython_core.services.media_manager.cli".to_string(),
|
||||||
"search_segments".to_string(),
|
"search_segments".to_string(),
|
||||||
keyword,
|
keyword,
|
||||||
];
|
];
|
||||||
|
|
@ -213,7 +213,7 @@ pub async fn search_segments(app: AppHandle, keyword: String) -> Result<String,
|
||||||
pub async fn delete_segment(app: AppHandle, segment_id: String) -> Result<String, String> {
|
pub async fn delete_segment(app: AppHandle, segment_id: String) -> Result<String, String> {
|
||||||
let args = vec![
|
let args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"delete_segment".to_string(),
|
"delete_segment".to_string(),
|
||||||
segment_id,
|
segment_id,
|
||||||
];
|
];
|
||||||
|
|
@ -226,7 +226,7 @@ pub async fn delete_segment(app: AppHandle, segment_id: String) -> Result<String
|
||||||
pub async fn delete_original_video(app: AppHandle, video_id: String) -> Result<String, String> {
|
pub async fn delete_original_video(app: AppHandle, video_id: String) -> Result<String, String> {
|
||||||
let args = vec![
|
let args = vec![
|
||||||
"-m".to_string(),
|
"-m".to_string(),
|
||||||
"python_core.services.media_manager".to_string(),
|
"python_core.services.media_manager.cli".to_string(),
|
||||||
"delete_original_video".to_string(),
|
"delete_original_video".to_string(),
|
||||||
video_id,
|
video_id,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue