X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_output%2Fimage.c;h=3bcecbcbe8272bda2b86b1af99548373b5f878e5;hb=de587c237065de4696d9d035d0504cdf34990d87;hp=7ba4e915a0e2678a14330946859cba6f3b6bb4cf;hpb=2bdea742c7875ecf7d8f3a28998bc00e6417a56b;p=vlc diff --git a/modules/video_output/image.c b/modules/video_output/image.c index 7ba4e915a0..3bcecbcbe8 100644 --- a/modules/video_output/image.c +++ b/modules/video_output/image.c @@ -4,7 +4,7 @@ * Copyright (C) 2004-2006 the VideoLAN team * $Id$ * - * Authors: Clément Stenac + * Authors: Clément Stenac * * 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 @@ -18,19 +18,24 @@ * * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include #include "vlc_image.h" +#include "vlc_strings.h" /***************************************************************************** * Local prototypes @@ -46,38 +51,66 @@ static void Display ( vout_thread_t *, picture_t * ); * Module descriptor *****************************************************************************/ #define FORMAT_TEXT N_( "Image format" ) -#define FORMAT_LONGTEXT N_( "Set the format of the output image." ) +#define FORMAT_LONGTEXT N_( "Format of the output images (png or jpg)." ) + +#define WIDTH_TEXT N_( "Image width" ) +#define WIDTH_LONGTEXT N_( "You can enforce the image width. By default " \ + "(-1) VLC will adapt to the video " \ + "characteristics.") + +#define HEIGHT_TEXT N_( "Image height" ) +#define HEIGHT_LONGTEXT N_( "You can enforce the image height. By default " \ + "(-1) VLC will adapt to the video " \ + "characteristics.") #define RATIO_TEXT N_( "Recording ratio" ) -#define RATIO_LONGTEXT N_( "Set the ratio of images that are recorded. "\ +#define RATIO_LONGTEXT N_( "Ratio of images to record. "\ "3 means that one image out of three is recorded." ) #define PREFIX_TEXT N_( "Filename prefix" ) -#define PREFIX_LONGTEXT N_( "Set the prefix of the filename. Output filename "\ - "will have the form prefixNUMBER.format" ) +#define PREFIX_LONGTEXT N_( "Prefix of the output images filenames. Output " \ + "filenames will have the \"prefixNUMBER.format\" "\ + "form." ) + +#define REPLACE_TEXT N_( "Always write to the same file" ) +#define REPLACE_LONGTEXT N_( "Always write to the same file instead of " \ + "creating one file per image. In this case, " \ + "the number is not appended to the filename." ) -static char *psz_format_list[] = { "png", "jpeg" }; -static char *psz_format_list_text[] = { "PNG", "JPEG" }; +static const char *const psz_format_list[] = { "png", "jpeg" }; +static const char *const psz_format_list_text[] = { "PNG", "JPEG" }; + +#define CFG_PREFIX "image-out-" vlc_module_begin( ); - set_shortname( _( "Image file" ) ); - set_description( _( "Image video output" ) ); + set_shortname( N_( "Image file" ) ); + set_description( N_( "Image video output" ) ); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VOUT ); set_capability( "video output", 0 ); - add_string( "image-out-format", "png", NULL, FORMAT_TEXT, FORMAT_LONGTEXT, - VLC_FALSE ); - add_string( "image-out-format", "jpeg", NULL, FORMAT_TEXT, FORMAT_LONGTEXT, - VLC_FALSE ); - change_string_list( psz_format_list, psz_format_list_text, 0 ); - add_integer( "image-out-ratio", 3 , NULL, RATIO_TEXT, RATIO_LONGTEXT, - VLC_FALSE ); - add_string( "image-out-prefix", "img", NULL, PREFIX_TEXT, PREFIX_LONGTEXT, - VLC_FALSE ); + add_string( CFG_PREFIX "format", "png", NULL, + FORMAT_TEXT, FORMAT_LONGTEXT, false ); + change_string_list( psz_format_list, psz_format_list_text, 0 ); + add_integer( CFG_PREFIX "width", 0, NULL, + WIDTH_TEXT, WIDTH_LONGTEXT, true ); + add_deprecated_alias( "image-width" ); /* since 0.9.0 */ + add_integer( CFG_PREFIX "height", 0, NULL, + HEIGHT_TEXT, HEIGHT_LONGTEXT, true ); + add_deprecated_alias( "image-height" ); /* since 0.9.0 */ + add_integer( CFG_PREFIX "ratio", 3, NULL, + RATIO_TEXT, RATIO_LONGTEXT, false ); + add_string( CFG_PREFIX "prefix", "img", NULL, + PREFIX_TEXT, PREFIX_LONGTEXT, false ); + add_bool( CFG_PREFIX "replace", 0, NULL, + REPLACE_TEXT, REPLACE_LONGTEXT, false ); set_callbacks( Create, Destroy ); vlc_module_end(); +static const char *const ppsz_vout_options[] = { + "format", "width", "height", "ratio", "prefix", "replace", NULL +}; + /***************************************************************************** * vout_sys_t: video output descriptor *****************************************************************************/ @@ -87,14 +120,20 @@ struct vout_sys_t char *psz_format; /* Format */ int i_ratio; /* Image ratio */ + unsigned int i_width; /* Image width */ + unsigned int i_height; /* Image height */ + int i_current; /* Current image */ int i_frames; /* Number of frames */ + bool b_replace; + + bool b_time; + bool b_meta; + image_handler_t *p_image; }; -#define FREE( p ) if( p ) { free( p ); p = NULL; } - /***************************************************************************** * Create: allocates video thread ***************************************************************************** @@ -109,20 +148,34 @@ static int Create( vlc_object_t *p_this ) if( ! p_vout->p_sys ) return VLC_ENOMEM; + config_ChainParse( p_vout, CFG_PREFIX, ppsz_vout_options, + p_vout->p_cfg ); + p_vout->p_sys->psz_prefix = - var_CreateGetString( p_this, "image-out-prefix" ); + var_CreateGetString( p_this, CFG_PREFIX "prefix" ); + p_vout->p_sys->b_time = strchr( p_vout->p_sys->psz_prefix, '%' ) + ? true : false; + p_vout->p_sys->b_meta = strchr( p_vout->p_sys->psz_prefix, '$' ) + ? true : false; p_vout->p_sys->psz_format = - var_CreateGetString( p_this, "image-out-format" ); + var_CreateGetString( p_this, CFG_PREFIX "format" ); + p_vout->p_sys->i_width = + var_CreateGetInteger( p_this, CFG_PREFIX "width" ); + p_vout->p_sys->i_height = + var_CreateGetInteger( p_this, CFG_PREFIX "height" ); p_vout->p_sys->i_ratio = - var_CreateGetInteger( p_this, "image-out-ratio" ); + var_CreateGetInteger( p_this, CFG_PREFIX "ratio" ); + p_vout->p_sys->b_replace = + var_CreateGetBool( p_this, CFG_PREFIX "replace" ); p_vout->p_sys->i_current = 0; p_vout->p_sys->p_image = image_HandlerCreate( p_vout ); if( !p_vout->p_sys->p_image ) { msg_Err( p_this, "unable to create image handler") ; - FREE( p_vout->p_sys->psz_prefix ); - FREE( p_vout->p_sys ); + FREENULL( p_vout->p_sys->psz_prefix ); + FREENULL( p_vout->p_sys->psz_format ); + FREENULL( p_vout->p_sys ); return VLC_EGENERIC; } @@ -208,9 +261,9 @@ static void Destroy( vlc_object_t *p_this ) /* Destroy structure */ image_HandlerDelete( p_vout->p_sys->p_image ); - FREE( p_vout->p_sys->psz_prefix ); - FREE( p_vout->p_sys->psz_format ); - FREE( p_vout->p_sys ); + FREENULL( p_vout->p_sys->psz_prefix ); + FREENULL( p_vout->p_sys->psz_format ); + FREENULL( p_vout->p_sys ); } /***************************************************************************** @@ -220,9 +273,14 @@ static void Destroy( vlc_object_t *p_this ) *****************************************************************************/ static void Display( vout_thread_t *p_vout, picture_t *p_pic ) { - video_format_t fmt_in = {0}, fmt_out = {0}; + video_format_t fmt_in, fmt_out; char *psz_filename; + char *psz_prefix; + char *psz_tmp; + + memset( &fmt_in, 0, sizeof( fmt_in ) ); + memset( &fmt_out, 0, sizeof( fmt_out ) ); if( p_vout->p_sys->i_frames % p_vout->p_sys->i_ratio != 0 ) { @@ -230,16 +288,50 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic ) return; } p_vout->p_sys->i_frames++; - psz_filename = (char *)malloc( 10 + strlen( p_vout->p_sys->psz_prefix ) - + strlen( p_vout->p_sys->psz_format ) ); fmt_in.i_chroma = p_vout->render.i_chroma; - fmt_out.i_width = fmt_in.i_width = p_vout->render.i_width; - fmt_out.i_height = fmt_in.i_height = p_vout->render.i_height; + fmt_in.i_width = p_vout->render.i_width; + fmt_in.i_height = p_vout->render.i_height; + + fmt_out.i_width = (p_vout->p_sys->i_width > 0) ? p_vout->p_sys->i_width : + p_vout->render.i_width; + fmt_out.i_height = (p_vout->p_sys->i_height > 0) ? p_vout->p_sys->i_height : + p_vout->render.i_height; - sprintf( psz_filename, "%s%.6i.%s", p_vout->p_sys->psz_prefix, - p_vout->p_sys->i_current, + if( p_vout->p_sys->b_time ) + { + psz_tmp = str_format_time( p_vout->p_sys->psz_prefix ); + path_sanitize( psz_tmp ); + } + else + psz_tmp = p_vout->p_sys->psz_prefix; + if( p_vout->p_sys->b_meta ) + { + psz_prefix = str_format_meta( p_vout, psz_tmp ); + path_sanitize( psz_prefix ); + if( p_vout->p_sys->b_time ) + free( psz_tmp ); + } + else + psz_prefix = psz_tmp; + psz_filename = (char *)malloc( 10 + strlen( psz_prefix ) + + strlen( p_vout->p_sys->psz_format ) ); + if( !psz_filename ) + return; + + if( p_vout->p_sys->b_replace ) + { + sprintf( psz_filename, "%s.%s", psz_prefix, p_vout->p_sys->psz_format ); + } + else + { + sprintf( psz_filename, "%s%.6i.%s", psz_prefix, + p_vout->p_sys->i_current, + p_vout->p_sys->psz_format ); + } + if( p_vout->p_sys->b_time || p_vout->p_sys->b_meta ) + free( psz_prefix ); image_WriteUrl( p_vout->p_sys->p_image, p_pic, &fmt_in, &fmt_out, psz_filename ) ; free( psz_filename ); @@ -252,4 +344,5 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic ) static void End( vout_thread_t *p_vout ) { + VLC_UNUSED(p_vout); }