⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motiondetect.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * motiondetect.c : Motion detect video effect plugin for vlc ***************************************************************************** * Copyright (C) 2005 VideoLAN * $Id: $ * * Authors: J閞鬽e Decoodt <djc@videolan.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>                                      /* malloc(), free() */#include <string.h>#include <vlc/vlc.h>#include <vlc/vout.h>#include <vlc/intf.h>#include "filter_common.h"/***************************************************************************** * Local prototypes *****************************************************************************/static int  Create    ( vlc_object_t * );static void Destroy   ( vlc_object_t * );static int  Init      ( vout_thread_t * );static void End       ( vout_thread_t * );static void Render    ( vout_thread_t *, picture_t * );static void MotionDetect( vout_thread_t *p_vout, picture_t *p_inpic,                                                 picture_t *p_outpic );static int  SendEvents   ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );/***************************************************************************** * Module descriptor *****************************************************************************/#define DESC_TEXT N_("Description file")#define DESC_LONGTEXT N_("Description file, file containing simple playlist")#define HISTORY_TEXT N_("History parameter")#define HISTORY_LONGTEXT N_("History parameter, number of frames used for detection")vlc_module_begin();    set_description( _("Motion detect video filter") );    set_shortname( N_( "Motion detect" ));/*  Leave this commented as long as the VLM intf in wx isn't available    set_category( CAT_VIDEO );    set_subcategory( SUBCAT_VIDEO_VFILTER );*/    set_capability( "video filter", 0 );    add_integer( "motiondetect-history", 1, NULL, HISTORY_TEXT,                                HISTORY_LONGTEXT, VLC_FALSE );    add_string( "motiondetect-description", "motiondetect", NULL, DESC_TEXT,                                DESC_LONGTEXT, VLC_FALSE );    set_callbacks( Create, Destroy );vlc_module_end();/***************************************************************************** * vout_sys_t: Motion detect video output method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the Motion detect specific properties of an output thread. *****************************************************************************/typedef struct area_t{    int i_x1, i_y1;    int i_x2, i_y2;    int i_matches;    int i_level;    int i_downspeed, i_upspeed;    char *psz_mrl;} area_t;struct vout_sys_t{    vout_thread_t *p_vout;    playlist_t *p_playlist;    uint8_t *p_bufferY;    int i_stack;    area_t** pp_areas;    int i_areas;    int i_history;};/***************************************************************************** * Control: control facility for the vout (forwards to child vout) *****************************************************************************/static int Control( vout_thread_t *p_vout, int i_query, va_list args ){    return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );}/***************************************************************************** * Create: allocates Distort video thread output method ***************************************************************************** * This function allocates and initializes a Distort vout method. *****************************************************************************/static int Create( vlc_object_t *p_this ){    vout_thread_t *p_vout = (vout_thread_t *)p_this;    char *psz_descfilename;    char buffer[256];    int x1, x2, y1, y2, i_level, i_downspeed, i_upspeed, i;    area_t *p_area;    FILE * p_file;    /* Allocate structure */    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );    if( p_vout->p_sys == NULL )    {        msg_Err( p_vout, "out of memory" );        return VLC_ENOMEM;    }    p_vout->pf_init = Init;    p_vout->pf_end = End;    p_vout->pf_manage = NULL;    p_vout->pf_render = Render;    p_vout->pf_display = NULL;    p_vout->pf_control = Control;    memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );    p_vout->p_sys->i_history = config_GetInt( p_vout,                                              "motiondetect-history" );    if( !(psz_descfilename = config_GetPsz( p_vout,                                            "motiondetect-description" ) ) )    {        free( p_vout->p_sys );        return VLC_EGENERIC;    }    p_vout->p_sys->p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,                                                 FIND_ANYWHERE );    if( !p_vout->p_sys->p_playlist )    {         msg_Err( p_vout, "playlist not found" );         free( p_vout->p_sys );         return VLC_EGENERIC;    }    /* Parse description file and allocate areas */    p_file = fopen( psz_descfilename, "r" );    if( !p_file )    {        msg_Err( p_this, "Failed to open descritpion file %s",                            psz_descfilename );        free( psz_descfilename );        free( p_vout->p_sys );        return VLC_EGENERIC;    }    p_vout->p_sys->i_areas = 0;    while( fscanf( p_file, "%d,%d,%d,%d,%d,%d,%d,",                            &x1, &y1, &x2, &y2, &i_level,                            &i_downspeed, &i_upspeed ) == 7 )    {        for( i = 0 ; i < 255 ; i++ )        {            fread( buffer + i, 1, 1, p_file );            if( *( buffer + i ) == '\n' )                break;        }        *( buffer + i )  = 0;        p_vout->p_sys->i_areas++;        p_vout->p_sys->pp_areas = realloc( p_vout->p_sys->pp_areas,                                        p_vout->p_sys->i_areas *                                                     sizeof( area_t ) );        if( !p_vout->p_sys->pp_areas )            /*FIXME: clean this... */            return VLC_ENOMEM;        p_area = malloc( sizeof( area_t ) );        if( !p_area )            break;        p_area->i_x1 = x1;        p_area->i_x2 = x2;        p_area->i_y1 = y1;        p_area->i_y2 = y2;        p_area->i_matches = 0;        p_area->i_level = i_level;        p_area->i_downspeed = i_downspeed;        p_area->i_upspeed = i_upspeed;        p_area->psz_mrl = strdup(buffer);        p_vout->p_sys->pp_areas[p_vout->p_sys->i_areas-1] = p_area;    }    fclose( p_file );    return VLC_SUCCESS;}/***************************************************************************** * Init: initialize Motion detect video thread output method *****************************************************************************/static int Init( vout_thread_t *p_vout ){    int i_index;    picture_t *p_pic;    video_format_t fmt = {0};    I_OUTPUTPICTURES = 0;    /* Initialize the output structure */    p_vout->output.i_chroma = p_vout->render.i_chroma;    p_vout->output.i_width  = p_vout->render.i_width;    p_vout->output.i_height = p_vout->render.i_height;    p_vout->output.i_aspect = p_vout->render.i_aspect;    fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;    fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -