fix: 修复批量处理中图片文件重复计数问题

- 替换glob模式匹配为直接文件系统遍历
- 避免在大小写不敏感文件系统上的重复匹配
- 添加更好的错误处理和调试日志
- 确保图片计数准确性

修复了Windows系统上同一图片文件被计数两次的问题
This commit is contained in:
root 2025-07-10 19:47:17 +08:00
parent 8f0cbe7995
commit 168ad4dafa
1 changed files with 24 additions and 6 deletions

View File

@ -245,19 +245,37 @@ class VideoGenerator:
progress_callback(f" 模型类型: {model_type}")
# Find image files
image_extensions = ['*.jpg', '*.jpeg', '*.png', '*.bmp', '*.gif', '*.tiff', '*.webp']
# Use a more robust approach to find image files
image_extensions = ['.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.webp']
image_files = []
for ext in image_extensions:
image_files.extend(glob.glob(os.path.join(image_folder, ext)))
image_files.extend(glob.glob(os.path.join(image_folder, ext.upper())))
# Get all files in the directory
try:
all_files = os.listdir(image_folder)
for file in all_files:
file_path = os.path.join(image_folder, file)
if os.path.isfile(file_path):
# Check if file extension matches (case-insensitive)
file_ext = os.path.splitext(file)[1].lower()
if file_ext in image_extensions:
image_files.append(file_path)
except OSError as e:
result['msg'] = f"Failed to read directory {image_folder}: {str(e)}"
logger.error(result['msg'])
return result
if not image_files:
result['msg'] = f"No image files found in {image_folder}"
logger.error(result['msg'])
return result
if progress_callback:
progress_callback(f'目录下找到 {len(image_files)} 张图片')
# Debug: log found image files
logger.info(f"Found {len(image_files)} image files in {image_folder}")
for i, img_file in enumerate(image_files):
logger.info(f" {i+1}. {os.path.basename(img_file)}")
if not prompts:
result['msg'] = "No prompts provided"