视频批量转换
- 批量转换当前目录MP4 格式文件到Output目录下
- 使用libx264 重新编码,crf 控制转换质量(0~51,默认23),0为无损,数字越大质量越差
Windows系统
新建convert.bat,复制如下代码,双击convert.bat开始转换
#convert.bat
@echo off
setlocal enabledelayedexpansion
set "SOURCE_FOLDER=%~dp0"
set "OUTPUT_FOLDER=%~dp0Output"
if not exist "%OUTPUT_FOLDER%" mkdir "%OUTPUT_FOLDER%"
for %%f in ("%SOURCE_FOLDER%*.MP4") do (
set "filename=%%~nf"
set "outputfile=%OUTPUT_FOLDER%\!filename!.mp4"
ffmpeg -i "%%f" -vcodec libx264 -crf 23 -c:a copy "!outputfile!"
)
echo Conversion completed.
pause
MacOS
新建convert.sh复制以下代码
使用chmod 777 ./convert.sh增加权限后
./convert.sh 开始转换
#!/bin/bash
for file in *.MP4; do
ffmpeg -i "$file" -vcodec libx264 -crf 23 "${file%}.mp4"
done
视频拼接
新建input.txt,需要拼接的视频路径如下保存
file 1.mp4
file 2.mp4
file 3.mp4
终端输入命令开始合并
# 保留声音合并
ffmpeg -f concat -safe 0 -i input.txt -c:v copy -c:a copy output.mp4
# 去掉声音合并
ffmpeg -f concat -safe 0 -i input.txt -c:v copy -an output.mp4
视频截取
# 指定开始时间 + 截取长度(s)
ffmpeg -ss 00:01:00 -t 60 -i input.mp4 -c copy output.mp4
# 指定开始时间 + 结束时间
ffmpeg -ss 00:01:00 -to 00:02:00 -i input.mp4 output.mp4
例如:
ffmpeg -ss 00:00:10 -to 00:35:10 -i 6.4.2.mp4 6.4.2.a.mp4
ffmpeg -ss 00:35:20 -to 01:10:18 -i 6.4.2.mp4 6.4.2.b.mp4
ffmpeg -ss 01:10:28 -to 01:45:27 -i 6.4.2.mp4 6.4.2.c.mp4
ffmpeg -ss 01:45:36 -to 02:20:36 -i 6.4.2.mp4 6.4.2.d.mp4