fix
This commit is contained in:
parent
f516e5a403
commit
8474e5004b
|
|
@ -292,11 +292,31 @@ class PySceneDetectSceneDetector(SceneDetector):
|
|||
|
||||
# 如果没有检测到场景变化,添加视频结束时间
|
||||
if len(scene_changes) == 1: # 只有开始时间0.0
|
||||
# 获取视频时长
|
||||
video_duration = video_manager.get_duration().get_seconds()
|
||||
if video_duration > 0:
|
||||
scene_changes.append(video_duration)
|
||||
logger.info(f"No scenes detected, using full video duration: {video_duration:.2f}s")
|
||||
# 获取视频时长 - 处理不同的返回类型
|
||||
try:
|
||||
duration_obj = video_manager.get_duration()
|
||||
if hasattr(duration_obj, 'get_seconds'):
|
||||
video_duration = duration_obj.get_seconds()
|
||||
elif isinstance(duration_obj, (tuple, list)) and len(duration_obj) >= 2:
|
||||
# 如果是tuple,通常格式是 (frames, fps)
|
||||
frames, fps = duration_obj[0], duration_obj[1]
|
||||
video_duration = frames / fps if fps > 0 else 0
|
||||
elif isinstance(duration_obj, (int, float)):
|
||||
video_duration = float(duration_obj)
|
||||
else:
|
||||
# 回退方案:从文件路径获取时长
|
||||
video_duration = self._get_video_duration_fallback(file_path)
|
||||
|
||||
if video_duration > 0:
|
||||
scene_changes.append(video_duration)
|
||||
logger.info(f"No scenes detected, using full video duration: {video_duration:.2f}s")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to get video duration from PySceneDetect: {e}")
|
||||
# 回退方案:从文件路径获取时长
|
||||
video_duration = self._get_video_duration_fallback(file_path)
|
||||
if video_duration > 0:
|
||||
scene_changes.append(video_duration)
|
||||
logger.info(f"Using fallback video duration: {video_duration:.2f}s")
|
||||
|
||||
scene_changes = sorted(list(set(scene_changes)))
|
||||
video_manager.release()
|
||||
|
|
@ -310,6 +330,16 @@ class PySceneDetectSceneDetector(SceneDetector):
|
|||
logger.error(f"PySceneDetect failed: {e}")
|
||||
raise
|
||||
|
||||
def _get_video_duration_fallback(self, file_path: str) -> float:
|
||||
"""获取视频时长的回退方案"""
|
||||
try:
|
||||
# 使用视频信息提取器获取时长
|
||||
video_info = self.video_info_extractor.extract_video_info(file_path)
|
||||
return video_info.get('duration', 0.0)
|
||||
except Exception as e:
|
||||
logger.warning(f"Fallback duration extraction failed: {e}")
|
||||
return 0.0
|
||||
|
||||
class OpenCVSceneDetector(SceneDetector):
|
||||
"""使用OpenCV进行场景检测"""
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue