mirror of
https://github.com/linyqh/NarratoAI.git
synced 2026-02-26 11:10:27 +00:00
feat(video_processor): 解决竖版视频解析出错;优化视频压缩处理
- 添加对横版和竖版视频的区分,使用不同的缩放比例 - 获取原始视频的宽度和高度,用于确定缩放比例 - 改进 FFmpeg 命令的执行,增加错误处理和日志记录
This commit is contained in:
parent
53b8cded04
commit
29d6107cd2
@ -212,7 +212,7 @@ class VideoProcessor:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
output_dir: 输出目录
|
output_dir: 输出目录
|
||||||
skip_seconds: 跳过视频开头的秒数
|
skip_seconds: 跳过视<EFBFBD><EFBFBD><EFBFBD>开头的秒数
|
||||||
"""
|
"""
|
||||||
skip_frames = int(skip_seconds * self.fps)
|
skip_frames = int(skip_seconds * self.fps)
|
||||||
|
|
||||||
@ -265,14 +265,30 @@ class VideoProcessor:
|
|||||||
video_name = os.path.splitext(os.path.basename(self.video_path))[0]
|
video_name = os.path.splitext(os.path.basename(self.video_path))[0]
|
||||||
compressed_video = os.path.join(compressed_dir, f"{video_name}_compressed.mp4")
|
compressed_video = os.path.join(compressed_dir, f"{video_name}_compressed.mp4")
|
||||||
|
|
||||||
|
# 获取原始视频的宽度和高度
|
||||||
|
original_width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
||||||
|
original_height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
||||||
|
|
||||||
logger.info("步骤1: 压缩视频...")
|
logger.info("步骤1: 压缩视频...")
|
||||||
|
if original_width > original_height:
|
||||||
|
# 横版视频
|
||||||
|
scale_filter = f'scale={compressed_width}:-1'
|
||||||
|
else:
|
||||||
|
# 竖版视频
|
||||||
|
scale_filter = f'scale=-1:{compressed_width}'
|
||||||
|
|
||||||
ffmpeg_cmd = [
|
ffmpeg_cmd = [
|
||||||
'ffmpeg', '-i', self.video_path,
|
'ffmpeg', '-i', self.video_path,
|
||||||
'-vf', f'scale={compressed_width}:-1',
|
'-vf', scale_filter,
|
||||||
'-y',
|
'-y',
|
||||||
compressed_video
|
compressed_video
|
||||||
]
|
]
|
||||||
subprocess.run(ffmpeg_cmd, check=True)
|
|
||||||
|
try:
|
||||||
|
subprocess.run(ffmpeg_cmd, check=True, capture_output=True, text=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logger.error(f"FFmpeg 错误输出: {e.stderr}")
|
||||||
|
raise
|
||||||
|
|
||||||
# 2. 从压缩视频中提取关键帧
|
# 2. 从压缩视频中提取关键帧
|
||||||
logger.info("\n步骤2: 从压缩视频提取关键帧...")
|
logger.info("\n步骤2: 从压缩视频提取关键帧...")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user