本文目录导读:

使用 FFmpeg(最通用,跨平台)
批量提取帧并转换格式(如 PNG→JPEG)
Windows (批处理):
@echo off
mkdir converted_frames
for %%f in (*.png) do (
ffmpeg -i "%%f" -q:v 2 "converted_frames\%%~nf.jpg"
)
Linux/Mac (Bash):
#!/bin/bash
mkdir -p converted_frames
for f in *.png; do
ffmpeg -i "$f" -q:v 2 "converted_frames/${f%.png}.jpg"
done
从视频批量提取帧并转换
提取所有帧为指定格式:
# 从 input.mp4 提取所有帧,每秒1帧,保存为 JPEG ffmpeg -i input.mp4 -vf fps=1 frame_%04d.jpg # 参数说明: # fps=1 : 每秒提取1帧 # %04d : 4位数字序号 (0001, 0002...)
Python 脚本(更灵活,可处理复杂逻辑)
import os
import subprocess
from pathlib import Path
def batch_convert_frames(input_dir, output_dir, input_ext='.png', output_ext='.jpg', quality=2):
"""
批量转换帧格式
"""
Path(output_dir).mkdir(parents=True, exist_ok=True)
for file in Path(input_dir).glob(f'*{input_ext}'):
output_file = Path(output_dir) / f"{file.stem}{output_ext}"
# FFmpeg 命令
cmd = [
'ffmpeg',
'-i', str(file),
'-q:v', str(quality), # 质量控制 (2-31, 越小质量越高)
'-y', # 覆盖已存在文件
str(output_file)
]
try:
subprocess.run(cmd, check=True, capture_output=True)
print(f"Converted: {file.name} -> {output_file.name}")
except subprocess.CalledProcessError as e:
print(f"Error converting {file.name}: {e}")
# 使用示例
batch_convert_frames('input_frames', 'converted_frames', '.png', '.jpg')
高级批量处理(带参数调整)
批量转换并调整分辨率
#!/bin/bash
# convert_frames.sh
input_dir="./frames"
output_dir="./converted"
mkdir -p "$output_dir"
for f in "$input_dir"/*.png; do
filename=$(basename "$f")
name="${filename%.*}"
ffmpeg -i "$f" \
-vf "scale=1920:1080" \ # 调整分辨率
-q:v 2 \ # JPEG质量
-pix_fmt yuv420p \ # 像素格式
"$output_dir/${name}.jpg"
done
批量转换不同格式(自动识别)
import os
import subprocess
SUPPORTED_INPUT = {'.png', '.jpg', '.jpeg', '.bmp', '.tiff', '.webp'}
OUTPUT_FORMAT = '.png' # 目标格式
def smart_convert(input_dir, output_dir):
for file in os.listdir(input_dir):
ext = os.path.splitext(file)[1].lower()
if ext not in SUPPORTED_INPUT:
continue
input_path = os.path.join(input_dir, file)
output_path = os.path.join(output_dir, f"{os.path.splitext(file)[0]}{OUTPUT_FORMAT}")
subprocess.run([
'ffmpeg', '-i', input_path,
'-y', output_path
])
smart_convert('./input', './output')
常见格式转换参数
| 源格式 | 目标格式 | 额外参数 |
|---|---|---|
| PNG | JPEG | -q:v 2 (2-31, 越小质量越高) |
| BMP | PNG | 无需额外参数 |
| JPEG | PNG | 无需额外参数 |
| WebP | PNG | 无需额外参数 |
| TGA | JPEG | -q:v 2 |
批量处理脚本(带进度显示)
import os
import subprocess
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor
def convert_single(args):
input_file, output_file, format_args = args
cmd = ['ffmpeg', '-i', input_file, '-y'] + format_args + [output_file]
subprocess.run(cmd, capture_output=True)
return os.path.basename(input_file)
def batch_convert_parallel(input_dir, output_dir, input_ext='.png', output_ext='.jpg', max_workers=4):
os.makedirs(output_dir, exist_ok=True)
files = [f for f in os.listdir(input_dir) if f.endswith(input_ext)]
tasks = []
for file in files:
in_path = os.path.join(input_dir, file)
out_path = os.path.join(output_dir, f"{os.path.splitext(file)[0]}{output_ext}")
tasks.append((in_path, out_path, ['-q:v', '2']))
with ThreadPoolExecutor(max_workers=max_workers) as executor:
results = list(tqdm(executor.map(convert_single, tasks), total=len(tasks)))
print(f"Converted {len(results)} files")
# 使用
batch_convert_parallel('frames', 'output', '.png', '.jpg')
安装要求
- FFmpeg: 下载安装
- Python 依赖:
pip install tqdm(如使用并行版本)
注意事项
- 备份原始文件: 转换前建议备份
- 质量平衡: JPEG质量参数
-q:v 2为最佳(2-5常用) - 色彩空间: PNG到JPEG转换可能改变色彩空间
- 大文件处理: 考虑使用并行处理提高效率
选择适合你操作系统和需求的脚本即可,FFmpeg 是最推荐的工具,功能强大且跨平台。
版权声明: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直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播