本文目录导读:

我来介绍几种批量调整视频分辨率的方法,包括使用FFmpeg、Python脚本以及一些图形界面工具。
使用FFmpeg(推荐)
基础批量处理脚本
Windows(batch脚本):
@echo off
set INPUT_DIR=.\input_videos
set OUTPUT_DIR=.\output_videos
set WIDTH=1920
set HEIGHT=1080
mkdir %OUTPUT_DIR% 2>nul
for %%i in (%INPUT_DIR%\*.mp4) do (
ffmpeg -i "%%i" -vf "scale=%WIDTH%:%HEIGHT%" -c:a copy "%OUTPUT_DIR%\%%~ni_resized.mp4"
)
Linux/macOS(bash脚本):
#!/bin/bash
INPUT_DIR="./input_videos"
OUTPUT_DIR="./output_videos"
WIDTH=1920
HEIGHT=1080
mkdir -p "$OUTPUT_DIR"
for file in "$INPUT_DIR"/*.mp4; do
filename=$(basename "$file")
ffmpeg -i "$file" -vf "scale=$WIDTH:$HEIGHT" -c:a copy "$OUTPUT_DIR/${filename%.*}_resized.mp4"
done
保持比例的缩放
# 设置固定宽度,高度自动计算 ffmpeg -i input.mp4 -vf "scale=1920:-2" output.mp4 # 设置固定高度,宽度自动计算 ffmpeg -i input.mp4 -vf "scale=-2:1080" output.mp4 # 限制最大尺寸 ffmpeg -i input.mp4 -vf "scale='min(1920,iw)':'min(1080,ih)':force_original_aspect_ratio=decrease" output.mp4
Python脚本(更灵活)
安装依赖
pip install opencv-python ffmpeg-python
批量处理脚本
import os
import ffmpeg
from pathlib import Path
def batch_resize_videos(input_dir, output_dir, target_width=1920, target_height=1080):
"""
批量调整视频分辨率
Args:
input_dir: 输入视频目录
output_dir: 输出视频目录
target_width: 目标宽度
target_height: 目标高度
"""
# 创建输出目录
Path(output_dir).mkdir(parents=True, exist_ok=True)
# 支持的视频格式
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.webm']
# 遍历输入目录
for file in Path(input_dir).iterdir():
if file.suffix.lower() in video_extensions:
input_path = str(file)
output_path = os.path.join(output_dir, f"{file.stem}_resized{file.suffix}")
try:
# 使用ffmpeg-python处理
stream = ffmpeg.input(input_path)
stream = ffmpeg.filter(stream, 'scale', target_width, target_height)
stream = ffmpeg.output(stream, output_path)
ffmpeg.run(stream, overwrite_output=True)
print(f"✓ 完成: {file.name}")
except Exception as e:
print(f"✗ 失败: {file.name} - {str(e)}")
# 使用示例
if __name__ == "__main__":
batch_resize_videos(
input_dir="./videos",
output_dir="./resized_videos",
target_width=1920,
target_height=1080
)
高级版:带选项的脚本
import os
import subprocess
from pathlib import Path
import argparse
class VideoResizer:
def __init__(self, input_dir, output_dir, width, height,
maintain_aspect=True, quality='high'):
self.input_dir = Path(input_dir)
self.output_dir = Path(output_dir)
self.width = width
self.height = height
self.maintain_aspect = maintain_aspect
self.quality = quality
# 质量预设
self.quality_presets = {
'high': '-crf 18',
'medium': '-crf 23',
'low': '-crf 28'
}
def get_scale_filter(self, orig_width, orig_height):
"""生成缩放滤镜"""
if self.maintain_aspect:
# 计算缩放比例,保持宽高比
scale_w = self.width / orig_width
scale_h = self.height / orig_height
scale = min(scale_w, scale_h)
new_width = int(orig_width * scale)
new_height = int(orig_height * scale)
return f"scale={new_width}:{new_height}"
else:
return f"scale={self.width}:{self.height}"
def resize_video(self, input_path, output_path):
"""调整单个视频"""
# 获取原始视频信息
probe = subprocess.run([
'ffprobe', '-v', 'error',
'-select_streams', 'v:0',
'-show_entries', 'stream=width,height',
'-of', 'csv=p=0',
str(input_path)
], capture_output=True, text=True)
try:
orig_width, orig_height = map(int, probe.stdout.strip().split(','))
scale_filter = self.get_scale_filter(orig_width, orig_height)
# 构建FFmpeg命令
cmd = [
'ffmpeg', '-i', str(input_path),
'-vf', scale_filter,
'-c:a', 'copy',
self.quality_presets.get(self.quality, '-crf 23'),
'-y',
str(output_path)
]
# 执行命令
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
print(f"✓ {input_path.name}")
return True
else:
print(f"✗ {input_path.name}: {result.stderr}")
return False
except Exception as e:
print(f"✗ {input_path.name}: {str(e)}")
return False
def batch_process(self):
"""批量处理所有视频"""
# 创建输出目录
self.output_dir.mkdir(parents=True, exist_ok=True)
# 支持的格式
extensions = ['.mp4', '.avi', '.mov', '.mkv', '.webm', '.flv']
# 获取所有视频文件
video_files = []
for ext in extensions:
video_files.extend(self.input_dir.glob(f"*{ext}"))
if not video_files:
print("未找到视频文件")
return
print(f"找到 {len(video_files)} 个视频文件")
print(f"目标分辨率: {self.width}x{self.height}")
print("-" * 50)
# 批量处理
success = 0
fail = 0
for video in video_files:
output_path = self.output_dir / f"{video.stem}_resized{video.suffix}"
if self.resize_video(video, output_path):
success += 1
else:
fail += 1
# 显示统计信息
print("-" * 50)
print(f"处理完成: {success} 成功, {fail} 失败")
def main():
parser = argparse.ArgumentParser(description='批量调整视频分辨率')
parser.add_argument('-i', '--input', required=True, help='输入目录')
parser.add_argument('-o', '--output', required=True, help='输出目录')
parser.add_argument('-w', '--width', type=int, default=1920, help='目标宽度')
parser.add_argument('-h', '--height', type=int, default=1080, help='目标高度')
parser.add_argument('--no-aspect', action='store_true', help='不保持宽高比')
parser.add_argument('-q', '--quality', choices=['high', 'medium', 'low'],
default='high', help='视频质量')
args = parser.parse_args()
resizer = VideoResizer(
input_dir=args.input,
output_dir=args.output,
width=args.width,
height=args.height,
maintain_aspect=not args.no_aspect,
quality=args.quality
)
resizer.batch_process()
if __name__ == "__main__":
main()
图形界面工具
HandBrake
- 开源免费
- 支持批量处理
- GUI界面易用
Shutter Encoder
- 免费专业工具
- 支持各种格式
- 批量处理功能
Adobe Media Encoder
- 专业级软件
- 强大的批量处理
- 需要付费订阅
使用建议
-
性能优化:
- 使用硬件加速:
-hwaccel cuda(NVIDIA) 或-hwaccel videotoolbox(macOS) - 多线程处理:
-threads 4
- 使用硬件加速:
-
质量控制:
- CRF值:18-28(越小质量越好)
- 使用
-c:v libx264保持兼容性
-
格式转换:
- 可在缩放时同时转换格式
- 添加
-c:v libx265转换为HEVC格式
选择哪种方法取决于你的技术水平和需求,命令行脚本适合批量处理和自动化,图形界面工具适合偶尔使用或不熟悉命令行的用户。
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播