ffmpeg 使用文档记录

#为视频增加黑边

1
ffmpeg -i input.mp4 -vf "scale=1920:888,pad=1920:1080:0:96:black" output.mp4

从 iPhone 13 pro 录屏得到的视频大小为1920*888,投稿视频的时候没有办法达到 1080p 的要求,需要补黑边。

视频信息

如果要将888补到1080其实要在上下加黑边。

参数解释:

  • scale 原尺寸缩放到的比例。
  • pad 填充后的比例,已经视频要放的位置,还有补的颜色。因为上下补所以 x 不变,还是0,y 需要上下各加一半黑边的长度(不然视频的黑边都加在下面了):
1
2
~  echo $(((1080-888)/2))                             [2021/12/11 17:03:40]
96

#从视频中截取一段

1
ffmpeg -i RPReplay_Final1637503011.MP4 -ss 10:05 -t 72 -c:v copy -c:a copy output.mp4

参数解释:

#获取视频通道数,采样率等信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
~  ffprobe -i test2.wav -v quiet -print_format json -show_format -show_streams
{
"streams": [
{
"index": 0,
"codec_name": "pcm_s16le",
"codec_long_name": "PCM signed 16-bit little-endian",
"codec_type": "audio",
"codec_tag_string": "[1][0][0][0]",
"codec_tag": "0x0001",
"sample_fmt": "s16",
"sample_rate": "48000",
"channels": 2,
"bits_per_sample": 16,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/48000",
"duration_ts": 337920,
"duration": "7.040000",
"bit_rate": "1536000",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0,
"captions": 0,
"descriptions": 0,
"metadata": 0,
"dependent": 0,
"still_image": 0
}
}
],
"format": {
"filename": "test2.wav",
"nb_streams": 1,
"nb_programs": 0,
"format_name": "wav",
"format_long_name": "WAV / WAVE (Waveform Audio)",
"duration": "7.040000",
"size": "1351724",
"bit_rate": "1536050",
"probe_score": 99
}
}

channels通道数
sample_rate采样率

#修改通道数/采样率

1
2
ffmpeg -i test3.wav -ac 1 -ar 16000 test4.wav
ffmpeg -y -i test.mp3 -acodec pcm_s16le -f s16le -ac 1 -ar 16000 test.pcm

参考https://ffmpeg.org/ffmpeg.html#Audio-Options

  • -ac 设置通道数
  • -ar 设置采样率
  • -acodec 设置音频格式
  • -f 设置输入/输出的格式(其实不太懂,待细看)