Answer the question
In order to leave comments, you need to log in
How to loop video from camera to small files using ffmpeg?
Not good at scripting. Tell me how to implement the functionality of a video recorder on a PC. There is an IP camera. I pull out the RTSP stream using ffmpeg and write it to a file lasting 15 minutes, but the function works only once:
ffmpeg -t 00:15:00 -i "rtsp://192.168.1.10:554/user=admin&password=&channel=1&stream=0.sdp" -vcodec copy -b:v 64k "/home/anton/video/$(date +%Y-%m-%d+%H-%M-%S).mkv"
#!/bin/bash
i='2700' #параметр обозначающий порог свободного места на диске в МБ
FREE=$(df -m | grep "/dev/sdb1" | awk '{print $4}')
while [ "$i" -le "$FREE" ] #запись пока есть свободное место на диске
do
echo "Запись нового файла: " $(date +%Y-%m-%d+%H-%M-%S)".mkv"
ffmpeg -t 00:05:00 -i "rtsp://192.168.1.10:554/user=admin&password=&channel=1&stream=0.sdp" -vcodec copy -b:v 64k "/media/anton/48D6-E2E1/$(date +%Y-%m-%d+%H-%M-%S).mkv"
FREE=$(df -m | grep "/dev/sdb1" | awk '{print $4}') #проверим сколько осталось свободного места после записи файла
if [ "$i" -gt "$FREE" ];
then
until [ "$i" -gt "$FREE" ]
do
#ищим самый старый файл, за последние пять дней
var_d=$(find /media/anton/48D6-E2E1 -type f -name '*.mkv' -mtime 5 -daystart | head -n 1 | rm)
echo "Удаляем старый файл: " $var_d
FREE=$(df -m | grep "/dev/sdb1" | awk '{print $4}') #проверим сколько осталось свободного места после удаления
var_d=""
done
fi
done
Answer the question
In order to leave comments, you need to log in
It turned out a working solution in a couple of lines - maybe someone will come to mind.
1. Run ffmpeg in screen named record.
Running ffmpeg with the -f segment option writes the rtsp stream continuously, splitting it automatically into files with a duration of 1800 seconds ( -segment_time 1800 option), i.e. 30 min. The fa name
-rtsp_transport tcp had to be added because without it packets were lost.
2. Add a line to /etc/crontab
which once a minute checks the given directory for the number of files and leaves only the 96 most recent files, and deletes the rest (96 for half an hour = 2 days).
I recommend putting motion. Can only record motion. And it works with IP, usb cameras.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question