HighInBC
17th February 2003, 17:59
I do not know if anyone out there will find this usefull, but here goes. I use a program called 'scanrec.exe' (http://www.davee.com/scanrec/index.html) and what it does is record any audio, it does not record silence. Un like other VOX recorders this program makes a log file showing when each audio snippet happened. soooo, I created a perl script that would generate an avs file to take the wav and reinsert silence. Why??
Well I go to local canabis rallies with my DV camera, it gives timestamps for each cut. I can leave my radio scanner rocrding the police freq @ home. and when I get back I can reinsert silence and synhc/dub it with the rally footage. I just synch my computer/cameras clock before I go out.
This script creates simple video that shows when each sound occured, this can be ignored and just the sound used. The higher the framerate you enter the better the synch would be, tho there is no real point in setting it higher than you final vid(I think). This script may still have bugs in it. Please respond with any comment/suggestions. Anywhoo, here is the perl script:
________________PERL_____________________
use strict;
use Time::Local;
my($prev_time,$prev_duration,$first_time,$frame_count);
my $target = 'scanner2';
my $fps = 29.97;
my $start_time = 0;#date_time2seconds('2003/02/12' , '19:00:00'); # set to 0 to start @ begining
my $end_time = 0;#date_time2seconds('2003/02/12' , '20:00:00'); # set to 0 to finish to end
my $header =
"audio = WAVSource(\"$target.wav\")
source = BlankClip(length=Ceil(Audiolength(audio) * $fps) , width=480,height=32,fps=$fps,audio_rate=8000,sixteen_bit=false,color=\$000000).\\
AudioDub(audio)
main =\\\n";
open (LOG , $target.'.log');
my @log = <LOG>;
close(LOG);
open (AVS , ">$target.avs");
print AVS ($header);
my @avs_lines;
while (scalar(@log))
{
my $line = shift(@log);
($line =~ s|\n||g);
if($line =~ m|(\d{4}/\d{2}/\d{2}),\s+(\d{2}:\d{2}:\d{2}),\s+(\d+\.\d),\s+(\d{2}:\d{2}:\d{2})|)
{
my $display_date = $1;
my $display_time = $2;
my $time = date_time2seconds($display_date,$display_time);
next if (($time < $start_time) && $start_time);
last if (($time > $end_time) && $end_time);
my $duration = $3 || '0';
my $rel_time = time2seconds($4) || '0';
$first_time ||= $time;
my $time_in_vid = $time - $first_time;
my $display_vid_time = time_conv($time_in_vid) || '0s';
my $frames_of_silence = (sprintf("%.0f", (($time_in_vid * $fps) - $frame_count)));
($frames_of_silence =~ s|^(.*)e.*$|$1|);
($frames_of_silence = 0) if ($frames_of_silence < 0);
my $start_frame = (sprintf("%.0f", $rel_time * $fps));
my $end_frame = (sprintf("%.0f", ($duration + $rel_time) * $fps));
my $length = ($end_frame - $start_frame);
push (@avs_lines , "(BlankClip(source , length=$frames_of_silence).Subtitle(\"Silence, next sound @ $display_vid_time(relative)\", text_color=\$FFFFFF, x=-1,y=21, size=18 , first_frame=0,last_frame=$frames_of_silence))+") if ($frames_of_silence);
push (@avs_lines , "(Trim(source , $start_frame , $end_frame).Subtitle(\"$line - $display_vid_time\", text_color=\$FFFFFF, x=-1,y=21, size=18 , first_frame=0,last_frame=$length))+\\\n");
$frame_count += $length+1;
$frame_count += $frames_of_silence;
$prev_duration = $duration;
$prev_time = $time;
}
}
($avs_lines[scalar(@avs_lines)-1] =~ s|\+\\||);
print AVS (join('' , @avs_lines));
print AVS ("return main\n");
close(AVS);
sub time2seconds
{
my $time = $_[0];
($time =~ m|^(\d{1,2}):(\d{2}):(\d{2})$|);
my $hours = $1;
my $minutes = $2;
my $seconds = $3;
my $secs = (($hours * 3600) + ($minutes * 60) + $seconds);
return $secs;
}
sub date_time2seconds
{
my ($date,$time) = @_;
($date =~ m|^(\d{4})/(\d{2})/(\d{2})$|) || return 0;
my $year = $1;
my $mon = $2;
my $mday = $3;
($time =~ m|^(\d{2}):(\d{2}):(\d{2})$|) || return 0;
my $hours = $1;
my $min = $2;
my $sec = $3;
return timelocal($sec,$min,$hours,$mday,$mon,$year);
}
sub time_conv
{
my($seconds)= $_[0];
return (undef) unless ($seconds);
my($result , $used);
my($days) = int($seconds/86400);
$used += ($days*86400);
my($hours) = int(($seconds - $used)/3600);
$used += ($hours*3600);
my($minutes) = int(($seconds - $used)/60);
$used += ($minutes*60);
$seconds = int(($seconds - $used));
$result = $days. 'd' if ($days);
$result .= $hours. 'h' if ($hours);
$result .= $minutes.'m' if ($minutes);
$result .= $seconds.'s' if ($seconds);
return($result || '0s');
}
____________END_PERL______________
Well I go to local canabis rallies with my DV camera, it gives timestamps for each cut. I can leave my radio scanner rocrding the police freq @ home. and when I get back I can reinsert silence and synhc/dub it with the rally footage. I just synch my computer/cameras clock before I go out.
This script creates simple video that shows when each sound occured, this can be ignored and just the sound used. The higher the framerate you enter the better the synch would be, tho there is no real point in setting it higher than you final vid(I think). This script may still have bugs in it. Please respond with any comment/suggestions. Anywhoo, here is the perl script:
________________PERL_____________________
use strict;
use Time::Local;
my($prev_time,$prev_duration,$first_time,$frame_count);
my $target = 'scanner2';
my $fps = 29.97;
my $start_time = 0;#date_time2seconds('2003/02/12' , '19:00:00'); # set to 0 to start @ begining
my $end_time = 0;#date_time2seconds('2003/02/12' , '20:00:00'); # set to 0 to finish to end
my $header =
"audio = WAVSource(\"$target.wav\")
source = BlankClip(length=Ceil(Audiolength(audio) * $fps) , width=480,height=32,fps=$fps,audio_rate=8000,sixteen_bit=false,color=\$000000).\\
AudioDub(audio)
main =\\\n";
open (LOG , $target.'.log');
my @log = <LOG>;
close(LOG);
open (AVS , ">$target.avs");
print AVS ($header);
my @avs_lines;
while (scalar(@log))
{
my $line = shift(@log);
($line =~ s|\n||g);
if($line =~ m|(\d{4}/\d{2}/\d{2}),\s+(\d{2}:\d{2}:\d{2}),\s+(\d+\.\d),\s+(\d{2}:\d{2}:\d{2})|)
{
my $display_date = $1;
my $display_time = $2;
my $time = date_time2seconds($display_date,$display_time);
next if (($time < $start_time) && $start_time);
last if (($time > $end_time) && $end_time);
my $duration = $3 || '0';
my $rel_time = time2seconds($4) || '0';
$first_time ||= $time;
my $time_in_vid = $time - $first_time;
my $display_vid_time = time_conv($time_in_vid) || '0s';
my $frames_of_silence = (sprintf("%.0f", (($time_in_vid * $fps) - $frame_count)));
($frames_of_silence =~ s|^(.*)e.*$|$1|);
($frames_of_silence = 0) if ($frames_of_silence < 0);
my $start_frame = (sprintf("%.0f", $rel_time * $fps));
my $end_frame = (sprintf("%.0f", ($duration + $rel_time) * $fps));
my $length = ($end_frame - $start_frame);
push (@avs_lines , "(BlankClip(source , length=$frames_of_silence).Subtitle(\"Silence, next sound @ $display_vid_time(relative)\", text_color=\$FFFFFF, x=-1,y=21, size=18 , first_frame=0,last_frame=$frames_of_silence))+") if ($frames_of_silence);
push (@avs_lines , "(Trim(source , $start_frame , $end_frame).Subtitle(\"$line - $display_vid_time\", text_color=\$FFFFFF, x=-1,y=21, size=18 , first_frame=0,last_frame=$length))+\\\n");
$frame_count += $length+1;
$frame_count += $frames_of_silence;
$prev_duration = $duration;
$prev_time = $time;
}
}
($avs_lines[scalar(@avs_lines)-1] =~ s|\+\\||);
print AVS (join('' , @avs_lines));
print AVS ("return main\n");
close(AVS);
sub time2seconds
{
my $time = $_[0];
($time =~ m|^(\d{1,2}):(\d{2}):(\d{2})$|);
my $hours = $1;
my $minutes = $2;
my $seconds = $3;
my $secs = (($hours * 3600) + ($minutes * 60) + $seconds);
return $secs;
}
sub date_time2seconds
{
my ($date,$time) = @_;
($date =~ m|^(\d{4})/(\d{2})/(\d{2})$|) || return 0;
my $year = $1;
my $mon = $2;
my $mday = $3;
($time =~ m|^(\d{2}):(\d{2}):(\d{2})$|) || return 0;
my $hours = $1;
my $min = $2;
my $sec = $3;
return timelocal($sec,$min,$hours,$mday,$mon,$year);
}
sub time_conv
{
my($seconds)= $_[0];
return (undef) unless ($seconds);
my($result , $used);
my($days) = int($seconds/86400);
$used += ($days*86400);
my($hours) = int(($seconds - $used)/3600);
$used += ($hours*3600);
my($minutes) = int(($seconds - $used)/60);
$used += ($minutes*60);
$seconds = int(($seconds - $used));
$result = $days. 'd' if ($days);
$result .= $hours. 'h' if ($hours);
$result .= $minutes.'m' if ($minutes);
$result .= $seconds.'s' if ($seconds);
return($result || '0s');
}
____________END_PERL______________