FreeBSD 14
1
2
|
# cd /usr/ports/multimedia/ffmpeg
# make install clean
|
Ubuntu 22.04 LTS
1
2
3
4
5
6
|
$ sudo apt update
$ $sudo apt install ffmpeg
$ ffmpeg -version
$ ffmpeg -encoders
$ ffmpeg -decoders
|
CentOS 7
1
2
3
|
$ sudo yum install epel-release
$ sudo yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
$ sudo yum install ffmpeg ffmpeg-devel
|
CentOS 8
1
2
3
4
5
|
$ wget http://www.ffmpeg.org/releases/ffmpeg-4.4.tar.gz
$ tar -xvf ffmpeg-4.4.tar.gz
$ cd ffmpeg-4.4/
$ ./configure && make && make install
$ ffmpeg -version
|
Windows 10
Visit the FFmpeg download page. The More downloading options section has FFmpeg packages and executable files for Linux, Windows, and Mac. To get the Windows version, Windows builds from gyan.dev
Extract the Downloaded Files
Add FFmpeg to PATH
1
|
> set path=D:\Program Files\ffmpeg-7.0.2-full_build\bin
|
Verify FFmpeg PATH
Instructions
1
2
|
$ sudo yum install mediainfo
$ mediainfo input.mp4
|
Conversion
1
2
|
$ ffmpeg -i input.avi output.mp4
$ ffmpeg -i input.mp4 output.ts
|
1
|
$ ffmpeg -i input.mp4 -vcodec h264 output.mp4
|
1
2
|
$ ffmpeg -i input.mp4 -acodec copy -vn output.aac
$ ffmpeg -i input.mp4 -acodec aac -vn output.aac
|
1
|
$ ffmpeg -i input.mp4 -vcodec copy -an output.mp4
|
Video clip
- ffmpeg -ss [start] -i [input] -t [duration] -c copy [output]
- ffmpeg -ss [start] -i [input] -to [end] -c copy [output]
1
2
|
$ ffmpeg -ss 00:03:03 -i ./input.mp4 -c copy ./output.mp4
$ ffmpeg -ss 00:03:03 -to 33:33:33 -i ./input.mp4 -c copy ./output.mp4
|
Video merge
1
2
3
4
5
6
|
$ vim ./join.txt
file /home/sk/myvideos/part1.mp4
file /home/sk/myvideos/part2.mp4
file /home/sk/myvideos/part3.mp4
$ ffmpeg -f concat -i join.txt -c copy output.mp4
$ ffmpeg -f concat -safe 0 -i ./join.txt -c copy output.mp4
|
Bit rate
There are 3 options for ffmpeg to control the bit rate: -minrate**-b:v****-b:a****-maxrate**
bitrate = file size / duration
biterate = 20.8M bit/60s = 20.810241024*8 bit/60s= 2831Kbps
|
| 分辨率320x240 码率200-384kbps |
| 分辨率640x480 码率768-1024kbps |
| 分辨率1280x720(720p) 码率2048-3072kbps |
| 分辨率1920x1080(1080p) 码率5120-8192kbps |
1
2
|
$ ffmpeg -i input.mp4 -b:v 2000k -bufsize 2000k output.mp4
$ ffmpeg -i input.mp4 -b:v 2000k -bufsize 2000k -maxrate 2500k output.mp4
|
Use of filters
Scale down the input 1920x1080 to 960x540 output
1
2
|
$ ffmpeg -i input.mp4 -vf scale=960:540 output.mp4
$ ffmpeg -i input.mp4 -vf scale=960:-1 output.mp4
|
Add logo to video
1
2
3
4
|
$ ffmpeg -i input.mp4 -i logo.png -filter_complex overlay output.mp4
$ ffmpeg -i input.mp4 -i logo.png -filter_complex overlay=W-w output.mp4
$ ffmpeg -i input.mp4 -i logo.png -filter_complex overlay=0:H-h output.mp4
$ ffmpeg -i input.mp4 -i logo.png -filter_complex overlay=W-w:H-h output.mp4
|
Remove video logo
-vf delogo=x:y:w:h[:t[:show]]
the coordinates from the upper left corner
|
|
|
-vf delogo=x:y:w:h[:t[:show]] |
| x:y |
The coordinates from the upper left corner |
| w:h |
Logo width and height |
| t |
The thickness of the rectangle edges defaults to 4 |
| show |
If set to 1 to have a green rectangle, the default value is 0. |
1
|
$ ffmpeg -i input.mp4 -vf delogo=0:0:220:90:100:1 output.mp4
|
Capture video image
1
2
3
4
5
6
7
8
9
|
ffmpeg -i input.mp4 -r 1 -q:v 2 -f image2 pic-%03d.jpeg
-r 表示每一秒几帧
-q:v表示存储jpeg的图像质量,一般2是高质量。
如此,ffmpeg会把input.mp4,每隔一秒,存一张图片下来。假设有60s,那会有60张。可以设置开始的时间,和你想要截取的时间。
ffmpeg -i input.mp4 -ss 00:00:20 -t 10 -r 1 -q:v 2 -f image2 pic-%03d.jpeg
-ss 表示开始时间
-t 表示共要多少时间。
如此,ffmpeg会从input.mp4的第20s时间开始,往下10s,即20~30s这10秒钟之间,每隔1s就抓一帧,总共会抓10帧。
|
Batch file
1
2
3
4
5
6
7
8
9
|
$ ffmpeg -i a.mp4
$ ffmpeg -i a.mp4 -hide_banner
$ ffmpeg -i a.mkv b.mp4
$ ffmpeg -i input.webm -qscale 0 output.mp4
$ ffmpeg -formats
$ ffmpeg -i ./input.mp4 -ss 01:01:01 -to 02:02:02 -c copy ./output.mp4
$ ffmpeg -i input.mp4 -t 00:33:03 -c copy output.mp4
$ ffmpeg -i input.mp4 -t 00:01:06 -c copy part1.mp4 -ss 00:01:06 -c copy part2.mp4
|
1
2
3
4
5
6
7
8
9
|
#!/bin/sh
Folder_A="/home/a"
for file_a in ${Folder_A}/*
do
out_filename=`basename $file_a`
in_filename="NEW-"${out_filename}
ffmpeg -i /home/a/$out_filename -vf scale=1280:-1 $in_filename -y
done
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/bin/sh
echo -e "start_time:${PWD}"
read start_time
echo -e "end_time:${PWD}"
read end_time
Folder_A="/home/cidi/Documents/vedio/fill_vedio"
for file_a in ${Folder_A}/*
do
out_filename=`basename $file_a`
in_filename="_CIDI_"${out_filename}
ffmpeg -i /home/cidi/Documents/vedio/fill_vedio/$out_filename -vcodec copy -acodec copy -ss $start_time -to $end_time $in_filename -y
done
|