searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

ffmpeg安装使用教程

2024-05-11 07:04:34
7
0
## 安装
项目:github.com/FFmpeg/FFmpeg

```
git clone git@github.com:FFmpeg/FFmpeg.git
cd FFmpeg/
./configure
make
make install
```

### 在 Mac OSX 上使用 Homebrew 安装 ffmpeg

```
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
```

## 使用

### 视频裁剪

**Use this to cut video from [start] for [duration]:**

> ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4

**Use this to cut video from [start] to [end]:**

> ffmpeg -ss [start] -i in.mp4 -to [end] -c copy -copyts out.mp4

**example1**
```
ffmpeg -ss 00:00:05 -t 10 -i input.mp4 -q 0 output.mp4
00:00:05 表示开始时间
00:00:10 表示想要截取的时长(不是结束时间)
-q 0应该是表示质量不损失
```

**example2**
```
ffmpeg -ss 00:00:05 -to 00:00:10 -i input.mp4 -c copy output.mp4
-c copy表示不必重新编码,速度更快
```

### 视频格式转换

**将视频 MP4 转化为 GIF**

```
ffmpeg -i small.mp4 small.gif
```

**将 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**

```
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 的第一帧图片**
使用 ImageMagick 可以方便第提取 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 -y -hide_banner -i "test.avi" -filter:v "crop=iw-400:ih-40,scale=960:720" -pix_fmt yuv420p output_video.mp4
```
crop=iw-400:ih-40 从输入宽度 (iw) (2x200 左/右) 裁剪 400 从输入高度 (ih) (2x20 顶部/底部) 裁剪 40 如果你想要一个“清晰”的边缘,你可以再剪一点。
scale=960:720 稍微缩放视频以使其恢复到原始的 720p,960 是将其保持在一个不错的 4x3 比例。不需要这种缩放,您的偏好。


0条评论
0 / 1000
蒋****凯
3文章数
0粉丝数
蒋****凯
3 文章 | 0 粉丝
蒋****凯
3文章数
0粉丝数
蒋****凯
3 文章 | 0 粉丝
原创

ffmpeg安装使用教程

2024-05-11 07:04:34
7
0
## 安装
项目:github.com/FFmpeg/FFmpeg

```
git clone git@github.com:FFmpeg/FFmpeg.git
cd FFmpeg/
./configure
make
make install
```

### 在 Mac OSX 上使用 Homebrew 安装 ffmpeg

```
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
```

## 使用

### 视频裁剪

**Use this to cut video from [start] for [duration]:**

> ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4

**Use this to cut video from [start] to [end]:**

> ffmpeg -ss [start] -i in.mp4 -to [end] -c copy -copyts out.mp4

**example1**
```
ffmpeg -ss 00:00:05 -t 10 -i input.mp4 -q 0 output.mp4
00:00:05 表示开始时间
00:00:10 表示想要截取的时长(不是结束时间)
-q 0应该是表示质量不损失
```

**example2**
```
ffmpeg -ss 00:00:05 -to 00:00:10 -i input.mp4 -c copy output.mp4
-c copy表示不必重新编码,速度更快
```

### 视频格式转换

**将视频 MP4 转化为 GIF**

```
ffmpeg -i small.mp4 small.gif
```

**将 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**

```
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 的第一帧图片**
使用 ImageMagick 可以方便第提取 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 -y -hide_banner -i "test.avi" -filter:v "crop=iw-400:ih-40,scale=960:720" -pix_fmt yuv420p output_video.mp4
```
crop=iw-400:ih-40 从输入宽度 (iw) (2x200 左/右) 裁剪 400 从输入高度 (ih) (2x20 顶部/底部) 裁剪 40 如果你想要一个“清晰”的边缘,你可以再剪一点。
scale=960:720 稍微缩放视频以使其恢复到原始的 720p,960 是将其保持在一个不错的 4x3 比例。不需要这种缩放,您的偏好。


文章来自个人专栏
公共
3 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0