import subprocess
def convert_videos_to_mp4(source_directory, target_directory):
# 定义支持的视频文件扩展名
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv']
# 确保目标文件夹存在,如果不存在,创建它
if not os.path.exists(target_directory):
os.makedirs(target_directory)
# 遍历指定目录
for filename in os.listdir(source_directory):
# 检查文件扩展名是否在支持的列表中
if any(filename.endswith(ext) for ext in video_extensions):
full_path = os.path.join(source_directory, filename)
target_path = os.path.join(target_directory, os.path.splitext(filename)[0] + '.mp4')
# 使用ffmpeg命令行工具转换视频格式
command = ['ffmpeg', '-i', full_path, '-codec:v', 'libx264', '-codec:a', 'aac', target_path]
subprocess.run(command)
print("视频转换完成。")
# 使用示例,替换'source_directory'为你的视频文件夹路径,'target_directory'为目标文件夹路径
convert_videos_to_mp4('video_features-master/BEOID', 'video_features-master/BEOID_mp4')
01-15
1906
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交