I went ahead and came up with this script.
Hope that helps. ![]()
Script "VIDEO__Record_LiveStreamWithTimeStamp.sh":
(EDIT: removed spurious "-t" in function)
#!/bin/bash
####################################################################################################
###
### Script to simplify interraction with ffmpeg for recording from video stream
###
### REF: https://askubuntu.com/a/428501
### REF: https://ubuntu-mate.community/t/cheese-recording-not-showing-landlord-coming-into-my-trailer-for-repair/28390/9
###
####################################################################################################
####################################################################################################
recordSegment()
{
###
### Options used in REF which were not used by Pavlos in his response demo
###
# -f video4linux2 \
# -s 640x480 \
# -r 30 \
# -vcodec libx264 \
# -vb 2000k \
ffmpeg \
-i /dev/video0 \
-preset ultrafast \
${segInterval} \
-vf "${textOverlayParameters}" \
-f mp4 "${videoFile}"
}
####################################################################################################
recordSlice()
{
videoFile="${videoFilePref}_${sliceStart}.mp4"
printf "\n\t Starting capture of video stream for next ${sliceMax} minutes as:\n\t -> ${videoFile}\n"
recordSegment
}
####################################################################################################
###
### 'drawtext' option specifications
###
#fontSpec="fontfile=DejaVuSans-Bold.ttf"
fontSpec="fontfile=FreeMono.ttf"
#timeFmt="text='\\%T'"
timeFmt="text='\\%{localtime}'"
fontClr="[email protected]"
timePosn="x=7:y=460"
textOverlayParameters="drawtext=${fontSpec}:${timeFmt}:${fontClr}:${timePosn}"
#echo ${textOverlayParameters}
#exit
####################################################################################################
mode=1
timeTot=0
timeWait=0
count=0
label=0
videoFilePref="vidrecord"
sliceMax=0
while [ $# -gt 0 ]
do
case "${1}" in
"--single" )
mode=1
shift
;;
"--slices" )
### number of recording slices to cover specified duration
mode=2
slices="${2}"
shift ; shift
;;
"--duration" )
### total recording time [ units in hours ]
timeTot="${2}"
count=1
shift ; shift
;;
"--wait" )
### wait time before start [ units in minutes ]
timeWait="${2}"
shift ; shift
;;
"--label" )
videoFilePref="${2}"
shift ; shift
;;
"--label_int" )
label=1
shift
;;
"--label_hms" )
label=0
shift
;;
"--debug" )
dbg=1
shift
;;
* ) printf "\n\t Invalid parameter used on command line. \n\t Only valid: [ --single | --slices {count} ] [ --duration {hours} ] [ --wait {minutes} ] [ --label {string} ] [ --label_int | --label_hms ] [ --debug ] \n Bye!\n\n" ; exit 1
esac
done
####################################################################################################
if [ ${mode} -eq 1 ]
then
test ${timeTot} -eq 0 && { printf "\n\t ERROR: Need to specify total record time with '--duration {hours}' option.\n Bye!\n\n" ; exit 1 ; }
if [ ${timeWait} -gt 0 ]
then
printf "\n\t WAITING ${timeWait} minute(s) before proceed with video recording ...\n\n"
hTime=$( expr ${timeWait} \* 60 )
sleep ${hTime}
fi
sliceMax=$( expr ${timeTot} \* 60 )
segInterval="-t $( expr ${sliceMax} \* 60 )"
if [ ${label} -eq 1 ]
then
sliceStart="$(date '+%Y%m%d_%H%M' )_${sliceMax}m"
else
sliceStart=$(date '+%Y%m%d_%H%M%S' )
fi
recordSlice
exit
fi
if [ ${mode} -eq 2 ]
then
test ${timeTot} -eq 0 && { printf "\n\t ERROR: Need to specify total record time with '--duration {hours}' option.\n Bye!\n\n" ; exit 1 ; }
if [ ${timeWait} -gt 0 ]
then
printf "\n\t WAITING ${timeWait} minute(s) before proceed with video recording ...\n\n"
hTime=$( expr ${timeWait} \* 60 )
sleep ${hTime}
fi
duration=$( expr ${timeTot} \* 60 )
sliceMax=$( expr ${duration} / ${slices} )
segInterval="-t $( expr ${sliceMax} \* 60 )"
indx=0
while [ ${indx} -lt ${slices} ]
do
if [ ${label} -eq 1 ]
then
sliceStart="$(date '+%Y%m%d_%H%M' )_${sliceMax}m"
else
sliceStart=$(date '+%Y%m%d_%H%M%S' )
fi
recordSlice
indx=$( expr ${indx} + 1 )
done
exit
fi
exit
Session log for "--single" mode:
./VIDEO__Record_LiveStreamWithTimeStamp.sh --single --duration 2 --label_int
Starting capture of video stream for next 120 minutes as:
-> vidrecord_20241024_1741_120m.mp4
Session log with "--slices" mode:
./VIDEO__Record_LiveStreamWithTimeStamp.sh --slices 6 --duration 2 --label_hms
Starting capture of video stream for next 20 minutes as:
-> vidrecord_20241024_181047.mp4
Starting capture of video stream for next 20 minutes as:
-> vidrecord_20241024_183047.mp4
Starting capture of video stream for next 20 minutes as:
-> vidrecord_20241024_185047.mp4
Starting capture of video stream for next 20 minutes as:
-> vidrecord_20241024_191047.mp4
Starting capture of video stream for next 20 minutes as:
-> vidrecord_20241024_193047.mp4
Starting capture of video stream for next 20 minutes as:
-> vidrecord_20241024_195047.mp4