bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
12.17k stars 1.52k forks source link

Limit recordings by max space or min free space #3631

Open alex-eri opened 2 months ago

alex-eri commented 2 months ago

Describe the feature

I mount dedicated hard disk to /recordings/ path. Since codec is h264 variable bitrate i can write from 24 to 48 hours in this storage.

I want to server remove old files when no free space for new segment.

moenodedev commented 2 months ago

It's probably easier to delete unneeded files with cron or a periodic task. You can match on filename prefix like /recordings//2023 or timestamp.

alex-eri commented 2 months ago

Already

#!/bin/bash

RECPATH="/mnts/rec_temp"
FREESPACE=$(df --output=avail -B 1 ${RECPATH} | tail -n 1)

if [ ${FREESPACE} -lt 1073741824 ]
then
find "${RECPATH}" -type f -printf "%T@ %p\n" | sort -n | head -n 1 | tee /dev/stderr | cut -d' ' -f2 | xargs  echo rm
else
echo free space ${FREESPACE}
fi

but if mediamtx manages max age i think it can also manage space.

alex-eri commented 2 months ago
#!/bin/bash

RECPATH="/mnts/rec_temp"
FREESPACE=$(df --output=avail -B 1 ${RECPATH} | tail -n 1)

if [ ${FREESPACE} -lt 1073741824 ]
then
find "${RECPATH}" -type f -printf "%T@ %p\n" | sort -n | head -n 1 | tee /dev/stderr | cut -d' ' -f2 | xargs  echo rm
else
echo free space ${FREESPACE}
fi