1. Pull a FFmpeg docker image.
docker pull jrottenberg/ffmpeg
2. Create a start-ffmpeg-all.sh startup script, because I have multiple cameras, so I need to start multiple containers.
#! /bin/bash
for((i=2;$i<=31;i++))
do
if (( ($i >= 9 && $i <= 12) || $i == 22 ))
then
echo "192.168.0.$i is not camera IP"
else
docker stop ffmpeg$i && docker rm ffmpeg$i
docker run -d --privileged=true -v /root/preview:/tmp/workdir --restart=always --name="ffmpeg$i" jrottenberg/ffmpeg -stats -i "rtsp://admin:[email protected].$i:554/h264/ch1/sub/av_stream" -vcodec libx264 -an -f flv rtmp://{ip}:12005/hls/movie$i -f image2 -y -update 1 -r 0.0001 preview$i.jpg
fi
done
主要命令是:ffmpeg -i "rtsp://admin:[email protected].$i:554/h264/ch1/sub/av_stream" -vcodec libx264 -an -f flv rtmp://{ip}:12005/hls/movie$i -f image2 -y -update 1 -r 0.2 preview$i.jpg
Explain these parameters:
-i input stream, camera stream address
-vcodec specifies the video codec
-an does not get sound, save cpu resources
-f output format, pay attention to the above two, one flv push, one image2 screenshot
-y Overwrite pictures with the same name
-update update
-r The frequency of timing screenshots, a few screenshots in 1 second, 0.2 means a screenshot in 5 seconds
3. Pull a nginx image
docker pull nginx
4. Create start-nginx.sh startup script
#!/bin/bash
docker stop nginx && docker rm nginx
sleep 3s
docker run --privileged=true -v /root/preview:/usr/share/nginx/html --restart=always -d -p 8010:80 -p 443:443 --name nginx nginx
~
5. Note that the mounted /root/preview directory is the directory where the screenshots of the ffmpeg container are saved, so it is ok.