📄 crop.c
字号:
/***************************************************************************** * crop.c : Crop video plugin for vlc ***************************************************************************** * Copyright (C) 2002, 2003 the VideoLAN team * $Id$ * * Authors: Samuel Hocevar <sam@zoy.org> * mod by Cedric Cocquebert <Cedric.Cocquebert@supelec.fr> * based of DScaler idea (M. Samblanet) * * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_vout.h>#include <vlc_interface.h>#include "filter_common.h"#define BEST_AUTOCROP 1#ifdef BEST_AUTOCROP #define RATIO_MAX 15000 // 10*4/3 for a 360#endif/***************************************************************************** * 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 int Manage ( vout_thread_t * );static void Render ( vout_thread_t *, picture_t * );static void UpdateStats ( vout_thread_t *, picture_t * );static int SendEvents( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );#ifdef BEST_AUTOCROP/***************************************************************************** * Callback prototypes *****************************************************************************/static int FilterCallback ( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );#endif/***************************************************************************** * Module descriptor *****************************************************************************/#define GEOMETRY_TEXT N_("Crop geometry (pixels)")#define GEOMETRY_LONGTEXT N_("Set the geometry of the zone to crop. This is set as <width> x <height> + <left offset> + <top offset>.")#define AUTOCROP_TEXT N_("Automatic cropping")#define AUTOCROP_LONGTEXT N_("Automatically detect black borders and crop them.")#ifdef BEST_AUTOCROP#define RATIOMAX_TEXT N_("Ratio max (x 1000)")#define RATIOMAX_LONGTEXT N_("Maximum image ratio. The crop plugin will never automatically crop to a higher ratio (ie, to a more \"flat\" image). The value is x1000: 1333 means 4/3.")#define RATIO_TEXT N_("Manual ratio")#define RATIO_LONGTEXT N_("Force a ratio (0 for automatic). Value is x1000: 1333 means 4/3.")#define TIME_TEXT N_("Number of images for change")#define TIME_LONGTEXT N_("The number of consecutive images with the same detected ratio (different from the previously detected ratio) to consider that ratio chnged and trigger recrop.")#define DIFF_TEXT N_("Number of lines for change")#define DIFF_LONGTEXT N_("The minimum difference in the number of detected black lines to consider that ratio changed and trigger recrop.")#define NBP_TEXT N_("Number of non black pixels ")#define NBP_LONGTEXT N_("The maximum of non-black pixels in a line to consider"\ " that the line is black.")#define SKIP_TEXT N_("Skip percentage (%)")#define SKIP_LONGTEXT N_("Percentage of the line to consider while checking for black lines. This allows to skip logos in black borders and crop them anyway.")#define LUM_TEXT N_("Luminance threshold ")#define LUM_LONGTEXT N_("Maximum luminance to consider a pixel as black (0-255).")#endifvlc_module_begin(); set_description( N_("Crop video filter") ); set_shortname( N_("Crop" )); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VFILTER ); set_capability( "video filter", 0 ); add_string( "crop-geometry", NULL, NULL, GEOMETRY_TEXT, GEOMETRY_LONGTEXT, false ); add_bool( "autocrop", 0, NULL, AUTOCROP_TEXT, AUTOCROP_LONGTEXT, false );#ifdef BEST_AUTOCROP add_integer_with_range( "autocrop-ratio-max", 2405, 0, RATIO_MAX, NULL, RATIOMAX_TEXT, RATIOMAX_LONGTEXT, true ); add_integer_with_range( "crop-ratio", 0, 0, RATIO_MAX, NULL, RATIO_TEXT, RATIO_LONGTEXT, false ); add_integer( "autocrop-time", 25, NULL, TIME_TEXT, TIME_LONGTEXT, true ); add_integer( "autocrop-diff", 16, NULL, DIFF_TEXT, DIFF_LONGTEXT, true ); add_integer( "autocrop-non-black-pixels", 3, NULL, NBP_TEXT, NBP_LONGTEXT, true ); add_integer_with_range( "autocrop-skip-percent", 17, 0, 100, NULL, SKIP_TEXT, SKIP_LONGTEXT, true ); add_integer_with_range( "autocrop-luminance-threshold", 40, 0, 128, NULL, LUM_TEXT, LUM_LONGTEXT, true );#endif //BEST_AUTOCROP add_shortcut( "crop" ); set_callbacks( Create, Destroy );vlc_module_end();/***************************************************************************** * vout_sys_t: Crop video output method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the Crop specific properties of an output thread. *****************************************************************************/struct vout_sys_t{ vout_thread_t *p_vout; unsigned int i_x, i_y; unsigned int i_width, i_height, i_aspect; bool b_autocrop; /* Autocrop specific variables */ unsigned int i_lastchange; bool b_changed;#ifdef BEST_AUTOCROP unsigned int i_ratio_max; unsigned int i_threshold, i_skipPercent, i_nonBlackPixel, i_diff, i_time; unsigned int i_ratio;#endif};/***************************************************************************** * 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 Crop video thread output method ***************************************************************************** * This function allocates and initializes a Crop vout method. *****************************************************************************/static int Create( vlc_object_t *p_this ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) return VLC_ENOMEM; p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = Manage; p_vout->pf_render = Render; p_vout->pf_display = NULL; p_vout->pf_control = Control; return VLC_SUCCESS;}/***************************************************************************** * Init: initialize Crop video thread output method *****************************************************************************/static int Init( vout_thread_t *p_vout ){ int i_index; char *psz_var; picture_t *p_pic; video_format_t fmt; I_OUTPUTPICTURES = 0; memset( &fmt, 0, sizeof(video_format_t) ); p_vout->p_sys->i_lastchange = 0; p_vout->p_sys->b_changed = false; /* 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; p_vout->fmt_out = p_vout->fmt_in; /* Shall we use autocrop ? */ p_vout->p_sys->b_autocrop = config_GetInt( p_vout, "autocrop" );#ifdef BEST_AUTOCROP p_vout->p_sys->i_ratio_max = config_GetInt( p_vout, "autocrop-ratio-max" ); p_vout->p_sys->i_threshold = config_GetInt( p_vout, "autocrop-luminance-threshold" ); p_vout->p_sys->i_skipPercent = config_GetInt( p_vout, "autocrop-skip-percent" ); p_vout->p_sys->i_nonBlackPixel = config_GetInt( p_vout, "autocrop-non-black-pixels" ); p_vout->p_sys->i_diff = config_GetInt( p_vout, "autocrop-diff" ); p_vout->p_sys->i_time = config_GetInt( p_vout, "autocrop-time" ); vlc_value_t val={0}; var_Get( p_vout, "ratio-crop", &val ); val.psz_string = "0"; var_SetString( p_vout, "ratio-crop", val.psz_string); if (p_vout->p_sys->b_autocrop) p_vout->p_sys->i_ratio = 0; else { p_vout->p_sys->i_ratio = config_GetInt( p_vout, "crop-ratio" ); // ratio < width / height => ratio = 0 (unchange ratio) if (p_vout->p_sys->i_ratio < (p_vout->output.i_width * 1000) / p_vout->output.i_height) p_vout->p_sys->i_ratio = 0; }#endif /* Get geometry value from the user */ psz_var = config_GetPsz( p_vout, "crop-geometry" ); if( psz_var ) { char *psz_parser, *psz_tmp; psz_parser = psz_tmp = psz_var; while( *psz_tmp && *psz_tmp != 'x' ) psz_tmp++; if( *psz_tmp ) { psz_tmp[0] = '\0'; p_vout->p_sys->i_width = atoi( psz_parser ); psz_parser = ++psz_tmp; while( *psz_tmp && *psz_tmp != '+' ) psz_tmp++; if( *psz_tmp ) { psz_tmp[0] = '\0'; p_vout->p_sys->i_height = atoi( psz_parser ); psz_parser = ++psz_tmp; while( *psz_tmp && *psz_tmp != '+' ) psz_tmp++; if( *psz_tmp ) { psz_tmp[0] = '\0'; p_vout->p_sys->i_x = atoi( psz_parser ); p_vout->p_sys->i_y = atoi( ++psz_tmp ); } else { p_vout->p_sys->i_x = atoi( psz_parser ); p_vout->p_sys->i_y = ( p_vout->output.i_height - p_vout->p_sys->i_height ) / 2; } } else { p_vout->p_sys->i_height = atoi( psz_parser ); p_vout->p_sys->i_x = ( p_vout->output.i_width - p_vout->p_sys->i_width ) / 2; p_vout->p_sys->i_y = ( p_vout->output.i_height - p_vout->p_sys->i_height ) / 2; } } else { p_vout->p_sys->i_width = atoi( psz_parser ); p_vout->p_sys->i_height = p_vout->output.i_height; p_vout->p_sys->i_x =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -