67 lines
2.5 KiB
Python
Raw Normal View History

import os
from datetime import datetime
from pathlib import Path
# video_path = "/root/autodl-tmp/video_processed/广州广之旅国际旅行社股份有限公司/广州广之旅国际旅行社股份有限公司/"
# print(os.path.splitext(os.path.basename(video_path))[0])
# save_dir="/root/autodl-tmp/video_llm"
# os.makedirs(save_dir, exist_ok=True)
# # 生成文件名(基于视频文件名和时间戳)
# video_name = os.path.splitext(os.path.basename(video_path))[0]
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
# txt_filename = f"tokens_{video_name}_{timestamp}.txt"
# txt_path = os.path.join(save_dir, "cost/" , video_name, txt_filename)
# print(txt_path)
def find_videos_from_processed_structure(input_path):
"""从video_processed结构中查找视频文件"""
video_files = []
for video_dir in input_path.iterdir():
if not video_dir.is_dir():
continue
video_split_dir = video_dir / "video_split"
if not video_split_dir.exists():
continue
# 从video_split目录中查找视频文件
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm']
for ext in video_extensions:
video_files.extend(video_split_dir.glob(f"*{ext}"))
video_files.extend(video_split_dir.glob(f"*{ext.upper()}"))
return video_files
def find_video_dirs(video_split_dir):
"""查找video_split目录中的所有视频文件名不含扩展名"""
video_split_path = Path(video_split_dir)
video_names = []
# 检查目录是否存在
if not video_split_path.exists():
print(f"目录不存在: {video_split_path}")
return []
# 查找视频文件
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm']
for ext in video_extensions:
video_files = list(video_split_path.glob(f"*{ext}"))
video_files.extend(list(video_split_path.glob(f"*{ext.upper()}")))
video_names.extend([video_file.stem for video_file in video_files])
print(f"找到 {len(video_names)} 个视频文件: {video_names}")
return video_names
# 测试查找整个video_processed结构
input_path = "/root/autodl-tmp/video_processed/"
a = find_videos_from_processed_structure(Path(input_path))
print("整个结构中的视频文件:", a)
# 测试查找单个video_split目录
video_split_path = "/root/autodl-tmp/video_processed/新疆中国国际旅行社/video_split/"
b = find_video_dirs(video_split_path)
print("video_split目录中的视频文件:", b)