With more and more video applications on the website, more and more web servers need to support [Video Transcoding] (https://cloud.tencent.com/product/vts?from=10680), video compression, FFmpeg is currently the best web server background transcoding program, the most applications . FFmpeg is a set of open source computer programs that can be used to record, convert digital audio and video, and convert them into streams. Use LGPL or GPL license. It provides a complete solution for recording, converting, and streaming audio and video. The following describes the deployment record for FFmpeg under Centos7:
1 ) Install EPEL Release, because the installation needs to use other repo sources, so EPEL support is required
[ root@qd-vpc-op-snapshot01 ~]# yum install -y epel-release
[ root@qd-vpc-op-snapshot01 ~]# rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7//If there is a lack of Code prompt, execute this command.[root@qd-vpc-op-snapshot01 ~]# yum repolist //After the installation is complete, you can check whether the installation is successful 2) Install Nux-Dextop source
[ root@qd-vpc-op-snapshot01 ~]# rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro //Import a Code[root@qd-vpc-op-snapshot01 ~]# rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm //Install nux-dextop source[root@qd-vpc-op-snapshot01 ~]# yum repolist #Check whether the repo source is installed successfully
3 ) Install ffmpeg
[ root@qd-vpc-op-snapshot01 ~]# yum install -y ffmpeg
[ root@qd-vpc-op-snapshot01 ~]# ffmpeg -version
ffmpeg version 2.6.8Copyright(c)2000-2016 the FFmpeg developers
built with gcc 4.8.5(GCC)20150623(Red Hat 4.8.5-4)
configuration:--prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'--enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-nonfree --enable-libfdk-aac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static--enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil 54.20.100/54.20.100
libavcodec 56.26.100/56.26.100
libavformat 56.25.101/56.25.101
libavdevice 56.4.100/56.4.100
libavfilter 5.11.102/5.11.102
libavresample 2.1.0/2.1.0
libswscale 3.1.101/3.1.101
libswresample 1.1.100/1.1.100
libpostproc 53.3.100/53.3.100
For the follow-up installation, a shell script was specially written for one-click installation**:
[ root@qd-vpc-op-snapshot01 ~]# cat ffmpeg_install.sh
#! /bin/bash
yum install -y vim
yum install -y epel-release
rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
yum repolist
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
yum repolist
yum update -y
yum install -y ffmpeg
ffmpeg -version
FFmpeg commonly used basic commands
1 ) Separate video and audio streams
ffmpeg -i input_file -vcodec copy -an output_file_video //Split video stream
ffmpeg -i input_file -acodec copy -vn output_file_audio //Separate audio stream 2) Video demultiplexing
ffmpeg –i test.mp4 –vcodec copy –an –f m4v test.264
ffmpeg –i test.avi –vcodec copy –an –f m4v test.2643) Video transcoding
ffmpeg –i test.mp4 –vcodec h264 –s 352*278 –an –f m4v test.264//Transcode to original file
ffmpeg –i test.mp4 –vcodec h264 –bf 0 –g 25 –s 352*278 –an –f m4v test.264//Transcode to original file
ffmpeg –i test.avi -vcodec mpeg4 –vtag xvid –qsame test_xvid.avi //Transcode to package file//-bf B frame number control,-g Key frame interval control,-s Resolution control 4) Video packaging
ffmpeg –i video_file –i audio_file –vcodec copy –acodec copy output_file
5 ) Video cut
ffmpeg –i test.avi –r 1 –f image2 image-%3d.jpeg //Extract picture
ffmpeg -ss 0:1:30-t 0:0:20-i input.avi -vcodec copy -acodec copy output.avi //Cut video//-r the frequency of image extraction,-ss start time,-t Duration 6) Video recording
ffmpeg –i rtsp://192.168.3.205:5555/test –vcodec copy out.avi
7 ) YUV sequence playback
ffplay -f rawvideo -video_size 1920x1080 input.yuv
8 ) YUV sequence to AVI
ffmpeg –s w*h –pix_fmt yuv420p –i input.yuv –vcodec mpeg4 output.avi
Description of main common parameters:
- i Set the input stream
- f Set output format
- ss start time
Video parameters:
- b Set the video traffic, the default is 200Kbit/s
- r Set the frame rate, the default is 25-s Set the width and height of the screen
- aspect Set the ratio of the screen
- vn does not process video
- vcodec sets the video codec, if not set, the same codec as the input stream is used
Audio parameters:
- ar set sampling rate
- ac sets the number of sound channels
- acodec sets the sound codec, if not set, the same codec as the input stream is used
- an does not process audio
Recommended Posts