一、安装ffmpeg
brew install ffmpeg //安装
ffmpeg -version //验证成功
常见问题
1.-bash: brew: command not found
【未安装homebrew】:终端执行指令,安装工具
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.Error: Failure while executing: git config --local --replace-all homebrew.private true
【缺少 xcode 插件引起】:可以下载最新版本的插件或者下载更新至最新版本的xcode。 终端执行:下载安装插件
xcode-select --install
3.Error: Checksum mismatch.
【文件重复】:文件重复,需要重新下载
终端执行:
rm -rf /Users/macname/Library/Caches/Homebrew/portable-ruby-2.3.7.leopard_64.bottle.tar.gz
参考资料:
https://www.cnblogs.com/xiaoxiaopinger/p/9360643.html
https://www.cnblogs.com/sea-stream/p/10310002.html
二、常用指令
1.视频格式转换:比如avi文件,转换为mp4;多用于大文件转换成小文件(亲测:3G.mov 转换成 300M.mp4,时间需要约1小时)
ffmpeg -i input.avi output.mp4
2.视频裁剪:从第0秒开始,向后截取31秒视频,并保存
ffmpeg -ss 00:00:00 -i video.mp4 -vcodec copy -acodec copy -t 00:00:31 output1.mp4
3.视频合并:先将 mp4 转化为同样编码形式的 ts 流,因为 ts流是可以 concate 的,先把 mp4 封装成 ts ,然后 concate ts 流, 最后再把 ts 流转化为 mp4。
ffmpeg -i output1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb output1.ts
ffmpeg -i output2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb output2.ts
为了减少命令的输入,需要一个filelist.txt文件,里面内容如下
file 'output1.ts'
file 'output2.ts'
合并视频命令
ffmpeg -f concat -i filelist.txt -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4
4.视频宽高比压缩:将输入的1920x1080缩小到960x540输出
ffmpeg -i input.mp4 -vf scale=960:540 output.mp4
ps: 如果540不写,写成-1,即scale=960:-1, 会根据宽高比等比缩放另一边。
5.提取音频:去掉视频图像仅保留音频
ffmpeg -i input.mp4 -acodec copy -vn output.aac
6.查看图片、视频信息:编码、时长、创建时间、帧率
ffmpeg -i test.mp4
参考资料:
https://www.jianshu.com/p/ddafe46827b7