fmmpeg是一个免费的开源多媒体框架,用于播放,编码,解码,流式传输,转码,多路复用,多路复用和过滤各种格式的多媒体文件,包括MPEG1音频和视频,MPEG4,h263,ac3,asf,avi,real, mjpeg和Flash。
fmmpeg是一个跨平台应用程序,可以在各种构建环境,配置和机器架构下的Linux,macOS,Windows,BSD,Solaris等上运行。大多数可用于Linux的媒体播放器以及音频/视频下载器和转换器(例如youtube-dl)都需要FFmpeg才能工作
centos8默认的Yum源不包含ffmpeg的库。先安装包含ffmpeg的仓库rpmfusion
1.安装第三方Yum源:rpmfusion
[root@localhost tmp]# yum install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
Last metadata expiration check: 0:03:39 ago on Wed 11 Mar 2020 10:19:16 PM EDT.
rpmfusion-free-release-8.noarch.rpm 3.1 kB/s | 11 kB 00:03
Dependencies resolved.
================================================================================================================================================
Package Architecture Version Repository Size
================================================================================================================================================
Installing:
rpmfusion-free-release noarch 8-0.1 @commandline 11 k
Transaction Summary
================================================================================================================================================
Install 1 Package
Total size: 11 k
Installed size: 3.7 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : rpmfusion-free-release-8-0.1.noarch 1/1
Verifying : rpmfusion-free-release-8-0.1.noarch 1/1
Installed:
rpmfusion-free-release-8-0.1.noarch
Complete!
2.yum命令安装fmmpeg
[root@localhost tmp]# yum install http://rpmfind.net/linux/epel/7/x86_64/Packages/s/SDL2-2.0.10-1.el7.x86_64.rpm
RPM Fusion for EL 8 - Free - Updates 33 kB/s | 248 kB 00:07
SDL2-2.0.10-1.el7.x86_64.rpm 87 kB/s | 448 kB 00:05
Dependencies resolved.
================================================================================================================================================
Package Architecture Version Repository Size
================================================================================================================================================
Installing:
SDL2 x86_64 2.0.10-1.el7 @commandline 448 k
Transaction Summary
================================================================================================================================================
Install 1 Package
Total size: 448 k
Installed size: 1.3 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : SDL2-2.0.10-1.el7.x86_64 1/1
Running scriptlet: SDL2-2.0.10-1.el7.x86_64 1/1
Verifying : SDL2-2.0.10-1.el7.x86_64 1/1
Installed:
SDL2-2.0.10-1.el7.x86_64
Complete!
[root@localhost tmp]#
yum命令安装fmmpeg
[root@localhost tmp]# yum install ffmpeg
Last metadata expiration check: 0:14:18 ago on Wed 11 Mar 2020 10:23:42 PM EDT.
Dependencies resolved.
================================================================================================================================================
Package Architecture Version Repository Size
================================================================================================================================================
Installing:
ffmpeg x86_64 4.2.2-1.el8 rpmfusion-free-updates 1.4 M
Transaction Summary
================================================================================================================================================
Install 1 Package
Total download size: 1.4 M
Installed size: 1.8 M
Is this ok [y/N]: y
Downloading Packages:
ffmpeg-4.2.2-1.el8.x86_64.rpm 711 kB/s | 1.4 MB 00:02
------------------------------------------------------------------------------------------------------------------------------------------------
Total 367 kB/s | 1.4 MB 00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : ffmpeg-4.2.2-1.el8.x86_64 1/1
Running scriptlet: ffmpeg-4.2.2-1.el8.x86_64 1/1
Verifying : ffmpeg-4.2.2-1.el8.x86_64 1/1
Installed:
ffmpeg-4.2.2-1.el8.x86_64
Complete!
[root@localhost tmp]#
yum发行的仓库,都有两个版本,一个是name是可执行文件的仓库,用于cli命令行(运维);一个是name-devel,用于二次开发调用和编译链接(开发人员需要安装词库)。
安装ffmpeg开发库:
[root@localhost tmp]# yum -y install ffmpeg-devel
Last metadata expiration check: 0:09:41 ago on Wed 11 Mar 2020 10:23:42 PM EDT.
Dependencies resolved.
================================================================================================================================================
Package Architecture Version Repository Size
================================================================================================================================================
Installing:
ffmpeg-devel x86_64 4.2.2-1.el8 rpmfusion-free-updates 908 k
Installing dependencies:
libvdpau x86_64 1.1.1-7.el8 AppStream 40 k
ocl-icd x86_64 2.2.12-1.el8 AppStream 51 k
openal-soft x86_64 1.18.2-7.el8 AppStream 394 k
libatomic x86_64 8.3.1-4.5.el8 BaseOS 22 k
jack-audio-connection-kit x86_64 1.9.12-8.el8 epel 519 k
libaom x86_64 1.0.0-8.20190810git9666276.el8 epel 1.6 M
libass x86_64 0.14.0-4.el8 epel 110 k
libdav1d x86_64 0.5.2-1.el8 epel 347 k
libmfx x86_64 1.25-4.el8 epel 36 k
libvmaf x86_64 1.3.15-1.el8 epel 347 k
pugixml x86_64 1.9-1.el8 epel 97 k
soxr x86_64 0.1.3-4.el8 epel 97 k
vid.stab x86_64 1.1.0-12.20190213gitaeabc8d.el8 epel 47 k
zimg x86_64 2.9.2-1.el8 epel 268 k
zvbi x86_64 0.2.35-9.el8 epel 424 k
ffmpeg-libs x86_64 4.2.2-1.el8 rpmfusion-free-updates 7.2 M
libavdevice x86_64 4.2.2-1.el8 rpmfusion-free-updates 96 k
opencore-amr x86_64 0.1.5-7.el8 rpmfusion-free-updates 180 k
vo-amrwbenc x86_64 0.1.3-8.el8 rpmfusion-free-updates 77 k
x264-libs x86_64 0.157-12.20190717git34c06d1.el8 rpmfusion-free-updates 651 k
x265-libs x86_64 3.1.2-1.el8 rpmfusion-free-updates 1.9 M
xvidcore x86_64 1.3.7-1.el8 rpmfusion-free-updates 268 k
Transaction Summary
================================================================================================================================================
Install 23 Packages
Total download size: 16 M
Installed size: 62 M
Downloading Packages:
(1/23): libvdpau-1.1.1-7.el8.x86_64.rpm 173 kB/s | 40 kB 00:00
(2/23): ocl-icd-2.2.12-1.el8.x86_64.rpm 186 kB/s | 51 kB 00:00
(3/23): openal-soft-1.18.2-7.el8.x86_64.rpm 972 kB/s | 394 kB 00:00
(4/23): libatomic-8.3.1-4.5.el8.x86_64.rpm 94 kB/s | 22 kB 00:00
(5/23): jack-audio-connection-kit-1.9.12-8.el8.x86_64.rpm 552 kB/s | 519 kB 00:00
(6/23): libdav1d-0.5.2-1.el8.x86_64.rpm 951 kB/s | 347 kB 00:00
(7/23): libmfx-1.25-4.el8.x86_64.rpm 72 kB/s | 36 kB 00:00
(8/23): libvmaf-1.3.15-1.el8.x86_64.rpm 1.3 MB/s | 347 kB 00:00
(9/23): pugixml-1.9-1.el8.x86_64.rpm 314 kB/s | 97 kB 00:00
(10/23): soxr-0.1.3-4.el8.x86_64.rpm 1.8 MB/s | 97 kB 00:00
(11/23): vid.stab-1.1.0-12.20190213gitaeabc8d.el8.x86_64.rpm 319 kB/s | 47 kB 00:00
(12/23): zimg-2.9.2-1.el8.x86_64.rpm 386 kB/s | 268 kB 00:00
(13/23): libaom-1.0.0-8.20190810git9666276.el8.x86_64.rpm 516 kB/s | 1.6 MB 00:03
(14/23): zvbi-0.2.35-9.el8.x86_64.rpm 1.5 MB/s | 424 kB 00:00
(15/23): libass-0.14.0-4.el8.x86_64.rpm 29 kB/s | 110 kB 00:03
(16/23): libavdevice-4.2.2-1.el8.x86_64.rpm 6.1 kB/s | 96 kB 00:15
(17/23): opencore-amr-0.1.5-7.el8.x86_64.rpm 167 kB/s | 180 kB 00:01
(18/23): vo-amrwbenc-0.1.3-8.el8.x86_64.rpm 40 kB/s | 77 kB 00:01
(19/23): ffmpeg-devel-4.2.2-1.el8.x86_64.rpm 41 kB/s | 908 kB 00:22
(20/23): x264-libs-0.157-12.20190717git34c06d1.el8.x86_64.rpm 185 kB/s | 651 kB 00:03
(21/23): x265-libs-3.1.2-1.el8.x86_64.rpm 357 kB/s | 1.9 MB 00:05
[MIRROR] ffmpeg-libs-4.2.2-1.el8.x86_64.rpm: Curl error (28): Timeout was reached for https://mirrors.ustc.edu.cn/rpmfusion/free/el/updates/8/x86_64/f/ffmpeg-libs-4.2.2-1.el8.x86_64.rpm [Operation timed out after 30001 milliseconds with 0 out of 0 bytes received]
(22/23): ffmpeg-libs-4.2.2-1.el8.x86_64.rpm 196 kB/s | 7.2 MB 00:37
[MIRROR] xvidcore-1.3.7-1.el8.x86_64.rpm: Curl error (28): Timeout was reached for https://mirrors.ustc.edu.cn/rpmfusion/free/el/updates/8/x86_64/x/xvidcore-1.3.7-1.el8.x86_64.rpm [Operation timed out after 30000 milliseconds with 0 out of 0 bytes received]
(23/23): xvidcore-1.3.7-1.el8.x86_64.rpm 8.7 kB/s | 268 kB 00:30
------------------------------------------------------------------------------------------------------------------------------------------------
Total 251 kB/s | 16 MB 01:03
warning: /var/cache/dnf/rpmfusion-free-updates-4f04908c20c55925/packages/ffmpeg-devel-4.2.2-1.el8.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 158b3811: NOKEY
RPM Fusion for EL 8 - Free - Updates 1.6 MB/s | 1.7 kB 00:00
Importing GPG key 0x158B3811:
Userid : "RPM Fusion free repository for EL (8) <[email protected]>"
Fingerprint: 8379 35CD 19E1 23AA 7F8A 8E69 979F 0C69 158B 3811
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmfusion-free-el-8
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : ocl-icd-2.2.12-1.el8.x86_64 1/23
Running scriptlet: ocl-icd-2.2.12-1.el8.x86_64 1/23
Installing : x264-libs-0.157-12.20190717git34c06d1.el8.x86_64 2/23
Running scriptlet: x264-libs-0.157-12.20190717git34c06d1.el8.x86_64 2/23
Installing : xvidcore-1.3.7-1.el8.x86_64 3/23
Installing : x265-libs-3.1.2-1.el8.x86_64 4/23
Installing : vo-amrwbenc-0.1.3-8.el8.x86_64 5/23
Installing : opencore-amr-0.1.5-7.el8.x86_64 6/23
Installing : zvbi-0.2.35-9.el8.x86_64 7/23
Running scriptlet: zvbi-0.2.35-9.el8.x86_64 7/23
Installing : zimg-2.9.2-1.el8.x86_64 8/23
Installing : vid.stab-1.1.0-12.20190213gitaeabc8d.el8.x86_64 9/23
Installing : soxr-0.1.3-4.el8.x86_64 10/23
Installing : pugixml-1.9-1.el8.x86_64 11/23
Running scriptlet: pugixml-1.9-1.el8.x86_64 11/23
Installing : libvmaf-1.3.15-1.el8.x86_64 12/23
Installing : libmfx-1.25-4.el8.x86_64 13/23
Installing : libdav1d-0.5.2-1.el8.x86_64 14/23
Installing : libass-0.14.0-4.el8.x86_64 15/23
Installing : libaom-1.0.0-8.20190810git9666276.el8.x86_64 16/23
Running scriptlet: jack-audio-connection-kit-1.9.12-8.el8.x86_64 17/23
Installing : jack-audio-connection-kit-1.9.12-8.el8.x86_64 17/23
Installing : libatomic-8.3.1-4.5.el8.x86_64 18/23
Running scriptlet: libatomic-8.3.1-4.5.el8.x86_64 18/23
Installing : openal-soft-1.18.2-7.el8.x86_64 19/23
Installing : libvdpau-1.1.1-7.el8.x86_64 20/23
Running scriptlet: libvdpau-1.1.1-7.el8.x86_64 20/23
Installing : ffmpeg-libs-4.2.2-1.el8.x86_64 21/23
Installing : libavdevice-4.2.2-1.el8.x86_64 22/23
Installing : ffmpeg-devel-4.2.2-1.el8.x86_64 23/23
Running scriptlet: ffmpeg-devel-4.2.2-1.el8.x86_64 23/23
Verifying : libvdpau-1.1.1-7.el8.x86_64 1/23
Verifying : ocl-icd-2.2.12-1.el8.x86_64 2/23
Verifying : openal-soft-1.18.2-7.el8.x86_64 3/23
Verifying : libatomic-8.3.1-4.5.el8.x86_64 4/23
Verifying : jack-audio-connection-kit-1.9.12-8.el8.x86_64 5/23
Verifying : libaom-1.0.0-8.20190810git9666276.el8.x86_64 6/23
Verifying : libass-0.14.0-4.el8.x86_64 7/23
Verifying : libdav1d-0.5.2-1.el8.x86_64 8/23
Verifying : libmfx-1.25-4.el8.x86_64 9/23
Verifying : libvmaf-1.3.15-1.el8.x86_64 10/23
Verifying : pugixml-1.9-1.el8.x86_64 11/23
Verifying : soxr-0.1.3-4.el8.x86_64 12/23
Verifying : vid.stab-1.1.0-12.20190213gitaeabc8d.el8.x86_64 13/23
Verifying : zimg-2.9.2-1.el8.x86_64 14/23
Verifying : zvbi-0.2.35-9.el8.x86_64 15/23
Verifying : ffmpeg-devel-4.2.2-1.el8.x86_64 16/23
Verifying : ffmpeg-libs-4.2.2-1.el8.x86_64 17/23
Verifying : libavdevice-4.2.2-1.el8.x86_64 18/23
Verifying : opencore-amr-0.1.5-7.el8.x86_64 19/23
Verifying : vo-amrwbenc-0.1.3-8.el8.x86_64 20/23
Verifying : x264-libs-0.157-12.20190717git34c06d1.el8.x86_64 21/23
Verifying : x265-libs-3.1.2-1.el8.x86_64 22/23
Verifying : xvidcore-1.3.7-1.el8.x86_64 23/23
Installed:
ffmpeg-devel-4.2.2-1.el8.x86_64 libvdpau-1.1.1-7.el8.x86_64 ocl-icd-2.2.12-1.el8.x86_64
openal-soft-1.18.2-7.el8.x86_64 libatomic-8.3.1-4.5.el8.x86_64 jack-audio-connection-kit-1.9.12-8.el8.x86_64
libaom-1.0.0-8.20190810git9666276.el8.x86_64 libass-0.14.0-4.el8.x86_64 libdav1d-0.5.2-1.el8.x86_64
libmfx-1.25-4.el8.x86_64 libvmaf-1.3.15-1.el8.x86_64 pugixml-1.9-1.el8.x86_64
soxr-0.1.3-4.el8.x86_64 vid.stab-1.1.0-12.20190213gitaeabc8d.el8.x86_64 zimg-2.9.2-1.el8.x86_64
zvbi-0.2.35-9.el8.x86_64 ffmpeg-libs-4.2.2-1.el8.x86_64 libavdevice-4.2.2-1.el8.x86_64
opencore-amr-0.1.5-7.el8.x86_64 vo-amrwbenc-0.1.3-8.el8.x86_64 x264-libs-0.157-12.20190717git34c06d1.el8.x86_64
x265-libs-3.1.2-1.el8.x86_64 xvidcore-1.3.7-1.el8.x86_64
Complete!
[root@localhost tmp]#
3.检查FFmpeg在CentOS8上的安装
[root@localhost tmp]# ffmpeg -version
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
[root@localhost tmp]#
准备视频文件:
[root@localhost minio]# pwd
/tmp/minio
[root@localhost minio]# ll
total 28644
-rw-r--r--. 1 root root 29330776 Mar 11 22:58 猫和老鼠.mp4
[root@localhost minio]#
4.测试ffmpeg
- 分割视频:下列命令可以从时间00:00:45开始,截取20秒钟视频出来
ffmpeg -ss 00:00:45 -t 00:00:20 -i 猫和老鼠.mp4 -codec copy 小猫和老鼠.mp4
参数含义:
–ss表示分割开始的时间
-t表示截取的视频的时长
-codec copy(也可以写为-c copy)表示未转码(视频和音频的编码和原来的一致)
[root@localhost minio]# ffmpeg -ss 00:00:45 -t 00:00:20 -i 猫和老鼠.mp4 -codec copy 小猫和老鼠.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '猫和老鼠.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2019-09-01T04:44:37.000000Z
encoder : Google
Duration: 00:03:55.91, start: 0.000000, bitrate: 994 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 863 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
creation_time : 2019-09-01T04:44:37.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 08/31/2019.
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
creation_time : 2019-09-01T04:44:37.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 08/31/2019.
Output #0, mp4, to '小猫和老鼠.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
encoder : Lavf58.29.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 863 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc (default)
Metadata:
creation_time : 2019-09-01T04:44:37.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 08/31/2019.
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
creation_time : 2019-09-01T04:44:37.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 08/31/2019.
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 603 fps=0.0 q=-1.0 Lsize= 3791kB time=00:00:19.99 bitrate=1553.3kbits/s speed=3.05e+03x
video:3457kB audio:315kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.502473%
[root@localhost minio]# ll
total 32436
-rw-r--r--. 1 root root 3881902 Mar 11 23:02 小猫和老鼠.mp4
-rw-r--r--. 1 root root 29330776 Mar 11 22:58 猫和老鼠.mp4
[root@localhost minio]#
效果截图:
未分割之前的视频,有3分51秒时长
用fmmpeg分割后的视频,是20秒时长
用同样的方法,分割出另外一段视频(从4分45秒开始的20秒视频):
[root@localhost minio]# ffmpeg -ss 00:01:40 -t 00:00:20 -i 猫和老鼠.mp4 -codec copy 小小猫和老鼠.mp4
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 637 fps=0.0 q=-1.0 Lsize= 2380kB time=00:00:19.97 bitrate= 975.7kbits/s speed=4e+03x
video:2026kB audio:332kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.904765%
[root@localhost minio]# ll
total 34816
-rw-r--r--. 1 root root 2436619 Mar 11 23:08 小小猫和老鼠.mp4
-rw-r--r--. 1 root root 3881902 Mar 11 23:02 小猫和老鼠.mp4
-rw-r--r--. 1 root root 29330776 Mar 11 22:58 猫和老鼠.mp4
[root@localhost minio]#
- 合并视频:用FFmpeg concat分离器的无损合并规格相同的视频的方法成功率比较高。
准备,首先创建源码文件描述文本videolist.txt ,确保内容如下:
[root@localhost minio]# cat videolist.txt
file '/tmp/minio/小猫和老鼠.mp4'
file '/tmp/minio/小小猫和老鼠.mp4'
[root@localhost minio]#
合并两段视频为一段:
[root@localhost minio]# ffmpeg -f concat -safe 0 -i videolist.txt -c copy 合并猫和鼠.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5585f95c2c40] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from 'videolist.txt':
Duration: N/A, start: -0.115828, bitrate: 1537 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1409 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 08/31/2019.
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 08/31/2019.
Output #0, mp4, to '合并猫和鼠.mp4':
Metadata:
encoder : Lavf58.29.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1409 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 08/31/2019.
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 08/31/2019.
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5585f9626480] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308467, current: 292063; changing to 308468. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308468, current: 292575; changing to 308469. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308469, current: 293087; changing to 308470. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308470, current: 293599; changing to 308471. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308471, current: 294111; changing to 308472. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308472, current: 294623; changing to 308473. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308473, current: 295135; changing to 308474. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886784, current: 848241; changing to 886785. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308474, current: 295647; changing to 308475. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886785, current: 849265; changing to 886786. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886786, current: 850289; changing to 886787. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308475, current: 296159; changing to 308476. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886787, current: 851313; changing to 886788. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308476, current: 296671; changing to 308477. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886788, current: 852337; changing to 886789. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308477, current: 297183; changing to 308478. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886789, current: 853361; changing to 886790. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886790, current: 854385; changing to 886791. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308478, current: 297695; changing to 308479. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886791, current: 855409; changing to 886792. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308479, current: 298207; changing to 308480. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886792, current: 856433; changing to 886793. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886793, current: 857457; changing to 886794. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308480, current: 298719; changing to 308481. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886794, current: 858481; changing to 886795. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308481, current: 299231; changing to 308482. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886795, current: 859505; changing to 886796. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886796, current: 860529; changing to 886797. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308482, current: 299743; changing to 308483. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886797, current: 861553; changing to 886798. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308483, current: 300255; changing to 308484. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886798, current: 862577; changing to 886799. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308484, current: 300767; changing to 308485. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886799, current: 863601; changing to 886800. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886800, current: 864625; changing to 886801. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308485, current: 301279; changing to 308486. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886801, current: 865649; changing to 886802. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308486, current: 301791; changing to 308487. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886802, current: 866673; changing to 886803. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886803, current: 867697; changing to 886804. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308487, current: 302303; changing to 308488. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886804, current: 868721; changing to 886805. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308488, current: 302815; changing to 308489. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886805, current: 869745; changing to 886806. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886806, current: 870769; changing to 886807. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308489, current: 303327; changing to 308490. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886807, current: 871793; changing to 886808. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308490, current: 303839; changing to 308491. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886808, current: 872817; changing to 886809. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308491, current: 304351; changing to 308492. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886809, current: 873841; changing to 886810. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886810, current: 874865; changing to 886811. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308492, current: 304863; changing to 308493. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886811, current: 875889; changing to 886812. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308493, current: 305375; changing to 308494. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886812, current: 876913; changing to 886813. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886813, current: 877937; changing to 886814. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308494, current: 305887; changing to 308495. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886814, current: 878961; changing to 886815. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308495, current: 306399; changing to 308496. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886815, current: 879985; changing to 886816. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886816, current: 881009; changing to 886817. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308496, current: 306911; changing to 308497. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886817, current: 882033; changing to 886818. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308497, current: 307423; changing to 308498. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886818, current: 883057; changing to 886819. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886819, current: 884081; changing to 886820. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308498, current: 307935; changing to 308499. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886820, current: 885105; changing to 886821. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:0; previous: 308499, current: 308447; changing to 308500. This may result in incorrect timestamps in the output file.
[mp4 @ 0x5585f9609080] Non-monotonous DTS in output stream 0:1; previous: 886821, current: 886129; changing to 886822. This may result in incorrect timestamps in the output file.
frame= 1240 fps=0.0 q=-1.0 Lsize= 6166kB time=00:00:40.22 bitrate=1255.7kbits/s speed=1.47e+03x
video:5485kB audio:643kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.625088%
[root@localhost minio]# ll
total 40988
-rw-r--r--. 1 root root 79 Mar 11 23:15 videolist.txt
-rw-r--r--. 1 root root 6314023 Mar 11 23:24 合并猫和鼠.mp4
-rw-r--r--. 1 root root 2436619 Mar 11 23:08 小小猫和老鼠.mp4
-rw-r--r--. 1 root root 3881902 Mar 11 23:02 小猫和老鼠.mp4
-rw-r--r--. 1 root root 29330776 Mar 11 22:58 猫和老鼠.mp4
[root@localhost minio]
合并后的视频为40秒,效果截图:
补充说明:ubuntu安装ffmpeg,使用以下命令即可:、
root@ubuntu:/home/# snap install ffmpeg
ffmpeg 4.1.4 from Snapcrafters installed
root@ubuntu:/home/#