ffmpeg批量压缩转换视频为30FPS
ffmpeg批量转换为小视频 有些时候我们需要批量压缩文件夹里面的视频,这时候我们就能使用python来对ffmpeg进行自动操控实现批量转视频,本脚本仅在termux上面使用过 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import os import subprocess import shlex script_dir = os.path.dirname(os.path.realpath(__file__)) video_dir = script_dir for root, dirs, files in os.walk(video_dir): for video in files: if video.endswith('.mp4'): filename, ext = os.path.splitext(video) out_file1 = filename + '_1' + ext cmd1 = f'ffmpeg -i {shlex.quote(os.path.join(root, video))} -g 90 -b:v 2000k -bufsize 2000k -maxrate 2500k {shlex.quote(os.path.join(root, out_file1))}' subprocess.run(cmd1, shell=True) out_file2 = filename + '_2' + ext cmd2 = f'ffmpeg -i {shlex.quote(os.path.join(root, out_file1))} -g 90 -r 30 {shlex.quote(os.path.join(root, out_file2))}' subprocess.run(cmd2, shell=True) os.remove(os.path.join(root, out_file1)) print('Done!') 使用方法 安装ffmpeg和python3运行即可
以上内容来自博客订阅源,版权归原作者。关注作者后可以在 关注列表 第一时间查看作者文章。

登录后,加入这场讨论。
登录参与