Python数据处理——WAV视频格式转MP4格式

from moviepy.editor import VideoFileClip
import os


def convert_to_mp4(input_path, output_path):
    try:
        # Load the video clip from the input_path
        clip = VideoFileClip(input_path)

        # Set the output path with .mp4 extension
        output_path_with_mp4 = os.path.splitext(output_path)[0] + ".mp4"

        # Convert and save the video clip to mp4 format
        clip.write_videofile(output_path_with_mp4, codec='libx264')

        print(f"Successfully converted {input_path} to {output_path_with_mp4}")
    except Exception as e:
        print(f"Error converting {input_path}: {str(e)}")


def batch_convert_to_mp4(input_folder, output_folder):
    # Ensure output folder exists
    os.makedirs(output_folder, exist_ok=True)

    # Loop through all files in the input folder
    for file_name in os.listdir(input_folder):
        input_path = os.path.join(input_folder, file_name)

        # Check if the file is a wav video
        if file_name.lower().endswith(".wav"):
            # Set the output path with .mp4 extension
            output_path = os.path.join(output_folder, os.path.splitext(file_name)[0] + ".mp4")
            convert_to_mp4(input_path, output_path)


if __name__ == "__main__":
    input_folder = "D:\\dataset\\Mirror\\Female_mirror"  # Replace with the path to your folder containing wav videos
    output_folder = "D:\\dataset\\Mirror\\Female_pic"  # Replace with the path where you want to save mp4 videos
    batch_convert_to_mp4(input_folder, output_folder)

   

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值