FFmpeg is not only an audio and video encoding and decoding tool, but also a set of audio and video encoding development kits. As an encoding development kit, it provides developers with rich calling interfaces for audio and video processing.
FFmpeg provides encapsulation and decapsulation of various media formats, including multiple audio and video encoding, multiple protocol streaming media, multiple colorful format conversions, multiple sampling rate conversions, multiple code rate conversions, etc.; the FFmpeg framework provides multiple A variety of plug-in modules, including plug-ins for packaging and decapsulation, plug-ins for encoding and decoding, etc. At the same time, it can also be used to record, convert digital audio, video, and convert it into an open source computer program for streaming. Adopt LGPL or GPL license. It provides a complete solution for recording, converting and streaming audio and video.
Article Directory
1. Download and install FFmpeg
- Download (custom version: http://www.ffmpeg.org/releases/)
wget http://www.ffmpeg.org/releases/ffmpeg-5.1.tar.gz
- decompress
tar -zxvf ffmpeg-5.1.tar.gz
- Compile and install (it takes a long time)
/home/ffmpeg is the installation directory specified by itself
cd ffmpeg-5.1
./configure --prefix=/home/ffmpeg
make && make install
- Configure environment variables (easy to use anywhere)
vi /etc/profile
Add the environment variable at the end of PATH:
export PATH=$PATH:$JAVA_HOME/bin:/home/ffmpeg/bin
source /ect/profile
- Verify correct installation
ffmpeg -version
Two, install nginx
1. Install dependencies
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
- Download, compile and install
# 下载
wget http://nginx.org/download/nginx-1.21.5.tar.gz
# 解压缩
tar -zxvf nginx-1.21.5.tar.gz
cd nginx-1.21.5/
# 执行配置并加载ssl模块
./configure --prefix=/usr/local/nginx --with-http_ssl_module
# 编译安装(默认安装在/usr/local/nginx)
make
make install
- start up
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# 进入:/usr/local/nginx/sbin
1 启动 ./nginx
2 停止 ./nginx -s stop
3 重启 ./nginx -s reload
4. Configure nginx (remember to open the port number on the external network server, and restart nginx and firewall)
server {
listen 82;
location / {
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/ffmpeg/video/; #root后的路径改为转码后的视频文件夹路径
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
}
3. Start transcoding
nohup ffmpeg -i replaced with rtsp stream address -c copy -y /home/ffmpeg/video/AK_PHAROS1_000003/1ZNBJ4800C006B/video.m3u8 2>/dev/null 2>&1 &
Note:
The first bold place is changed to your RTSP address to ensure normal playback (you can use the vlc tool to test) the
second place is the location path where the video stream is stored after transcoding
PS: This command runs in the background, if you want to foreground Run to remove the nohup at the beginning and 2>/dev/null at the end 2>&1 &
The video after successful transcoding is accessed through nginx, and the playback address of the result after executing the above method is:
http://IP address:82/AK_PHAROS1_000003/1ZNBJ4800C006B/video.m3u8
Test it in VLC: