使用ffmpeg将文件夹下的avi转换为mp4

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')
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值