定义坐标版本
import os import subprocess input_dir = "/Users/gd/Downloads/videos" output_dir = "/Users/gd/Downloads/videos/directory" # 创建输出目录 os.makedirs(output_dir, exist_ok=True) for file in os.listdir(input_dir): if file.endswith(".mp4"): input_file = os.path.join(input_dir, file) output_file = os.path.join( output_dir, file.replace(".mp4", ".mp4") ) # 剪切的起始坐标 x = 0 y = 500 # 请根据实际需求调整 # FFmpeg命令 ffmpeg_command = [ "ffmpeg", "-i", input_file, "-vf", f"scale=1920:-1, crop=1920:1680:{x}:{y}", "-c:a", "copy", output_file, ] # 执行FFmpeg命令 subprocess.run(ffmpeg_command) print("Conversion completed.") # debug # ffmpeg -i input_video.mp4 -vf "scale=1920:-1, crop=1920:1680:0:500" -c:a copy output_video.mp4
拉伸版本
import os import subprocess input_dir = r"D:\Work_Tools\16x9\研究室" output_dir = r"D:\Work_Tools\16x9\研究室1920x1080" # 创建输出目录 os.makedirs(output_dir, exist_ok=True) for file in os.listdir(input_dir): if file.endswith(".mp4"): input_file = os.path.join(input_dir, file) output_file = os.path.join( output_dir, file.replace(".mp4", ".mp4") ) # 剪切的起始坐标 #x = 0 #y = 500 # 请根据实际需求调整 # FFmpeg命令 ffmpeg_command = [ "ffmpeg", "-i", input_file, "-vf", f"scale=1920:1080, crop=1080:1080", "-c:a", "copy", "-c:v", "libx264", "-c:a", "libmp3lame", "-y", output_file, ] # 执行FFmpeg命令 subprocess.run(ffmpeg_command) print("Conversion completed.") # debug # ffmpeg -i input_video.mp4 -vf "scale=1920:1080, crop=1920:1680" -c:a copy output_video.mp4
取中版本
import os import subprocess input_dir = r"D:\CRVideoMate Output\研究室" output_dir = r"D:\Work_Tools\16x9\研究室" # 创建输出目录 os.makedirs(output_dir, exist_ok=True) for file in os.listdir(input_dir): if file.endswith(".mp4"): input_file = os.path.join(input_dir, file) output_file = os.path.join( output_dir, file.replace(".mp4", ".mp4") ) # 剪切的起始坐标 #x = 0 #y = 500 # 请根据实际需求调整 # FFmpeg命令 ffmpeg_command = [ "ffmpeg", "-i", input_file, "-vf", f"scale=1920:-1, crop=1920:780", "-c:a", "copy", "-y", output_file, ] # 执行FFmpeg命令 subprocess.run(ffmpeg_command) print("Conversion completed.") # debug # ffmpeg -i input_video.mp4 -vf "scale=1920:-1, crop=1920:1680:0:500" -c:a copy output_video.mp4