bash
ffmpeg -i ./Test.mp4
-i 输入
bash
ffmpeg -i chuangGuand.mp4 test1.avi
输出文件为test1.avi
视频截取
bash
ffmpeg -ss 00:00:10 -t 00:00:30 -i test.mp4 -vcodec copy -acodec copy output.mp4
2. -ss 00:00:10
start time 开始时间
从视频第 10 秒开始截取
3. -t 00:00:30
duration 持续时间
截取30 秒长度
4. -i test.mp4
input 输入文件
要剪辑的原视频叫 test.mp4
5. -vcodec copy
视频编码直接复制,不重新压缩
6. -acodec copy
音频编码直接复制
和视频一样,不改动、不压缩
7. output.mp4
输出文件名
合并视频
bash
file 'test1.mp4'
file 'test2.mp4'
file 'test3.mp4'
bash
ffmpeg -f concat -i test.txt -c:v copy hb.mp4
bash
ffmpeg -f concat -i test.txt -vcodec copy -acodec copy hb1.mp4
它们是完全等价的别名:
-vcodec copy
= video codec copy(老写法)
-c:v copy
= codec:video copy(新写法)
-acodec copy ≡ -c:a copy 音频
更改视频的分辨率
bash
ffmpeg -i chuangGuand.mp4 -filter:v scale=1280:720 -c:a copy fbl.mp4
改变音视频的编码方式
bash
ffmpeg -i test.avi -c:v libx264 -c:a aac output.mp4
提取视频中的音频
bash
ffmpeg -i test.mp4 -vn test.mp3
-vn,就是 disable video
bash
ffmpeg -i test.mp4 -an output.mp4
-an 去掉音频
提取图像
bash
ffmpeg -i test.mp4 -r 1 -f image2 image_%2d.png
m3u8
bash
ffmpeg -i test.mp4 -vcodec libx264
-strict -2 -acodec aac -hls_list_size 0 -f hls index.m3u8
2. -vcodec libx264
视频编码用 H.264
= 所有浏览器、手机都支持的通用格式
3. -acodec aac
音频编码用 AAC
= 最通用的音频格式
4. -strict -2
允许使用标准 AAC 编码(老版本 FFmpeg 需要,现在可加可不加)
-strict very → -3 最严格
-strict strict → -2 严格
-strict normal → 0 默认
-strict unofficial→ 1 允许非官方
-strict experimental → 2 ✅ 实验性(常用
AI说的2015前
-strict -2是experiment
2015后
-strict -2 是strict
5. -hls_list_size 0
m3u8 列表包含所有切片,不删除、不滚动
-hls_list_size 3 如果为3 只会保留最新的3个ts
= 0 = 保留全部切片
6. -f hls
强制输出 HLS 格式 -format 流媒体格式
7. index.m3u8
bash
ffmpeg -i chuangGuand.mp4 -c:v libx264 -c:a aac -hls_time 30 -hls_list_size 0 -f hls Myindex.m3u8