Files
zip-video/compress.py
becken e0759cc9e1 feat: 添加视频处理相关脚本
- 新增 VideoZip.py: 实现了一个简单的图形界面,用于选择文件夹并进行视频转换
- 新增 compress.py: 包含视频转换和文件列表获取功能
- 新增 video_image.py: 实现了视频截图和视频转换功能
- 在 .gitignore 中添加 .DS_Store 文件忽略项
2025-03-13 18:51:32 +08:00

47 lines
1.3 KiB
Python

import os
def convert(from_file, to_file):
command = (
"ffmpeg -i "
+ from_file
+ " -s 1280x720 -b:v 3M -vcodec h264 -r 29.97 -acodec aac -ab 48k -ac 2 "
+ to_file
)
os.system(command)
def get_file_list(fpath):
# 定义视频文件的常见扩展名
video_extensions = {".mp4", ".m4v", ".avi", ".mov", ".mkv", ".flv", ".wmv", ".webm"}
# 用来存储视频文件名的列表
video_files = []
dir_path = os.path.dirname(os.path.abspath(__file__))
base_path = dir_path + "/"
print(dir_path)
# 遍历指定目录
for root, dirs, files in os.walk(fpath):
for file in files:
# 获取文件扩展名
_, ext = os.path.splitext(file)
# 如果扩展名是视频格式,则添加到列表中
if ext.lower() in video_extensions:
from_file = "./in/"+file
name, ext = os.path.splitext(file)
to_file = "z_" + name + ".mp4"
convert(from_file, to_file)
# video_files.append(dir_path + "/" + file)
# return video_files
if __name__ == "__main__":
# 使用示例
directory = "./" # 请替换为你想要遍历的文件夹路径
get_file_list(directory)