如何使用 ffmpeg 捕获 HLS/rtsp 流快照?

如何使用 ffmpeg 捕获 HLS/rtsp 流快照?

我想使用 ffmpeg 来捕获 HLS 或 RTSP 流快照。

有什么简单的方法可以做到这一点吗?

谢谢!

答案1

所以 - 我认为我之前在 stackexchange 上找到了这个问题的答案,所以我只是重复我找到的信息(即不能承担责任!)

#!/bin/bash

# TimeLapse snapshot capture script.

# This script should capture any stills in the incoming Stills directory

time=`date '+%Y_%m_%d__%H_%M_%S'`;

# Specific for each camera
CameraName=no-spaces-this-will-be-a-filename-eventually
CameraIP='192.168.1.150'

CameraUsername='user'
CameraPassword='password'

# Shouldn't need to be changed!
StorageDirectory=/mnt/storage/Stills
StorageFilename=$CameraName-$time.png

mkdir -p $StorageDirectory/$CameraName;

ffmpeg -rtsp_transport tcp -i rtsp://$CameraUsername:$CameraPassword@$CameraIP:554/mainStream -ss 00:00:01.50 -vframes 1 $StorageDirectory/$CameraName/$StorageFilename -nostats -hide_banner -v 0 -loglevel quiet

现在 - 它与 HikVision 相机配合得很好。我就是用它来做的。

具体来说,-ss 00:00:01.50意味着它会播放一秒半的视频-vframe 1抓取 1 帧。这样可以让视频流“稳定下来”,这样您就不会只得到半幅图像。

我运行这个程序来定期从相机中捕捉图像,然后每周一次将其转换成缩时电影

#!/bin/bash

# TimeLapse footage creation script.

# This script should take any stills in the incoming Stills directory and
# compile them into a .mp4 file in the Movies directory.
# Then moved the 'processed' stills into a timestamped directory the
# Processed directory.

time=`date '+%Y_%m_%d__%H_%M_%S'`;
source="/mnt/storage/"

for CameraName in `ls $source/Stills/`; do

# If the Movies directory for $CameraName doesn't exist, make it.
   mkdir -p /mnt/storage/Movies/$CameraName

# Make the movie in the Movie directory using the stills from the Stills directory
   ffmpeg -framerate 10/1 -pattern_type glob -i "$source/Stills/$CameraName/*.png" -vf fps=30 -c:v libx264 -pix_fmt yuv420p $source/Movies/$CameraName/$CameraName-$time.mp4

# Make the Processed directory for $CameraName if it doesn't already exist
   mkdir -p /mnt/storage/Processed/$CameraName
# Make the timestamped directory for the stills to be moved into
   mkdir -p /mnt/storage/Processed/$CameraName/$time
# Move the stills
   mv $source/Stills/$CameraName/*.png $source/Processed/$CameraName/$time/

done

第一个脚本是 cronjob,每 5 分钟运行一次。第二个脚本是 cronjob,每周运行一次。

希望有所帮助。

相关内容