Last active
October 3, 2025 14:25
-
-
Save zhuziyi1989/b26f0f95903f4aefe43cc3f927587077 to your computer and use it in GitHub Desktop.
Revisions
-
zhuziyi1989 renamed this gist
Sep 17, 2025 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
zhuziyi1989 renamed this gist
Nov 30, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
zhuziyi1989 revised this gist
Mar 22, 2019 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,22 +13,22 @@ ### 将 MP4 转化成 高品质码率MP3 (320kbps) ffmpeg -i wonderful.mp4 wonderful.mp3 -b:a 320k ### 实现 MP4 与 GIF 的互转 将视频 MP4 转化为 GIF[](#) -------------------- ffmpeg -i small.mp4 small.gif ### 转化视频中的一部分为 GIF[](#) ffmpeg -t 3 -ss 00:00:02 -i small.webm small-clip.gif 从视频中第二秒开始,截取时长为3秒的片段转化为 gif @@ -37,15 +37,15 @@ 默认转化是中等质量模式,若要转化出高质量的 gif,可以修改比特率 ffmpeg -i small.mp4 -b 2048k small.gif 视频属性调整[](#) ----------- ### 缩放视频尺寸[](#) ffmpeg -i big.mov -vf scale=360:-1 small.mov 注意 `sacle` 值必须是偶数,这里的 `-1` 表示保持长宽比,根据宽度值自适应高度。 @@ -54,37 +54,37 @@ ### 加倍速播放视频[](#) ffmpeg -i input.mov -filter:v "setpts=0.5*PTS" output.mov 定义帧率 16fps: ffmpeg -i input.mov -r 16 -filter:v "setpts=0.125*PTS" -an output.mov ### 慢倍速播放视频[](#) ffmpeg -i input.mov -filter:v "setpts=2.0*PTS" output.mov ### 静音视频(移除视频中的音频)[](#) ffmpeg -i input.mov -an mute-output.mov `-an` 就是禁止音频输出 将 GIF 转化为 MP4[](#) ------------------ ffmpeg -f gif -i animation.gif animation.mp4 也可以将 gif 转为其他视频格式 ffmpeg -f gif -i animation.gif animation.mpeg ffmpeg -f gif -i animation.gif animation.webm 获取 GIF 的第一帧图片[](#) -
zhuziyi1989 created this gist
Mar 22, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,134 @@ ## 使用 ffmpeg 总结 ### 安装 在 Mac OSX 上使用 [Homebrew](http://brew.sh/) 安装 [ffmpeg](https://www.ffmpeg.org/): brew install ffmpeg brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-libass --with-libquvi --with-libvorbis --with-libvpx --with-opus --with-x265 brew update && brew upgrade ffmpeg ### 将 MP4 转化成 高品质码率MP3 (320kbps) ``` ffmpeg -i wonderful.mp4 wonderful.mp3 -b:a 320k ``` ### 实现 MP4 与 GIF 的互转 将视频 MP4 转化为 GIF[](#) -------------------- ```ffmpeg -i small.mp4 small.gif``` ### 转化视频中的一部分为 GIF[](#) ```ffmpeg -t 3 -ss 00:00:02 -i small.webm small-clip.gif``` 从视频中第二秒开始,截取时长为3秒的片段转化为 gif ### 转化高质量 GIF[](#) 默认转化是中等质量模式,若要转化出高质量的 gif,可以修改比特率 ```ffmpeg -i small.mp4 -b 2048k small.gif``` 视频属性调整[](#) ----------- ### 缩放视频尺寸[](#) ```ffmpeg -i big.mov -vf scale=360:-1 small.mov``` 注意 `sacle` 值必须是偶数,这里的 `-1` 表示保持长宽比,根据宽度值自适应高度。 如果要求压缩出来的视频尺寸长宽都保持为偶数,可以使用 `-2` ### 加倍速播放视频[](#) ```ffmpeg -i input.mov -filter:v "setpts=0.5*PTS" output.mov``` 定义帧率 16fps: ```ffmpeg -i input.mov -r 16 -filter:v "setpts=0.125*PTS" -an output.mov``` ### 慢倍速播放视频[](#) ```ffmpeg -i input.mov -filter:v "setpts=2.0*PTS" output.mov``` ### 静音视频(移除视频中的音频)[](#) ```ffmpeg -i input.mov -an mute-output.mov``` `-an` 就是禁止音频输出 将 GIF 转化为 MP4[](#) ------------------ ```ffmpeg -f gif -i animation.gif animation.mp4``` 也可以将 gif 转为其他视频格式 ```ffmpeg -f gif -i animation.gif animation.mpeg``` ```ffmpeg -f gif -i animation.gif animation.webm``` 获取 GIF 的第一帧图片[](#) ------------------ 使用 [ImageMagick](http://www.imagemagick.org/) 可以方便第提取 gif 图片的第 N 帧图像。 安装 ImageMagick brew install imagemagick 提取第一帧 convert 'animation.gif[0]' animation-first-frame.gif 通过 `[0]` 就可以提取出 gif 的第一帧图像。 GIF 转出来的 MP4 播放不了?[](#) ----------------------- 有些 GIF 转化出来的 MP4 不能被 Mac QuickTime Player.app 播放,需要添加 `pixel formal` 参数 ffmpeg -i input.gif -vf scale=420:-2,format=yuv420p out.mp4 使用 `yunv420p` 需要保证长宽为偶数,这里同时使用了 `scale=420:-2` 。 [FFmpeg CompilationGuide/MacOSX](https://trac.ffmpeg.org/wiki/Encode/H.264>wiki 解释</a>: QuickTime Player 对 H.264 视频只支持 YUV 色域 4:2:0 方式的二次插值算法。</p> <p>参考资料</p> <ul> <li><a href=) * [Convert Video to GIF or GIF to Video](http://davidwalsh.name/convert-video-gif) * [Get the First Frame of an Animated GIF with ImageMagick](http://davidwalsh.name/first-frame-animated-gif) * [Create an Image Preview from a Video](http://davidwalsh.name/create-image-preview-video) * [How to speed up / slow down a video](https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video) * [ffmpeg useful commands (FFMPEG 命令大全)](http://siwei.me/blog/posts/ffmpeg-useful-commands) * [ffmpeg 文档](http://siwei.me/blog/posts/ffmpeg-useful-commands) * * * * [← HTML5 表单自动填表功能](http://note.rpsh.net/posts/2015/04/16/html5-form-autocomplete/ "HTML5 表单自动填表功能") * [解决 iPhone AirDrop 找不到 Mac →](http://note.rpsh.net/posts/2015/07/16/iphone-airdrop-cannot-find-mac/ "解决 iPhone AirDrop 找不到 Mac")