压缩视频

使用工具

ffmpeg

python

脚本如下

import os, sys

def MyCmd(cmd):
	print(cmd)
	#os.system(cmd)
	
def compress_video(infile, outfile):
	cmd = 'ffmpeg -i {} -b:v 1.5M  {}'.format(infile, outfile)
	MyCmd(cmd)
	
def ListFiles(folder):
	for i in os.listdir(folder):
		yield '%s\\%s'%(folder,i)
		

files_iter = ListFiles(r'E:\ljjshouji\DCIM\Camera')
video_files_iter = filter(lambda x:x.lower().endswith('.mp4') and not x.lower().endswith('_compressed.mp4') and os.path.isfile(x), files_iter)

def HandleAFile(x):
	des = '%s_compressed.mp4'%x
	if os.path.isfile(des):
		MyCmd('del %s'%x)
	else:
		compress_video(x, des)
		
list(map(HandleAFile, video_files_iter))

Powered by Jekyll and Theme by solid

本站总访问量