<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.elphel.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Xab</id>
	<title>ElphelWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.elphel.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Xab"/>
	<link rel="alternate" type="text/html" href="https://wiki.elphel.com/wiki/Special:Contributions/Xab"/>
	<updated>2026-08-03T03:20:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://wiki.elphel.com/index.php?title=Cctv&amp;diff=5468</id>
		<title>Cctv</title>
		<link rel="alternate" type="text/html" href="https://wiki.elphel.com/index.php?title=Cctv&amp;diff=5468"/>
		<updated>2009-01-30T08:18:45Z</updated>

		<summary type="html">&lt;p&gt;Xab: Quick and Dirty cctv scripts&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
Here is a couple of script to put online a cctv environement based on Mencoder/Mplayer.&lt;br /&gt;
&lt;br /&gt;
The idea is to have a cctv server with enough storage grabing rtsp unicast stream with the timestamp incrusted onscreen.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Hardware =&lt;br /&gt;
&lt;br /&gt;
Server: &lt;br /&gt;
&lt;br /&gt;
Dell poweredge 1970&lt;br /&gt;
 &lt;br /&gt;
1 quad core Intel Xeon &lt;br /&gt;
&lt;br /&gt;
8go of ram and &lt;br /&gt;
&lt;br /&gt;
500G of disk.&lt;br /&gt;
&lt;br /&gt;
4x Elphel 333.&lt;br /&gt;
&lt;br /&gt;
= Setup =&lt;br /&gt;
A user cctv created locally with /var/cctv as home.&lt;br /&gt;
&lt;br /&gt;
All videos will be stored in /var/cctv/videos/&lt;br /&gt;
&lt;br /&gt;
The goal is to have a script launched everyday that will start a new file with timestamp as name followd by camera number, stop existing recording and cleanup old videos (due to legal reason no more than 30 days must be kept).&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
The tricky part is to generate osd with the same timestamp as the start of the recording.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== OSD generation ===&lt;br /&gt;
&lt;br /&gt;
This script will generate subtitles in srt format &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/perl -w&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
my $start=time();&lt;br /&gt;
#will generate a day of timestamp&lt;br /&gt;
my $end=$start+86400;&lt;br /&gt;
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );&lt;br /&gt;
my $h=0;&lt;br /&gt;
my $m=0;&lt;br /&gt;
my $s=0;&lt;br /&gt;
&lt;br /&gt;
my ($sec2,$min2,$hour2,$mday2,$mon2,$year2) = localtime($start);&lt;br /&gt;
while ($start&amp;lt;$end)&lt;br /&gt;
{&lt;br /&gt;
  if ($s &amp;lt;= 59){&lt;br /&gt;
    $s++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($s == 60){&lt;br /&gt;
    $s=0;&lt;br /&gt;
    $m++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($m == 60){&lt;br /&gt;
    $m=0;&lt;br /&gt;
    $h++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($h==24){&lt;br /&gt;
  $h=0;&lt;br /&gt;
                                     }&lt;br /&gt;
  my ($sec,$min,$hour,$mday,$mon,$year)=($sec2,$min2,$hour2,$mday2,$mon2,$year2);&lt;br /&gt;
  $start++;&lt;br /&gt;
  ($sec2,$min2,$hour2,$mday2,$mon2,$year2) = localtime($start);&lt;br /&gt;
&lt;br /&gt;
 $year2+=1900;&lt;br /&gt;
 printf &amp;quot;%02d:%02d:%02d,001--&amp;gt;%02d:%02d:%02d,1000\n&amp;quot;,$h,$m,$s,$h,$m,$s;&lt;br /&gt;
 printf  &amp;quot;%02d:%02d:%02d %02d/%s/%02d\n\n&amp;quot;,$hour,$min,$sec,$mday,$abbr[$mon],$year;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will generate output like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
06:38:57,001--&amp;gt;06:38:57,1000&lt;br /&gt;
02:13:42 30/Jan/2009&lt;br /&gt;
&lt;br /&gt;
1.timeline from the begining of video (6 hours and 38 minutes since video started)&lt;br /&gt;
2.localtime and date&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Starting/Stopping and incrust ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
path=&amp;quot;/usr/local/bin&amp;quot;;&lt;br /&gt;
wdir=&amp;quot;/var/cctv&amp;quot;;&lt;br /&gt;
logsd=&amp;quot;$wdir/logs&amp;quot;&lt;br /&gt;
videosd=&amp;quot;$wdir/videos&amp;quot;;&lt;br /&gt;
subd=&amp;quot;$wdir/subs&amp;quot;;&lt;br /&gt;
rund=&amp;quot;$wdir/run&amp;quot;;&lt;br /&gt;
today=$(date +%y%m%d);&lt;br /&gt;
&lt;br /&gt;
for cam in cam0 cam1 cam2 cam3; do&lt;br /&gt;
# Check if recording already running&lt;br /&gt;
if [[ -e $rund/$cam.pid ]]; then&lt;br /&gt;
  pid=$(cat $rund/$cam.pid)&lt;br /&gt;
# Wait until process killed&lt;br /&gt;
  while [[ $(ps -p $pid  | grep $pid) != &amp;quot;&amp;quot; ]]&lt;br /&gt;
   do&lt;br /&gt;
    print &amp;quot;Trying cleannig process $cam&amp;quot;&lt;br /&gt;
    kill -15 $pid&lt;br /&gt;
    sleep 2&lt;br /&gt;
   done&lt;br /&gt;
  rm -f $rund/$cam.pid&lt;br /&gt;
fi&lt;br /&gt;
  # Generate timestamp&lt;br /&gt;
  now=$(date +%Y%m%d%H%M%S);&lt;br /&gt;
  srt=&amp;quot;$now-$cam.srt&amp;quot;;&lt;br /&gt;
  # Generate subtitles&lt;br /&gt;
  /home/cctv/bin/gensubsrt.pl &amp;gt; $subd/$srt;&lt;br /&gt;
  # start recording and incrusting timestamp on screen &lt;br /&gt;
  $path/mencoder rtsp://$cam -sub $subd/$srt -o $videosd/$now-$cam.avi \&lt;br /&gt;
  -quiet -ovc lavc -vf scale=640:480 &amp;lt; /dev/null &amp;gt; $logsd/$now-$cam 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
  # Store the pid to next kill&lt;br /&gt;
  print $! &amp;gt; $rund/$cam.pid;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cleanup ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use POSIX;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
my $days = 30; #how many days to keep&lt;br /&gt;
my $max_age = $days*86400;&lt;br /&gt;
my @files = glob(&#039;/var/cctv/videos/*&#039;);&lt;br /&gt;
my $now = time();&lt;br /&gt;
&lt;br /&gt;
for my $file (@files){&lt;br /&gt;
  if ( $file =~ /\/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})[^\/]+$/ ){&lt;br /&gt;
    my ($year,$month,$day,$hour,$min,$sec) = ($1,$2,$3,$4,$5,$6);&lt;br /&gt;
    my $file_age = $now-mktime($sec,$min,$hour,$day,$month-1,$year-1900);&lt;br /&gt;
    if ( $file_age &amp;gt; $max_age ) {&lt;br /&gt;
      print &amp;quot;$file too old deleting...\n&amp;quot;;&lt;br /&gt;
      unlink $file;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:Xab|xab]] 02:18, 30 January 2009 (CST)&lt;/div&gt;</summary>
		<author><name>Xab</name></author>
	</entry>
	<entry>
		<id>https://wiki.elphel.com/index.php?title=Cctv&amp;diff=5467</id>
		<title>Cctv</title>
		<link rel="alternate" type="text/html" href="https://wiki.elphel.com/index.php?title=Cctv&amp;diff=5467"/>
		<updated>2009-01-29T18:49:27Z</updated>

		<summary type="html">&lt;p&gt;Xab: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
Here is a couple of script to put online a cctv environement based on Mencoder/Mplayer.&lt;br /&gt;
&lt;br /&gt;
The idea is to have a cctv server with enough storage grabing rtsp unicast stream with the timestamp incrusted onscreen.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Hardware =&lt;br /&gt;
&lt;br /&gt;
Server: &lt;br /&gt;
&lt;br /&gt;
Dell poweredge 1970&lt;br /&gt;
 &lt;br /&gt;
1 quad core Intel Xeon &lt;br /&gt;
&lt;br /&gt;
8go of ram and &lt;br /&gt;
&lt;br /&gt;
500G of disk.&lt;br /&gt;
&lt;br /&gt;
4x Elphel 353.&lt;br /&gt;
&lt;br /&gt;
= Setup =&lt;br /&gt;
A user cctv created locally with /var/cctv as home.&lt;br /&gt;
&lt;br /&gt;
All videos will be stored in /var/cctv/videos/&lt;br /&gt;
&lt;br /&gt;
The goal is to have a script launched everyday that will start a new file with timestamp as name followd by camera number, stop existing recording and cleanup old videos (due to legal reason no more than 30 days must be kept).&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
The tricky part is to generate osd with the same timestamp as the start of the recording.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== OSD generation ===&lt;br /&gt;
&lt;br /&gt;
This script will generate subtitles in srt format &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/perl -w&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
my $start=time();&lt;br /&gt;
#will generate a day of timestamp&lt;br /&gt;
my $end=$start+86400;&lt;br /&gt;
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );&lt;br /&gt;
my $h=0;&lt;br /&gt;
my $m=0;&lt;br /&gt;
my $s=0;&lt;br /&gt;
&lt;br /&gt;
my ($sec2,$min2,$hour2,$mday2,$mon2,$year2) = localtime($start);&lt;br /&gt;
while ($start&amp;lt;$end)&lt;br /&gt;
{&lt;br /&gt;
  if ($s &amp;lt;= 59){&lt;br /&gt;
    $s++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($s == 60){&lt;br /&gt;
    $s=0;&lt;br /&gt;
    $m++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($m == 60){&lt;br /&gt;
    $m=0;&lt;br /&gt;
    $h++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($h==24){&lt;br /&gt;
  $h=0;&lt;br /&gt;
                                     }&lt;br /&gt;
  my ($sec,$min,$hour,$mday,$mon,$year)=($sec2,$min2,$hour2,$mday2,$mon2,$year2);&lt;br /&gt;
  $start++;&lt;br /&gt;
  ($sec2,$min2,$hour2,$mday2,$mon2,$year2) = localtime($start);&lt;br /&gt;
&lt;br /&gt;
 $year2+=1900;&lt;br /&gt;
 printf &amp;quot;%02d:%02d:%02d,001--&amp;gt;%02d:%02d:%02d,1000\n&amp;quot;,$h,$m,$s,$h,$m,$s;&lt;br /&gt;
 printf  &amp;quot;%02d:%02d:%02d %02d/%s/%02d\n\n&amp;quot;,$hour,$min,$sec,$mday,$abbr[$mon],$year;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will generate output like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
06:38:57,001--&amp;gt;06:38:57,1000&lt;br /&gt;
02:13:42 30/Jan/2009&lt;br /&gt;
&lt;br /&gt;
1.timeline from the begining of video (6 hours and 38 minutes since video started)&lt;br /&gt;
2.localtime and date&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Starting/Stopping and incrust ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
path=&amp;quot;/usr/local/bin&amp;quot;;&lt;br /&gt;
wdir=&amp;quot;/var/cctv&amp;quot;;&lt;br /&gt;
logsd=&amp;quot;$wdir/logs&amp;quot;&lt;br /&gt;
videosd=&amp;quot;$wdir/videos&amp;quot;;&lt;br /&gt;
subd=&amp;quot;$wdir/subs&amp;quot;;&lt;br /&gt;
rund=&amp;quot;$wdir/run&amp;quot;;&lt;br /&gt;
today=$(date +%y%m%d);&lt;br /&gt;
&lt;br /&gt;
for cam in cam0 cam1 cam2 cam3; do&lt;br /&gt;
# Check if recording already running&lt;br /&gt;
if [[ -e $rund/$cam.pid ]]; then&lt;br /&gt;
  pid=$(cat $rund/$cam.pid)&lt;br /&gt;
# Wait until process killed&lt;br /&gt;
  while [[ $(ps -p $pid  | grep $pid) != &amp;quot;&amp;quot; ]]&lt;br /&gt;
   do&lt;br /&gt;
    print &amp;quot;Trying cleannig process $cam&amp;quot;&lt;br /&gt;
    kill -15 $pid&lt;br /&gt;
    sleep 2&lt;br /&gt;
   done&lt;br /&gt;
  rm -f $rund/$cam.pid&lt;br /&gt;
fi&lt;br /&gt;
  # Generate timestamp&lt;br /&gt;
  now=$(date +%Y%m%d%H%M%S);&lt;br /&gt;
  srt=&amp;quot;$now-$cam.srt&amp;quot;;&lt;br /&gt;
  # Generate subtitles&lt;br /&gt;
  /home/cctv/bin/gensubsrt.pl &amp;gt; $subd/$srt;&lt;br /&gt;
  # start recording and incrusting timestamp on screen &lt;br /&gt;
  $path/mencoder rtsp://$cam -sub $subd/$srt -o $videosd/$now-$cam.avi \&lt;br /&gt;
  -quiet -ovc lavc -vf scale=640:480 &amp;lt; /dev/null &amp;gt; $logsd/$now-$cam 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
  # Store the pid to next kill&lt;br /&gt;
  print $! &amp;gt; $rund/$cam.pid;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cleanup ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use POSIX;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
my $days = 30; #how many days to keep&lt;br /&gt;
my $max_age = $days*86400;&lt;br /&gt;
my @files = glob(&#039;/var/cctv/videos/*&#039;);&lt;br /&gt;
my $now = time();&lt;br /&gt;
&lt;br /&gt;
for my $file (@files){&lt;br /&gt;
  if ( $file =~ /\/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})[^\/]+$/ ){&lt;br /&gt;
    my ($year,$month,$day,$hour,$min,$sec) = ($1,$2,$3,$4,$5,$6);&lt;br /&gt;
    my $file_age = $now-mktime($sec,$min,$hour,$day,$month-1,$year-1900);&lt;br /&gt;
    if ( $file_age &amp;gt; $max_age ) {&lt;br /&gt;
      print &amp;quot;$file too old deleting...\n&amp;quot;;&lt;br /&gt;
      unlink $file;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:Xab|xab]] 12:49, 29 January 2009 (CST)&lt;/div&gt;</summary>
		<author><name>Xab</name></author>
	</entry>
	<entry>
		<id>https://wiki.elphel.com/index.php?title=Cctv&amp;diff=5466</id>
		<title>Cctv</title>
		<link rel="alternate" type="text/html" href="https://wiki.elphel.com/index.php?title=Cctv&amp;diff=5466"/>
		<updated>2009-01-29T18:48:07Z</updated>

		<summary type="html">&lt;p&gt;Xab: quick and dirty cctv scripts&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
Here is a couple of script to put online a cctv environement based on Mencoder/Mplayer.&lt;br /&gt;
&lt;br /&gt;
The idea is to have a cctv server with enough storage grabing rtsp unicast stream with the timestamp incrusted onscreen.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Hardware =&lt;br /&gt;
&lt;br /&gt;
Server: &lt;br /&gt;
&lt;br /&gt;
Dell poweredge 1970&lt;br /&gt;
 &lt;br /&gt;
1 quad core Intel Xeon &lt;br /&gt;
&lt;br /&gt;
8go of ram and &lt;br /&gt;
&lt;br /&gt;
500G of disk.&lt;br /&gt;
&lt;br /&gt;
4x Elphel 353.&lt;br /&gt;
&lt;br /&gt;
= Setup =&lt;br /&gt;
A user cctv created locally with /var/cctv as home.&lt;br /&gt;
&lt;br /&gt;
All videos will be stored in /var/cctv/videos/&lt;br /&gt;
&lt;br /&gt;
The goal is to have a script launched everyday that will start a new file with timestamp as name followd by camera number, stop existing recording and cleanup old videos (due to legal reason no more than 30 days must be kept).&lt;br /&gt;
&lt;br /&gt;
== Scripts ==&lt;br /&gt;
The tricky part is to generate osd with the same timestamp as the start of the recording.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== OSD generation ===&lt;br /&gt;
&lt;br /&gt;
This script will generate subtitles in srt format &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/perl -w&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
my $start=time();&lt;br /&gt;
#will generate a day of timestamp&lt;br /&gt;
my $end=$start+86400;&lt;br /&gt;
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );&lt;br /&gt;
my $h=0;&lt;br /&gt;
my $m=0;&lt;br /&gt;
my $s=0;&lt;br /&gt;
&lt;br /&gt;
my ($sec2,$min2,$hour2,$mday2,$mon2,$year2) = localtime($start);&lt;br /&gt;
while ($start&amp;lt;$end)&lt;br /&gt;
{&lt;br /&gt;
  if ($s &amp;lt;= 59){&lt;br /&gt;
    $s++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($s == 60){&lt;br /&gt;
    $s=0;&lt;br /&gt;
    $m++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($m == 60){&lt;br /&gt;
    $m=0;&lt;br /&gt;
    $h++;&lt;br /&gt;
  }&lt;br /&gt;
  if ($h==24){&lt;br /&gt;
  $h=0;&lt;br /&gt;
                                     }&lt;br /&gt;
  my ($sec,$min,$hour,$mday,$mon,$year)=($sec2,$min2,$hour2,$mday2,$mon2,$year2);&lt;br /&gt;
  $start++;&lt;br /&gt;
  ($sec2,$min2,$hour2,$mday2,$mon2,$year2) = localtime($start);&lt;br /&gt;
&lt;br /&gt;
 $year2+=1900;&lt;br /&gt;
 printf &amp;quot;%02d:%02d:%02d,001--&amp;gt;%02d:%02d:%02d,1000\n&amp;quot;,$h,$m,$s,$h,$m,$s;&lt;br /&gt;
 printf  &amp;quot;%02d:%02d:%02d %02d/%s/%02d\n\n&amp;quot;,$hour,$min,$sec,$mday,$abbr[$mon],$year;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will generate output like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
06:38:57,001--&amp;gt;06:38:57,1000&lt;br /&gt;
02:13:42 30/Jan/2009&lt;br /&gt;
&lt;br /&gt;
1.timeline from the begining of video (6 hours and 38 minutes since video started)&lt;br /&gt;
2.localtime and date&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Starting/Stopping and incrust ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
path=&amp;quot;/usr/local/bin&amp;quot;;&lt;br /&gt;
wdir=&amp;quot;/var/cctv&amp;quot;;&lt;br /&gt;
logsd=&amp;quot;$wdir/logs&amp;quot;&lt;br /&gt;
videosd=&amp;quot;$wdir/videos&amp;quot;;&lt;br /&gt;
subd=&amp;quot;$wdir/subs&amp;quot;;&lt;br /&gt;
rund=&amp;quot;$wdir/run&amp;quot;;&lt;br /&gt;
today=$(date +%y%m%d);&lt;br /&gt;
&lt;br /&gt;
for cam in cam0 cam1 cam2 cam3; do&lt;br /&gt;
# Check if recording already running&lt;br /&gt;
if [[ -e $rund/$cam.pid ]]; then&lt;br /&gt;
  pid=$(cat $rund/$cam.pid)&lt;br /&gt;
# Wait until process killed&lt;br /&gt;
  while [[ $(ps -p $pid  | grep $pid) != &amp;quot;&amp;quot; ]]&lt;br /&gt;
   do&lt;br /&gt;
    print &amp;quot;Trying cleannig process $cam&amp;quot;&lt;br /&gt;
    kill -15 $pid&lt;br /&gt;
    sleep 2&lt;br /&gt;
   done&lt;br /&gt;
  rm -f $rund/$cam.pid&lt;br /&gt;
fi&lt;br /&gt;
  # Generate timestamp&lt;br /&gt;
  now=$(date +%Y%m%d%H%M%S);&lt;br /&gt;
  srt=&amp;quot;$now-$cam.srt&amp;quot;;&lt;br /&gt;
  # Generate subtitles&lt;br /&gt;
  /home/cctv/bin/gensubsrt.pl &amp;gt; $subd/$srt;&lt;br /&gt;
  # start recording and incrusting timestamp on screen &lt;br /&gt;
  $path/mencoder rtsp://$cam -sub $subd/$srt -o $videosd/$now-$cam.avi \&lt;br /&gt;
  -quiet -ovc lavc -vf scale=640:480 &amp;lt; /dev/null &amp;gt; $logsd/$now-$cam 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
  # Store the pid to next kill&lt;br /&gt;
  print $! &amp;gt; $rund/$cam.pid;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cleanup ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl -w&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use POSIX;&lt;br /&gt;
use Time::Local;&lt;br /&gt;
&lt;br /&gt;
my $days = 30; #how many days to keep&lt;br /&gt;
my $max_age = $days*86400;&lt;br /&gt;
my @files = glob(&#039;/var/cctv/videos/*&#039;);&lt;br /&gt;
my $now = time();&lt;br /&gt;
&lt;br /&gt;
for my $file (@files){&lt;br /&gt;
  if ( $file =~ /\/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})[^\/]+$/ ){&lt;br /&gt;
    my ($year,$month,$day,$hour,$min,$sec) = ($1,$2,$3,$4,$5,$6);&lt;br /&gt;
    my $file_age = $now-mktime($sec,$min,$hour,$day,$month-1,$year-1900);&lt;br /&gt;
    if ( $file_age &amp;gt; $max_age ) {&lt;br /&gt;
      print &amp;quot;$file too old deleting...\n&amp;quot;;&lt;br /&gt;
      unlink $file;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Xab</name></author>
	</entry>
</feed>