#!/usr/bin/env python3 """ 视频导出功能测试脚本 测试 video_cutter.py 的各项功能 """ import sys import os # 添加当前目录到 Python 路径 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from video_cutter import parse_image_info, find_video_file, export_video_clip def test_parse_image_info(): """测试图片名解析功能""" print("=" * 60) print("测试图片名解析功能") print("=" * 60) test_cases = [ ("001 Puss Gets the Boot [1940]_05m23s_456.jpg", True), ("002 The Midnight Snack [1941]_02m15s_123.jpg", True), ("003 The Night Before Christmas [1941]_00m00s_000.jpg", True), ("invalid_image.jpg", False), ("no_timestamp.jpg", False), ] for image_name, expected in test_cases: result = parse_image_info(image_name) success = (result is not None) == expected status = "✅" if success else "❌" print(f"\n{status} {image_name}") if result: print(f" 视频名: {result['video_name']}") print(f" 时间点: {result['timestamp_seconds']:.3f}秒") else: print(f" 解析失败") return True def test_find_video_file(): """测试视频文件查找功能""" print("\n" + "=" * 60) print("测试视频文件查找功能") print("=" * 60) test_cases = [ "001 Puss Gets the Boot [1940]", "002 The Midnight Snack [1941]", "nonexistent_video", ] for video_name in test_cases: result = find_video_file(video_name) status = "✅" if result else "❌" print(f"\n{status} {video_name}") if result: print(f" 找到: {result}") else: print(f" 未找到") return True def test_export_video_clip(): """测试视频导出功能""" print("\n" + "=" * 60) print("测试视频导出功能") print("=" * 60) # 测试用例 test_cases = [ { "image_name": "001 Puss Gets the Boot [1940]_05m23s_456.jpg", "mode": "around", "seconds": 120, "description": "前后各2分钟" }, { "image_name": "001 Puss Gets the Boot [1940]_05m23s_456.jpg", "mode": "after", "seconds": 180, "description": "后3分钟" }, { "image_name": "001 Puss Gets the Boot [1940]_05m23s_456.jpg", "mode": "before", "seconds": 60, "description": "前1分钟" }, { "image_name": "001 Puss Gets the Boot [1940]_05m23s_456.jpg", "mode": "total", "seconds": 0, "description": "整个视频" }, ] for i, case in enumerate(test_cases, 1): print(f"\n测试 {i}: {case['description']}") print(f" 图片: {case['image_name']}") print(f" 模式: {case['mode']}") print(f" 秒数: {case['seconds']}") result = export_video_clip( image_name=case['image_name'], mode=case['mode'], seconds=case['seconds'] ) if result['success']: print(f" ✅ 导出成功") print(f" 📁 文件: {result['video_path']}") print(f" ⏱️ 时间: {result['start_time']} -> {result['end_time']}") print(f" 🎬 时长: {result['duration']}") else: print(f" ❌ 导出失败: {result['error']}") return True def main(): """主测试函数""" print("视频导出功能测试") print("=" * 60) # 测试解析功能 test_parse_image_info() # 测试查找功能 test_find_video_file() # 询问是否测试导出功能 print("\n" + "=" * 60) print("注意:视频导出测试需要:") print(" 1. 安装 ffmpeg") print(" 2. 存在对应的视频文件") print("=" * 60) response = input("\n是否测试视频导出功能?(y/n): ").strip().lower() if response == 'y': test_export_video_clip() print("\n" + "=" * 60) print("测试完成!") print("=" * 60) if __name__ == "__main__": main()