From 01f7523dbe4dc9abc1674ed9cb5ac6b6dfcc247b Mon Sep 17 00:00:00 2001 From: stan Date: Sun, 16 Oct 2005 21:33:10 +0000 Subject: [PATCH] Bug 179 - Revamped web video generation. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1510 e3e1d417-86f3-4887-817a-d78f3d33393f --- scripts/zmvideo.pl.z | 33 +++++++++++++---- web/zm_funcs.php | 4 +- web/zm_html_view_video.php | 76 +++++++++++++++++++++++++------------- 3 files changed, 78 insertions(+), 35 deletions(-) diff --git a/scripts/zmvideo.pl.z b/scripts/zmvideo.pl.z index c6f4589b5..329aa166a 100644 --- a/scripts/zmvideo.pl.z +++ b/scripts/zmvideo.pl.z @@ -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= [-r ,--rate=] [-s ,--scale=] [-o,--overwrite] +Usage: zmvideo.pl -e ,--event= [--format ] [--rate=] [--scale=] [--overwrite] Parameters are :- -e, --event= - What event to create the video for +-f, --format= - What format to create the video in, default is mpg. For ffmpeg only. -r, --rate= - Relative rate to use, 1 = realtime, 2 = double speed , 0.5 = half speed etc -s, --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" ); diff --git a/web/zm_funcs.php b/web/zm_funcs.php index 68607b2e6..17579f2a1 100644 --- a/web/zm_funcs.php +++ b/web/zm_funcs.php @@ -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 ); diff --git a/web/zm_html_view_video.php b/web/zm_html_view_video.php index a2da65469..9ac2b8905 100644 --- a/web/zm_html_view_video.php +++ b/web/zm_html_view_video.php @@ -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(); ?> @@ -79,7 +121,7 @@ if ( !empty($generate) ) "; - 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) ) @@ -115,11 +156,12 @@ else   - + + - +
  
checked>
 
@@ -149,24 +191,6 @@ else @@ -197,7 +221,7 @@ else - +
 /  /  /  /