Added video generation frame rate and scaling.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@651 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
parent
945e8e4145
commit
22490ebfac
|
@ -77,18 +77,24 @@ $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
|
||||||
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
||||||
|
|
||||||
my $event_id;
|
my $event_id;
|
||||||
|
my $rate = 1;
|
||||||
|
my $scale = 1;
|
||||||
|
my $overwrite = 0;
|
||||||
|
|
||||||
sub Usage
|
sub Usage
|
||||||
{
|
{
|
||||||
print( "
|
print( "
|
||||||
Usage: zmvideo.pl -e <event_id>,--event=<event_id>
|
Usage: zmvideo.pl -e <event_id>,--event=<event_id> [-r <rate>,--rate=<rate>] [-s <scale>,--scale=<scale>] [-o,--overwrite]
|
||||||
Parameters are :-
|
Parameters are :-
|
||||||
-e<event_id>, --event=<event_id> - What event to start create the video for
|
-e<event_id>, --event=<event_id> - What event to create the video for
|
||||||
|
-r<rate>, --rate=<rate> - Relative rate to use, 1 = realtime, 2 = double speed , -2 = half speed etc
|
||||||
|
-s<scale>, --scale=<scale> - Scale to use, 1 = normal, 2 = double size, -2 = half size etc
|
||||||
|
-o, --overwrite - Whether to overwrite an existing file, off by default.
|
||||||
");
|
");
|
||||||
exit( -1 );
|
exit( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !GetOptions( 'event=i'=>\$event_id ) )
|
if ( !GetOptions( 'event=i'=>\$event_id, 'rate=i'=>\$rate, 'scale=i'=>\$scale, 'overwrite'=>\$overwrite ) )
|
||||||
{
|
{
|
||||||
Usage();
|
Usage();
|
||||||
}
|
}
|
||||||
|
@ -105,6 +111,30 @@ if ( ZM_OPT_MPEG eq "no" )
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ZM_OPT_MPEG eq "mpeg_encode" && $rate != 1 )
|
||||||
|
{
|
||||||
|
print( STDERR "Variable rate not supported with mpeg_encode\n" );
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $rate < -4 || $rate > 10 )
|
||||||
|
{
|
||||||
|
print( STDERR "Rate is out of range, -4 >= rate <= 10\n" );
|
||||||
|
Usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !$scale || $scale < -4 || $scale > 4 )
|
||||||
|
{
|
||||||
|
print( STDERR "Scale is out of range, -4 >= scale <= 4\n" );
|
||||||
|
Usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
my ( $detaint_rate ) = $rate =~ /^(-?\d+(?:\.\d+)?)$/;
|
||||||
|
my ( $detaint_scale ) = $scale =~ /^(-?\d+(?:\.\d+)?)$/;
|
||||||
|
|
||||||
|
$rate = $detaint_rate;
|
||||||
|
$scale = $detaint_scale;
|
||||||
|
|
||||||
my $log_file = LOG_FILE;
|
my $log_file = LOG_FILE;
|
||||||
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
|
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
|
||||||
#open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
|
#open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
|
||||||
|
@ -116,7 +146,7 @@ select( LOG ); $| = 1;
|
||||||
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_SERVER, ZM_DB_USERB, ZM_DB_PASSB );
|
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_SERVER, ZM_DB_USERB, ZM_DB_PASSB );
|
||||||
|
|
||||||
my @filters;
|
my @filters;
|
||||||
my $sql = "select max(F.Delta)-min(F.Delta) as FullLength,E.*,M.Name as MonitorName, M.Palette from Frames as F inner join Events as E on F.EventId = E.Id inner join Monitors as M on E.MonitorId = M.Id where EventId = '$event_id' group by F.EventId";
|
my $sql = "select max(F.Delta)-min(F.Delta) as FullLength, E.*, M.Name as MonitorName, M.Width as MonitorWidth, M.Height as MonitorHeight, M.Palette from Frames as F inner join Events as E on F.EventId = E.Id inner join Monitors as M on E.MonitorId = M.Id where EventId = '$event_id' group by F.EventId";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my $event = $sth->fetchrow_hashref();
|
my $event = $sth->fetchrow_hashref();
|
||||||
|
@ -125,7 +155,7 @@ chdir( ZM_PATH_WEB.'/'.ZM_DIR_EVENTS.'/'.$event->{MonitorName}.'/'.$event->{Id}
|
||||||
( my $video_name = $event->{Name} ) =~ s/\s/_/g;
|
( my $video_name = $event->{Name} ) =~ s/\s/_/g;
|
||||||
my $video_file = "$video_name.mpg";
|
my $video_file = "$video_name.mpg";
|
||||||
|
|
||||||
if ( !-s $video_file )
|
if ( $overwrite || !-s $video_file )
|
||||||
{
|
{
|
||||||
print( LOG "Creating video file $video_file for event $event->{Id}\n" );
|
print( LOG "Creating video file $video_file for event $event->{Id}\n" );
|
||||||
|
|
||||||
|
@ -153,13 +183,36 @@ if ( !-s $video_file )
|
||||||
print( PARAMS "REFERENCE_FRAME ORIGINAL\n" );
|
print( PARAMS "REFERENCE_FRAME ORIGINAL\n" );
|
||||||
print( PARAMS "FRAME_RATE 24\n" );
|
print( PARAMS "FRAME_RATE 24\n" );
|
||||||
|
|
||||||
if ( $event->{Palette} == 1 && !ZM_COLOUR_JPEG_FILES )
|
my $scale_conversion = "";
|
||||||
|
if ( $scale != 1 )
|
||||||
{
|
{
|
||||||
print( PARAMS "INPUT_CONVERT ".ZM_PATH_NETPBM."/jpegtopnm * | ".ZM_PATH_NETPBM."/pgmtoppm white | ".ZM_PATH_NETPBM."/ppmtojpeg\n" );
|
if ( $scale > 1 )
|
||||||
|
{
|
||||||
|
$scale_conversion = ZM_PATH_NETPBM."/pnmscale $scale";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$scale_conversion = ZM_PATH_NETPBM."/pnmscale ".(1/$scale);
|
||||||
|
}
|
||||||
|
if ( $event->{Palette} == 1 && !ZM_COLOUR_JPEG_FILES )
|
||||||
|
{
|
||||||
|
print( PARAMS "INPUT_CONVERT ".ZM_PATH_NETPBM."/jpegtopnm * | ".$scale_conversion." | ".ZM_PATH_NETPBM."/pgmtoppm white | ".ZM_PATH_NETPBM."/ppmtojpeg\n" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print( PARAMS "INPUT_CONVERT ".ZM_PATH_NETPBM."/jpegtopnm * | ".$scale_conversion." | ".ZM_PATH_NETPBM."/ppmtojpeg\n" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print( PARAMS "INPUT_CONVERT *\n" );
|
if ( $event->{Palette} == 1 && !ZM_COLOUR_JPEG_FILES )
|
||||||
|
{
|
||||||
|
print( PARAMS "INPUT_CONVERT ".ZM_PATH_NETPBM."/jpegtopnm * | ".ZM_PATH_NETPBM."/pgmtoppm white | ".ZM_PATH_NETPBM."/ppmtojpeg\n" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print( PARAMS "INPUT_CONVERT *\n" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print( PARAMS "INPUT_DIR .\n" );
|
print( PARAMS "INPUT_DIR .\n" );
|
||||||
|
|
||||||
|
@ -172,13 +225,50 @@ if ( !-s $video_file )
|
||||||
close( PARAMS );
|
close( PARAMS );
|
||||||
|
|
||||||
my $command = ZM_PATH_MPEG_ENCODE." $param_file >mpeg.log";
|
my $command = ZM_PATH_MPEG_ENCODE." $param_file >mpeg.log";
|
||||||
|
print( LOG $command."\n" );
|
||||||
my $output = qx($command);
|
my $output = qx($command);
|
||||||
|
print( LOG $output."\n" );
|
||||||
}
|
}
|
||||||
elsif ( ZM_OPT_MPEG eq "ffmpeg" )
|
elsif ( ZM_OPT_MPEG eq "ffmpeg" )
|
||||||
{
|
{
|
||||||
my $frame_rate = sprintf( "%.2f", $event->{Frames}/$event->{FullLength} );
|
my $frame_rate = sprintf( "%.2f", $event->{Frames}/$event->{FullLength} );
|
||||||
my $command = ZM_PATH_FFMPEG." -y ".ZM_FFMPEG_OPTIONS." -r $frame_rate -i capture-%03d.jpg $video_file > mpeg.log";
|
if ( $rate )
|
||||||
|
{
|
||||||
|
if ( $rate != 1 )
|
||||||
|
{
|
||||||
|
if ( $rate > 1 )
|
||||||
|
{
|
||||||
|
$frame_rate *= $rate;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$frame_rate /= $rate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$frame_rate = 25.0;
|
||||||
|
}
|
||||||
|
my $width = $event->{MonitorWidth};
|
||||||
|
my $height = $event->{MonitorHeight};
|
||||||
|
if ( $scale != 1 )
|
||||||
|
{
|
||||||
|
if ( $scale > 1 )
|
||||||
|
{
|
||||||
|
$width = int($width*$scale);
|
||||||
|
$height = int($height*$scale);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$width = int($width/$scale);
|
||||||
|
$height = int($height/$scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my $command = ZM_PATH_FFMPEG." -y ".ZM_FFMPEG_OPTIONS." -r $frame_rate -s ${width}x${height} -i capture-%03d.jpg $video_file > mpeg.log";
|
||||||
|
print( LOG $command."\n" );
|
||||||
my $output = qx($command);
|
my $output = qx($command);
|
||||||
|
print( LOG $output."\n" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,14 @@ $rates = array(
|
||||||
"-4" => "1/4x",
|
"-4" => "1/4x",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$scales = array(
|
||||||
|
"4" => "4x",
|
||||||
|
"2" => "2x",
|
||||||
|
"1" => "Real",
|
||||||
|
"-2" => "1/2x",
|
||||||
|
"-4" => "1/4x",
|
||||||
|
);
|
||||||
|
|
||||||
require_once( 'zm_db.php' );
|
require_once( 'zm_db.php' );
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
|
|
|
@ -307,9 +307,11 @@ function zmaCheck( $monitor )
|
||||||
return( daemonCheck( "zma", "-m $monitor" ) );
|
return( daemonCheck( "zma", "-m $monitor" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
function createVideo( $event )
|
function createVideo( $event, $rate, $scale, $overwrite=0 )
|
||||||
{
|
{
|
||||||
$command = ZM_PATH_BIN."/zmvideo.pl -e $event[Id]";
|
$command = ZM_PATH_BIN."/zmvideo.pl -e $event[Id] -r $rate -s $scale";
|
||||||
|
if ( $overwite )
|
||||||
|
$command .= " -o";
|
||||||
$result = exec( $command, $output, $status );
|
$result = exec( $command, $output, $status );
|
||||||
return( $status?"":rtrim($result) );
|
return( $status?"":rtrim($result) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,12 @@
|
||||||
die( mysql_error() );
|
die( mysql_error() );
|
||||||
$event = mysql_fetch_assoc( $result );
|
$event = mysql_fetch_assoc( $result );
|
||||||
|
|
||||||
ob_start();
|
if ( !isset( $scale ) )
|
||||||
|
$scale = 1;
|
||||||
|
if ( !isset( $rate ) )
|
||||||
|
$rate = 1;
|
||||||
|
|
||||||
// Note this all has a bunch of extra padding as IE won't flush less than 1024 chars
|
ob_start();
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -19,12 +22,28 @@
|
||||||
<link rel="stylesheet" href="zm_styles.css" type="text/css">
|
<link rel="stylesheet" href="zm_styles.css" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<form name="video_form" method="get" action="<?= $PHP_SELF ?>">
|
||||||
|
<input type="hidden" name="view" value="<?= $view ?>">
|
||||||
|
<input type="hidden" name="action" value="<?= $action ?>">
|
||||||
|
<input type="hidden" name="eid" value="<?= $eid ?>">
|
||||||
|
<input type="hidden" name="generate" value="1">
|
||||||
|
<table align="center" border="0" cellspacing="0" cellpadding="2" width="250">
|
||||||
|
<tr><td colspan="2" class="head" align="center">Video Generation Parameters</td></tr>
|
||||||
|
<tr><td colspan="2"> </td></tr>
|
||||||
|
<tr><td class="text" align="right">Frame Rate</td><td><?php buildSelect( "rate", $rates ) ?></td></tr>
|
||||||
|
<tr><td class="text" align="right">Video Size</td><td><?php buildSelect( "scale", $scales ) ?></td></tr>
|
||||||
|
<tr><td class="text" align="right">Overwite Existing</td><td><input type="checkbox" class="form-noborder" name="overwrite" value="1"<?php if ( $overwrite ) { ?> checked<?php } ?>></td></tr>
|
||||||
|
<tr><td colspan="2"> </td></tr>
|
||||||
|
<tr><td colspan="2" align="center"><input type="submit" class="form" value="Generate Video"></td></tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
if ( $generate )
|
||||||
|
{
|
||||||
|
?>
|
||||||
<table border="0" cellspacing="0" cellpadding="4" width="100%">
|
<table border="0" cellspacing="0" cellpadding="4" width="100%">
|
||||||
<tr><td> </td></tr>
|
<tr><td> </td></tr>
|
||||||
<tr><td> </td></tr>
|
<tr><td> </td></tr>
|
||||||
<tr><td> </td></tr>
|
|
||||||
<tr><td> </td></tr>
|
|
||||||
<tr><td> </td></tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center" class="head">Generating Video</td>
|
<td align="center" class="head">Generating Video</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -32,45 +51,48 @@
|
||||||
<tr><td> </td></tr>
|
<tr><td> </td></tr>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
<?php
|
|
||||||
$buffer_string = "<!-- This is some long buffer text to ensure that IE flushes correctly -->";
|
|
||||||
for ( $i = 0; $i < 4096/strlen($buffer_string); $i++ )
|
|
||||||
{
|
|
||||||
echo $buffer_string."\n";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
ob_end_flush();
|
$buffer_string = "<!-- This is some long buffer text to ensure that IE flushes correctly -->";
|
||||||
if ( $video_file = createVideo( $event ) )
|
for ( $i = 0; $i < 4096/strlen($buffer_string); $i++ )
|
||||||
{
|
{
|
||||||
$event_dir = ZM_DIR_EVENTS."/$event[MonitorName]/".sprintf( "%d", $eid );
|
echo $buffer_string."\n";
|
||||||
$video_path = $event_dir.'/'.$video_file;
|
}
|
||||||
//header("Location: $video_path" );
|
?>
|
||||||
|
<?php
|
||||||
|
ob_end_flush();
|
||||||
|
if ( $video_file = createVideo( $event, $rate, $scale, $overwrite ) )
|
||||||
|
{
|
||||||
|
$event_dir = ZM_DIR_EVENTS."/$event[MonitorName]/".sprintf( "%d", $eid );
|
||||||
|
$video_path = $event_dir.'/'.$video_file;
|
||||||
|
//header("Location: $video_path" );
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>ZM - Video - <?= $event[Name] ?></title>
|
|
||||||
<link rel="stylesheet" href="zm_styles.css" type="text/css">
|
|
||||||
<script language="JavaScript">
|
<script language="JavaScript">
|
||||||
location.replace('<?= $video_path ?>');
|
location.replace('<?= $video_path ?>');
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ob_end_flush();
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>ZM - Video - <?= $event[Name] ?></title>
|
|
||||||
<link rel="stylesheet" href="zm_styles.css" type="text/css">
|
<link rel="stylesheet" href="zm_styles.css" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p class="head" align="center"><font color="red"><br><br><br>Video Generation Failed!<br><br><br></font></p>
|
<p class="head" align="center"><font color="red"><br><br>Video Generation Failed!<br><br></font></p>
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
<?php
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ob_end_flush();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue