34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
|
# coding=utf-8
|
|||
|
|
|||
|
import os
|
|||
|
|
|||
|
input_dir = 'Video/'
|
|||
|
output_dir = '../Output_Video'
|
|||
|
|
|||
|
# 如果没有Output_Video这个文件夹,则创建这个文件夹
|
|||
|
if not os.path.exists(output_dir):
|
|||
|
os.mkdir(output_dir)
|
|||
|
|
|||
|
|
|||
|
class VideoConverter(object):
|
|||
|
def __init__(self):
|
|||
|
self.input_video_path = input_dir
|
|||
|
self.new_resolution = "640x480"
|
|||
|
self.new_fps = "10"
|
|||
|
self.output_video_path = output_dir
|
|||
|
|
|||
|
def convert_video(self):
|
|||
|
input_video_list = os.listdir(input_dir)
|
|||
|
for each_video in input_video_list:
|
|||
|
video_name, _ = os.path.splitext(each_video) # _是占坑符
|
|||
|
input_video_path = input_dir + os.sep + each_video
|
|||
|
output_video_path = output_dir + os.sep + video_name + ".mp4"
|
|||
|
ffmpeg_command = ("ffmpeg -i %s -s %s -r %s -y %s" % (input_video_path, self.new_resolution, self.new_fps, output_video_path))
|
|||
|
os.system(ffmpeg_command)
|
|||
|
os.system("pause")
|
|||
|
|
|||
|
|
|||
|
if __name__ == '__main__':
|
|||
|
v_obj = VideoConverter()
|
|||
|
v_obj.convert_video()
|