- 批量将avi格式的视频转换为mp4格式
import os
from moviepy.editor import VideoFileClip
video_folder = r'视频文件路径'
avi_files = [f for f in os.listdir(video_folder) if f.endswith('.avi')]
for avi_file in avi_files:
avi_path = os.path.join(video_folder, avi_file)
mp4_path = os.path.join(video_folder, avi_file.rsplit('.', 1)[0] + '.mp4')
avi_clip = VideoFileClip(avi_path)
avi_clip.write_videofile(mp4_path, codec='libx264')
avi_clip.close()
print("转换完成")
- 将avi格式的视频转换mp4格式
import os
from moviepy.editor import VideoFileClip
avi_file_path = r'你的AVI视频文件路径.avi'
mp4_file_path = os.path.splitext(avi_file_path)[0] + '.mp4'
avi_clip = VideoFileClip(avi_file_path)
avi_clip.write_videofile(mp4_file_path, codec='libx264')
print("转换完成")