Transcode AVC H264 to HEVC H265 with timestamp using VLC

I've setup a Raspberry Pi NOIR camera for night-time monitoring.

The Raspberry Pi cannot encode H265 natively because it does not have the processing power nor the native video hardware encoder (especially the Pi Zero)

Recording a stream at a reasonable quality every night though with the NOIR camera would create hundreds of MB of files, every day.

That's a lot of data to write to an SD card, so I used my Ubuntu Server instead, which has an octo-core processor and SSDs.

To consume the stream, VLC can be used. It can also be used to overlay text and transcode the steam to another format.

HEVC uses much less space. A 1280x720 stream is only about 20MB for 30 minutes. Over 10 hours, that's about 400MB per day.

To do the transcode, here is the command:

cvlc "rtsp://10.0.0.123:8554/unicast" --play-and-exit --run-time 1800 --sout='#transcode{vcodec=h265,fps=15,aenc=none,sfilter=marq}:std{access=file,mux=mp4,dst=/mnt/picam/picamstream.mp4}'

I found that the time would stay after more than 30 minutes though, causing the video to be recorded, but the metadata to be wrong and the rest of the video could not be played. Though I'd like a solution to that, a workaround is to make the stream last 30 minutes and start a new file each time.

This script does it. I've also added a text overlay as a sub-filter:

#!/bin/bash

COUNTER=0
# 20 videos at 30 min each = 10 hours
while [  $COUNTER -lt 20 ]; do
    echo The counter is $COUNTER
    now=`date +"%Y-%m-%d-%H%M"`
    /usr/bin/cvlc "rtsp://10.0.0.123:8554/unicast" --sub-filter=marq --marq-marquee='%Y-%m-%d %H:%M:%S' --play-and-exit --run-time 1800 --sout='#transcode{vcodec=h265,fps=15,aenc=none,sfilter=marq}:std{access=file,mux=mp4,dst=/mnt/picam/picamstream.mp4}'
    mv /mnt/picam/picamstream.mp4 /mnt/picam/${now}.mp4
    let COUNTER=COUNTER+1 
done

This can be dropped into crontab and reliably records the stream every day.

Spot the Hamster!

Labels

DIY | Linux