My use case for this has been to have a daily recap of any clips that were triggered by motion.
Specifically, I have main and sub feeds, with sub-feeds doing mocord (record 247 but tag events), and the main feeds doing nodect, linked to the sub feed (so detection happens on the 480p feed, and if there's motion, it starts recording the 1080p high bitrate feed).
So, I want a recap of just the high res videos.
I used to do this with ffmpeg, with two back to back rounds. First, to do the timelapse speed up, put a timeline on top of the videos as well as overlay text with the event name, then second, to concat and re-encode.
This was absurdly slow, so I wanted to do it in one pass.
The tool I ended up using was libmlt through melt, which is what is behind kdenlive the video editor.
Then, I kick this off in a cron job.
The thing that gets the speedup is the timewarp, which I found from digging into how the Kdenlive speed on clips works since it worked well.
30:1 at 30 fps means each second becomes 1 frame
NOTE: This is terribly messy code, and was written over 5 years ago. It's messy, building up the CLI tags then running it, but it has also worked every night for just about 2000 days.
I'm sure you can get Claude to do something nicer if you so wish.
#!/usr/bin/bash
SDATE=$(date -d yesterday +"%Y-%m-%d")
#SDATE="$1"
rm /tmp/*.txt;
#note moved files to include sdate so multiple scripts can run at once
find ../../CCTV/1/"${SDATE}" -mindepth 1 -name "*.mp4" > /tmp/files-${SDATE}.txt;
find ../../CCTV/3/"${SDATE}" -mindepth 1 -name "*.mp4" >> /tmp/files-${SDATE}.txt;
find ../../CCTV/5/"${SDATE}" -mindepth 1 -name "*.mp4" >> /tmp/files-${SDATE}.txt;
find ../../CCTV/7/"${SDATE}" -mindepth 1 -name "*.mp4" >> /tmp/files-${SDATE}.txt;
cat /tmp/files-${SDATE}.txt | sort -t / -k5 -V | tee /tmp/sorted-${SDATE}.txt
command=""
for f in `cat /tmp/sorted-${SDATE}.txt`; do \
even=`echo $f | cut -d'/' -f7 | cut -c -7`;
#event=`echo EVENT_${even}`; #for some reason it does not like this
command="$command timewarp:30:$f warp_pitch=1 -attach dynamictext:${even} size=28 fgcolour=white bgcolour=black weight=700 family=mono"
#command="$command timewarp:30:$f warp_pitch=1 -attach timer direction=down speed=30 size=20 fgcolour=white bgcolour=black family=mono "
done;
# todo at some point get custom codecs working
# echo "-profile hdv_1080_30p -progress -consumer avformat:cctv-${SDATE}.mkv acodec=libvorbis vcodec=libx265" | tee -a command.txt
echo $command | tee /tmp/command-${SDATE}.txt
# note xfvb used for running headless via cron
nice -19 xvfb-run -a melt ${command} -profile atsc_1080p_30 -progress -consumer avformat:cctv-${SDATE}.mkv acodec=libvorbis vcodec=libx265 crf=26 g=240 ac=1 threads=12 ab=64k
mv -vf cctv-${SDATE}.mkv /data/NAS/CCTV/Timelapse/