feat: 添加视频处理相关脚本
- 新增 VideoZip.py: 实现了一个简单的图形界面,用于选择文件夹并进行视频转换 - 新增 compress.py: 包含视频转换和文件列表获取功能 - 新增 video_image.py: 实现了视频截图和视频转换功能 - 在 .gitignore 中添加 .DS_Store 文件忽略项
This commit is contained in:
74
video_image.py
Normal file
74
video_image.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# encoding: utf-8
|
||||
# 视频截图的python文件
|
||||
import os
|
||||
import re
|
||||
import subprocess as sp
|
||||
import sys
|
||||
|
||||
|
||||
|
||||
p1 = '[\u4e00-\u9fa5_a-zA-Z0-9]*.mp4'
|
||||
p2 = '([\u4e00-\u9fa5_a-zA-Z0-9]*.)*((mp4)|(MP4)|(mov)|(MOV)|(m4v)|(M4V)|(mpg)|(MPG))'
|
||||
pattern1 = re.compile(p1)
|
||||
pattern2 = re.compile(p2)
|
||||
|
||||
|
||||
|
||||
runpath = os.path.dirname(os.path.realpath(__file__))
|
||||
#sys.path[0]
|
||||
|
||||
def runCommend(commend):
|
||||
f = os.popen(commend)
|
||||
for i in f.readlines():
|
||||
pass
|
||||
# print(i)
|
||||
print('run complite')
|
||||
|
||||
def get_image_from_video(file_path, file_name):
|
||||
print('into \" get_image_from_video \" function')
|
||||
print(file_name, file_path)
|
||||
video_path = file_path + '/'
|
||||
video_name = file_name
|
||||
image_path = file_path + '/'
|
||||
image_name = file_name[:-4] + '.jpg'
|
||||
comm = 'ffmpeg -i ' + video_path + video_name + ' -ss 1 -f image2 ' + image_path + image_name
|
||||
runCommend(comm)
|
||||
|
||||
|
||||
|
||||
def conver_video(file_path, file_name):
|
||||
input_path = file_path + '/'
|
||||
input_name = file_name
|
||||
output_path = file_path + '/'
|
||||
output_name = ""
|
||||
sp_input_name = file_name.split('.')
|
||||
ext_pos = len(sp_input_name) - 1
|
||||
print('---------------' + sp_input_name[ext_pos])
|
||||
output_name = 'z_' + file_name[:-4] + '.mp4'
|
||||
# if sp_input_name[ext_pos] == 'mp4':
|
||||
# output_name = file_name[:-4] + '_z.mp4'
|
||||
# else:
|
||||
# output_name = file_name[:-4] + '.mp4'
|
||||
|
||||
comm = 'ffmpeg -i \'' + input_path + input_name + '\' -r 60 -vcodec libx264 -tune film -b:v 6M -fs 200MB -s 1920*1080 \'' + output_path + output_name + '\''
|
||||
# comm = 'ffmpeg -i \'' + input_path + input_name + '\' -vcodec libx264 \'' + output_path + output_name + '\''
|
||||
runCommend(comm)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv
|
||||
|
||||
list = os.listdir(args[1]) # 列出文件夹下所有的目录与文件
|
||||
for i in range(0, len(list)):
|
||||
print('----------------------------')
|
||||
path = os.path.join(args[1], list[i])
|
||||
if os.path.isfile(path):
|
||||
print('FileName: ' + list[i])
|
||||
matcher1 = re.search(pattern2, list[i])
|
||||
if matcher1 != None:
|
||||
# get_image_from_video(args[1], list[i])
|
||||
conver_video(args[1], list[i])
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user