Bug 179 - Revamped web video generation.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1510 e3e1d417-86f3-4887-817a-d78f3d33393f
pull/27/merge
stan 2005-10-16 21:33:10 +00:00
parent ce7164a065
commit 01f7523dbe
3 changed files with 78 additions and 35 deletions

View File

@ -92,16 +92,27 @@ $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
my $event_id;
my $format = 'mpg';
my $rate = 1.0;
my $scale = 1.0;
my $overwrite = 0;
my @formats = split( '/\s+/', ZM_FFMPEG_FORMATS );
for ( my $i = 0; $i < @formats; $i++ )
{
if ( $i =~ /^(.+)\*$/ )
{
$format = $formats[$i] = $1;
}
}
sub Usage
{
print( "
Usage: zmvideo.pl -e <event_id>,--event=<event_id> [-r <rate>,--rate=<rate>] [-s <scale>,--scale=<scale>] [-o,--overwrite]
Usage: zmvideo.pl -e <event_id>,--event=<event_id> [--format <format>] [--rate=<rate>] [--scale=<scale>] [--overwrite]
Parameters are :-
-e<event_id>, --event=<event_id> - What event to create the video for
-f<format>, --format=<format> - What format to create the video in, default is mpg. For ffmpeg only.
-r<rate>, --rate=<rate> - Relative rate to use, 1 = realtime, 2 = double speed , 0.5 = half speed etc
-s<scale>, --scale=<scale> - Scale to use, 1 = normal, 2 = double size, 0.5 = half size etc
-o, --overwrite - Whether to overwrite an existing file, off by default.
@ -109,7 +120,7 @@ Parameters are :-
exit( -1 );
}
if ( !GetOptions( 'event=i'=>\$event_id, 'rate=f'=>\$rate, 'scale=f'=>\$scale, 'overwrite'=>\$overwrite ) )
if ( !GetOptions( 'event=i'=>\$event_id, 'format=s'=>\$format, 'rate=f'=>\$rate, 'scale=f'=>\$scale, 'overwrite'=>\$overwrite ) )
{
Usage();
}
@ -132,6 +143,12 @@ if ( ZM_OPT_MPEG eq "mpeg_encode" && $rate != 1.0 )
exit(-1);
}
if ( $format ne 'mpg' && ZM_OPT_MPEG eq "mpeg_encode" )
{
print( STDERR "Format not supported for mpeg_encode\n" );
Usage();
}
if ( $rate < 0.25 || $rate > 100 )
{
print( STDERR "Rate is out of range, 0.25 >= rate <= 100\n" );
@ -144,9 +161,11 @@ if ( !$scale || $scale < 0.25 || $scale > 4 )
Usage();
}
my ( $detaint_format ) = $format =~ /^(\w+)$/;
my ( $detaint_rate ) = $rate =~ /^(-?\d+(?:\.\d+)?)$/;
my ( $detaint_scale ) = $scale =~ /^(-?\d+(?:\.\d+)?)$/;
$format = $detaint_format;
$rate = $detaint_rate;
$scale = $detaint_scale;
@ -171,12 +190,12 @@ chdir( ZM_PATH_WEB.'/'.ZM_DIR_EVENTS.'/'.$event->{MonitorId}.'/'.$event->{Id} );
my $file_rate = $rate;
$file_rate =~ s/\./_/;
$file_rate =~ s/_00//;
$file_rate =~ s/0$//;
$file_rate =~ s/(_\d+)0+$/$1/;
my $file_scale = $scale;
$file_scale =~ s/\./_/;
$file_scale =~ s/_00//;
$file_scale =~ s/0$//;
my $video_file = "$video_name-$file_rate-$file_scale.mpg";
$file_scale =~ s/(_\d+)0+$/$1/;
my $video_file = "$video_name-$file_rate-$file_scale.$format";
if ( $overwrite || !-s $video_file )
{
@ -247,7 +266,7 @@ if ( $overwrite || !-s $video_file )
print( PARAMS "END_INPUT\n" );
close( PARAMS );
my $command = ZM_PATH_MPEG_ENCODE." $param_file >mpeg.log";
my $command = ZM_PATH_MPEG_ENCODE." $param_file >mpeg_encode.log";
print( LOG $command."\n" );
my $output = qx($command);
print( LOG $output."\n" );
@ -266,7 +285,7 @@ if ( $overwrite || !-s $video_file )
$width = int($width*$scale);
$height = int($height*$scale);
}
my $command = ZM_PATH_FFMPEG." -y -r $frame_rate -s ${width}x${height} ".ZM_FFMPEG_INPUT_OPTIONS." -i %0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg ".ZM_FFMPEG_OUTPUT_OPTIONS." $video_file > mpeg.log";
my $command = ZM_PATH_FFMPEG." -y -r $frame_rate ".ZM_FFMPEG_INPUT_OPTIONS." -i %0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg -s ${width}x${height} ".ZM_FFMPEG_OUTPUT_OPTIONS." $video_file > ffmpeg.log";
print( LOG $command."\n" );
my $output = qx($command);
print( LOG $output."\n" );

View File

@ -702,9 +702,9 @@ function createListThumbnail( $event, $overwrite=false )
return( $thumb_data );
}
function createVideo( $event, $rate, $scale, $overwrite=false )
function createVideo( $event, $format, $rate, $scale, $overwrite=false )
{
$command = ZM_PATH_BIN."/zmvideo.pl -e ".$event['Id']." -r ".sprintf( "%.2f", ($rate/RATE_SCALE) )." -s ".sprintf( "%.2f", ($scale/SCALE_SCALE) );
$command = ZM_PATH_BIN."/zmvideo.pl -e ".$event['Id']." -f ".$format." -r ".sprintf( "%.2f", ($rate/RATE_SCALE) )." -s ".sprintf( "%.2f", ($scale/SCALE_SCALE) );
if ( $overwrite )
$command .= " -o";
$result = exec( $command, $output, $status );

View File

@ -45,6 +45,48 @@ if ( !isset( $scale ) )
$event_dir = ZM_DIR_EVENTS."/".$event['MonitorId']."/".sprintf( "%d", $eid );
$video_formats = array();
$ffmpeg_formats = preg_split( '/\s+/', ZM_FFMPEG_FORMATS );
foreach ( $ffmpeg_formats as $ffmpeg_format )
{
if ( preg_match( '/^(.+)\*$/', $ffmpeg_format, $matches ) )
{
$video_formats[$matches[1]] = $matches[1];
if ( !isset($video_format) )
{
$video_format = $matches[1];
}
}
else
{
$video_formats[$ffmpeg_format] = $ffmpeg_format;
}
}
$video_files = array();
if ( $dir = opendir( $event_dir ) )
{
while ( ($file = readdir( $dir )) !== false )
{
$file = $event_dir.'/'.$file;
if ( is_file( $file ) )
{
if ( preg_match( '/\.(?:'.join( '|', $video_formats ).')$/', $file ) )
{
$video_files[] = $file;
}
}
}
closedir( $dir );
}
if ( isset($download) )
{
header( "Content-disposition: attachment; filename=".$video_files[$download]."; size=".filesize($video_files[$download]) );
readfile( $video_files[$download] );
exit;
}
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
@ -79,7 +121,7 @@ if ( !empty($generate) )
</table>
<?php
$buffer_string = "<!-- This is some long buffer text to ensure that IE flushes correctly -->";
for ( $i = 0; $i < 4096/strlen($buffer_string); $i++ )
for ( $i = 0; $i < 8192/strlen($buffer_string); $i++ )
{
echo $buffer_string."\n";
}
@ -87,10 +129,9 @@ if ( !empty($generate) )
</body>
</html>
<?php
ob_flush();
ob_start();
ob_end_flush();
if ( $video_file = createVideo( $event, $rate, $scale, $overwrite ) )
if ( $video_file = createVideo( $event, $video_format, $rate, $scale, $overwrite ) )
{
$video_path = $event_dir.'/'.$video_file;
}
@ -98,7 +139,7 @@ if ( !empty($generate) )
<html>
<head>
<script type="text/javascript">
location.replace('<?= $PHP_FILE ?>?view=<?= $view ?>&eid=<?= $eid ?>&generated=<?= $video_file?1:0 ?>');
location.replace('<?= $PHP_FILE ?>?view=<?= $view ?>&eid=<?= $eid ?>&video_format=<?= $video_format ?>&rate=<?= $rate ?>&scale=<?= $scale ?>&generated=<?= $video_file?1:0 ?>');
</script>
</head>
<body>
@ -115,11 +156,12 @@ else
<tr><td width="50">&nbsp;</td><td class="head" align="center"><?= $zmSlangVideoGenParms ?></td><td width="50" class="text" align="right"><a href="javascript: closeWindow();"><?= $zmSlangClose ?></a></td></tr>
</table>
<table align="center" border="0" cellspacing="0" cellpadding="2" width="96%">
<tr><td width="50%">&nbsp;</td><td width="50%">&nbsp;</td></tr>
<tr><td width="50%"><img src="graphics/spacer.gif" width="1" height="5"></td><td width="50%"><img src="graphics/spacer.gif" width="1" height="5"></td></tr>
<tr><td class="text" align="right"><?= $zmSlangVideoFormat ?></td><td><?= buildSelect( "video_format", $video_formats ) ?></td></tr>
<tr><td class="text" align="right"><?= $zmSlangFrameRate ?></td><td><?= buildSelect( "rate", $rates ) ?></td></tr>
<tr><td class="text" align="right"><?= $zmSlangVideoSize ?></td><td><?= buildSelect( "scale", $scales ) ?></td></tr>
<tr><td class="text" align="right"><?= $zmSlangOverwriteExisting ?></td><td><input type="checkbox" class="form-noborder" name="overwrite" value="1"<?php if ( isset($overwrite) ) { ?> checked<?php } ?>></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2"><img src="graphics/spacer.gif" width="1" height="5"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" class="form" value="<?= $zmSlangGenerateVideo ?>"></td></tr>
</table>
</form>
@ -149,24 +191,6 @@ else
<tr><td>
<table align="center" border="0" cellspacing="0" cellpadding="3">
<?php
$video_files = array();
$video_types = array( "mpg", "mpeg", "asf", "mov", "3gp" );
if ( $dir = opendir( $event_dir ) )
{
while ( ($file = readdir( $dir )) !== false )
{
$file = $event_dir.'/'.$file;
if ( is_file( $file ) )
{
if ( preg_match( '/\.(?:'.join( '|', $video_types ).')$/', $file ) )
{
$video_files[] = $file;
}
}
}
closedir( $dir );
}
if ( count($video_files) )
{
?>
@ -197,7 +221,7 @@ else
<td class="text" align="center"><?= filesize( $file ) ?></td>
<td class="text" align="center"><?= $rate_text ?></td>
<td class="text" align="center"><?= $scale_text ?></td>
<td class="text" align="center"><a href="javascript:viewVideo( '<?= $file ?>', 'zmVideo<?= $eid ?>-<?= $scale ?>', 12+<?= reScale( $event['Width'], $scale ) ?>, 20+<?= reScale( $event['Height'], $scale ) ?> );"><?= $zmSlangView ?></a>&nbsp;/&nbsp;<a href="<?= $file ?>" target="_blank"><?= $zmSlangDownload ?></a>&nbsp;/&nbsp;<a href="javascript: deleteVideo( <?= $index ?> )"><?= $zmSlangDelete ?></a></td>
<td class="text" align="center"><a href="javascript:viewVideo( '<?= $file ?>', 'zmVideo<?= $eid ?>-<?= $scale ?>', 12+<?= reScale( $event['Width'], $scale ) ?>, 20+<?= reScale( $event['Height'], $scale ) ?> );"><?= $zmSlangView ?></a>&nbsp;/&nbsp;<a href="<?= $file ?>" onClick="window.location='<?= $PHP_SELF ?>?view=<?= $view ?>&eid=<?= $eid ?>&download=<?= $index ?>'" target="_blank"><?= $zmSlangDownload ?></a>&nbsp;/&nbsp;<a href="javascript: deleteVideo( <?= $index ?> )"><?= $zmSlangDelete ?></a></td>
</tr>
<?php
$index++;