1. 第一种方法
电脑下载安装ffmpeg
然后代码如下
python
from moviepy.editor import VideoFileClip
import os
import ffmpeg
def convert_video_to_mp4(input_video_path, output_video_path):
'''
速度慢, CPU狂飙
:param input_video_path:
:param output_video_path:
:return:
'''
video_clip = VideoFileClip(input_video_path)
video_clip.write_videofile(output_video_path, codec='libx264', audio_codec='aac')
# 速度快
def covert_mkv_to_mp4(input_video_path, output_video_path):
'''
速度快,
:param input_video_path:
:param output_video_path:
:return:
'''
ffmpeg.input(input_file).output(output_file, vcodec='copy', acodec='copy').run()
2 第二种方法
直接改后缀,就可以播放了...
这种方法真的是太简单了...
python
filepath = '文件目录'
files = os.listdir(filepath)
for file in files:
if file.find("mkv") > 0:
oldname = os.path.join(filepath,file)
file = file.replace('mkv','mp4')
newname = os.path.join(filepath,file)
os.rename(oldname,newname)