Copyright 2022 - Custom text here

ConcatenateVideoCamFiles.pl

#!perl.exe
use File::Basename;
use Win32::process;


$vddir = "C:\\Program Files\\video_tools\\VirtualDub-1.6.12";

$dir1 = $ARGV[0];

opendir BD1, $dir1 || die "Cannot open $dir1: $!";
foreach $d1 (readdir BD1) {
# We leave the special directories alone, or we'll never finish.
next if $d1 =~ /^\.{1,2}$/;
$dir2 = "$dir1\\$d1";
if( -d $dir2 ){
# print "$dir2\n";
opendir BD2, $dir2 || die "Cannot open $dir2: $!";
foreach $d2 (readdir BD2) {
# We leave the special directories alone, or we'll never finish.
next if $d2 =~ /^\.{1,2}$/;
$dir3 = "$dir2\\$d2";
if( -d "$dir3" ){
print "$dir3\n";
$dir25fps = "$dir3\\$d2 divx5";
if( !-f "$dir25fps.avi" ){
mkdirp($dir25fps, 0775);
uniform_framerate($dir3,$dir25fps);
concat("$dir25fps");
`rmdir /S/Q "$dir25fps"`;
}
}
}
closedir BD2 || die "Cannot close $dir2: $!";
}
}
closedir BD1 || die "Cannot close $dir1: $!";

sub uniform_framerate($)
{
my $directory = shift;
my $dir25 = shift;

opendir D, $directory || die "Cannot open $directory:";
foreach $f (readdir D) {
# We leave the special directories alone, or we'll never finish.
next if $f =~ /^\.{1,2}$/;
if( $f =~ /\.avi$/ ){

my $directory_bs = $directory;
$directory_bs =~ s/\\/\\\\/g; # with supplementary backslash
my $dir25_bs = $dir25;
$dir25_bs =~ s/\\/\\\\/g; # with supplementary backslash
my $vcf_file="conc.vcf";

open(VCF,">$vddir/conc.vcf") || die "Cannot open $vddir/conc.vcf: $!\n";
print VCF <<balise_vcf;
VirtualDub.Open("$directory_bs\\\\$f",0,0);
VirtualDub.audio.SetSource(1);
VirtualDub.audio.SetMode(0);
VirtualDub.audio.SetInterleave(1,500,1,0,0);
VirtualDub.audio.SetClipMode(1,1);
VirtualDub.audio.SetConversion(0,0,0,0,0);
VirtualDub.audio.SetVolume();
VirtualDub.audio.SetCompression();
VirtualDub.audio.EnableFilterGraph(0);
VirtualDub.video.SetDepth(24,24);
VirtualDub.video.SetMode(0);
VirtualDub.video.SetFrameRate(40000,1);
VirtualDub.video.SetIVTC(0,0,-1,0);
VirtualDub.video.SetCompression();
VirtualDub.video.filters.Clear();
VirtualDub.audio.filters.Clear();

VirtualDub.SaveAVI("$dir25_bs\\\\$f");
VirtualDub.Close();
balise_vcf
close(VCF);


Win32::Process::Create($ProcessObj,
"$vddir\\VirtualDub.exe",
"VirtualDub.exe /s\"$vcf_file\" /x /r",
0,
NORMAL_PRIORITY_CLASS,
$vddir) || die ErrorReport();

$exitcode = 1;

$ProcessObj->Wait(60000000);
$ProcessObj->GetExitCode( $exitcode );

if( $exitcode != 0 ){
$ProcessObj->Kill( $exitcode );
print "Process Killed<BR>\n";
}
}
}
closedir D || die "Cannot close $directory: $!";
}

sub concat($)
{
my $directory = shift;
$directory_bs = $directory;
$directory_bs =~ s/\\/\\\\/g; # with supplementary backslash
$vcf_file="conc.vcf";

open(VCF,">$vddir/conc.vcf") || die "Cannot open $vddir/conc.vcf: $!\n";

$i=0;
opendir D, $directory || die "Cannot open $directory:";
foreach $f (readdir D) {
# We leave the special directories alone, or we'll never finish.
next if $f =~ /^\.{1,2}$/;
if( $f =~ /\.avi$/ ){
if( $i==0) {
print VCF "VirtualDub.Open(\"$directory_bs\\\\$f\",0,0);\n";
}else{
print "$f\n";
print VCF "VirtualDub.Append(\"$directory_bs\\\\$f\");\n";
}
$i++;
}
}
closedir D || die "Cannot close $directory: $!";

print VCF <<balise_vcf;
VirtualDub.audio.SetSource(1);
VirtualDub.audio.SetMode(1);
VirtualDub.audio.SetInterleave(1,500,1,0,0);
VirtualDub.audio.SetClipMode(1,1);
VirtualDub.audio.SetConversion(0,0,0,0,0);
VirtualDub.audio.SetVolume();
VirtualDub.audio.SetCompression(85,48000,2,0,24000,1,12,"AQAEAAAAQAIBAAAA");
VirtualDub.audio.EnableFilterGraph(0);
VirtualDub.video.SetDepth(24,24);
VirtualDub.video.SetMode(3);
VirtualDub.video.SetFrameRate(0,1);
VirtualDub.video.SetIVTC(0,0,-1,0);
VirtualDub.video.SetCompression(0x78766964,0,10000,0);
VirtualDub.video.SetCompData(512,"zAEAAAAAAAAAAAAAMN4tAAAAgEABAAAAAAAAAAAAAAAAAAAAAAAAACwBAAAyAAAAIBFqAAAAMAAAACQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAmpmZmZmZyT+amZmZmZnJPwIAAAAAAAAAAAAAAIACAADgAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAZAAAAAAAAAABAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAgAAAAEAAAABAAAAAAAAAGM6XGRpdngubG9nAGM6XHRlc3QuZGl2eABjOlxtdmluZm8uYmluAGM6XG5ld3JjLnR4dAA=");
VirtualDub.SaveAVI("$directory_bs.avi");
VirtualDub.Close();
balise_vcf
close(VCF);
#DivX :
# VirtualDub.video.SetCompression(0x78766964,0,10000,0);
# VirtualDub.video.SetCompData(512,"zAEAAAAAAAAAAAAA4MgQAAAAgEABAAAAAAAAAAAAAAAAAAAAAAAAACwBAAAyAAAAIBFqAAAAMAAAACQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAmpmZmZmZyT+amZmZmZnJPwIAAAAAAAAAAAAAAIACAADgAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAZAAAAAAAAAABAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAgAAAAEAAAABAAAAAAAAAGM6XGRpdngubG9nAGM6XHRlc3QuZGl2eABjOlxtdmluZm8uYmluAGM6XG5ld3JjLnR4dAA=");

Win32::Process::Create($ProcessObj,
"$vddir\\VirtualDub.exe",
"VirtualDub.exe /s\"$vcf_file\" /x /r",
0,
NORMAL_PRIORITY_CLASS,
$vddir) || die ErrorReport();

$exitcode = 1;

$ProcessObj->Wait(60000000);
$ProcessObj->GetExitCode( $exitcode );

if( $exitcode != 0 ){
$ProcessObj->Kill( $exitcode );
print "Process Killed<BR>\n";
}
}

sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}


sub mkdirp
{
my($directory, $mode) = @_;
my @dirs = split(/\\/, $directory);
my $path = shift(@dirs); # build it as we go
my $result = 1; # assume it will work

unless (-d $path) {
$result &&= mkdir($path, $mode);
}

foreach (@dirs) {
$path .= "/$_";
if ( ! -d $path) {
$result &&= mkdir($path, $mode);
}
}

return $result;
}
f t g m