Upload FTP video

Anything you want added or changed in future versions of ZoneMinder? Post here and there's a chance it will get in! Search to make sure it hasn't already been requested.
Post Reply
lookathome
Posts: 18
Joined: Wed May 05, 2010 2:10 pm

Upload FTP video

Post by lookathome »

Is it possible to implement in zmfilter.pl a procedure that upload the ftp video generated by encoding mmpeg?
Now only zip format is possible.

Bye
Lookathome
Can this work ?

Code: Select all

sub generateVideo
{
    my $filter = shift;
    my $event = shift;
    my $phone = shift;

    my $rate = $event->{DefaultRate}/100;
    my $scale = $event->{DefaultScale}/100;
    my $format;

    my @ffmpeg_formats = split( /\s+/, ZM_FFMPEG_FORMATS );
    my $default_video_format;
    my $default_phone_format;
    foreach my $ffmpeg_format( @ffmpeg_formats )
    {
        if ( $ffmpeg_format =~ /^(.+)\*\*$/ )
        {
            $default_phone_format = $1;
        }
        elsif ( $ffmpeg_format =~ /^(.+)\*$/ )
        {
            $default_video_format = $1;
        }
    }

    if ( $phone && $default_phone_format )
    {
        $format = $default_phone_format;
    }
    elsif ( $default_video_format )
    {
        $format = $default_video_format;
    }
    else
    {
        $format = $ffmpeg_formats[0];
    }

    my $command = ZM_PATH_BIN."/zmvideo.pl -e ".$event->{Id}." -r ".$rate." -s ".$scale." -f ".$format;
    my $output = qx($command);
        chomp( $output );
        
        #modified my Molok uploading the video
            my $filter = shift;
    my $event = shift;

    if ( !ZM_UPLOAD_FTP_HOST )
    {
        Error( "Cannot upload archive as no FTP host defined" );
        return( 0 );
    }
my $arch_file = $output;
Info( "Uploading to ".ZM_UPLOAD_FTP_HOST."\n" );
        my $ftp = Net::FTP->new( ZM_UPLOAD_FTP_HOST, Timeout=>ZM_UPLOAD_FTP_TIMEOUT, Passive=>ZM_UPLOAD_FTP_PASSIVE, Debug=>ZM_UPLOAD_FTP_DEBUG );
        if ( !$ftp )
        {
            warn( "Can't create ftp connection: $@" );
            return( 0 );
        }
        $ftp->login( ZM_UPLOAD_FTP_USER, ZM_UPLOAD_FTP_PASS ) or warn( "FTP - Can't login" );
        $ftp->binary() or warn( "FTP - Can't go binary" );
        $ftp->cwd( ZM_UPLOAD_FTP_REM_DIR ) or warn( "FTP - Can't cwd" );
        $ftp->put( $arch_file ) or warn( "FTP - Can't upload '$arch_file'" );
        $ftp->quit() or warn( "FTP - Can't quit" );
        unlink( $arch_file );
        my $status = $? >> 8;
    if ( $status || DBG_LEVEL > 0 )
    {
        Debug( "Output: $output\n" );
    }
    if ( $status )
    {
        Error( "Video generation '$command' failed with status: $status\n" );
        if ( wantarray() )
        {
            return( undef, undef );
        }
        return( 0 );
    }
    else
    {
        my $sql = "update Events set Videoed = 1 where Id = ?";
        my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
        my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() );
        if ( wantarray() )
        {
            return( $format, sprintf( "%s/%s", getEventPath( $event ), $output ) ); 
        }
    }
    return( 1 );
}
lookathome
Posts: 18
Joined: Wed May 05, 2010 2:10 pm

Post by lookathome »

it does not work.
Nothing happen when i use this filter.

i hope some one can help.

The problem is :
with this procedure you have just to use ffmpeg to make the avi files and then use the ftp uploading procedure.
Post Reply