X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fscene.c;h=532aae647e28e937422ca30a927362216f338ff3;hb=b2262bc3649b61d93df0d756017dafb9d2ad5822;hp=03656b5719f8cef7876c5a806fb9fc796ec9e249;hpb=05492281965ed211badf7e1f4c2220be720d3356;p=vlc diff --git a/modules/video_filter/scene.c b/modules/video_filter/scene.c index 03656b5719..532aae647e 100644 --- a/modules/video_filter/scene.c +++ b/modules/video_filter/scene.c @@ -32,13 +32,12 @@ #include #include -#include #include -#include "vlc_filter.h" +#include #include "filter_picture.h" -#include "vlc_image.h" -#include "vlc_strings.h" +#include +#include /***************************************************************************** * Local prototypes @@ -55,7 +54,7 @@ static void SavePicture( filter_t *, picture_t * ); * Module descriptor *****************************************************************************/ #define FORMAT_TEXT N_( "Image format" ) -#define FORMAT_LONGTEXT N_( "Format of the output images (png or jpg)." ) +#define FORMAT_LONGTEXT N_( "Format of the output images (png, jpeg, ...)." ) #define WIDTH_TEXT N_( "Image width" ) #define WIDTH_LONGTEXT N_( "You can enforce the image width. By default " \ @@ -86,36 +85,34 @@ static void SavePicture( filter_t *, picture_t * ); "creating one file per image. In this case, " \ "the number is not appended to the filename." ) -static const char *const psz_format_list[] = { "png", "jpeg" }; -static const char *const psz_format_list_text[] = { "PNG", "JPEG" }; - +#define SCENE_HELP N_("Send your video to picture files") #define CFG_PREFIX "scene-" vlc_module_begin () set_shortname( N_( "Scene filter" ) ) set_description( N_( "Scene video filter" ) ) + set_help(SCENE_HELP) set_category( CAT_VIDEO ) set_subcategory( SUBCAT_VIDEO_VOUT ) set_capability( "video filter2", 0 ) /* General options */ 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", 288, NULL, - WIDTH_TEXT, WIDTH_LONGTEXT, true ); - add_integer( CFG_PREFIX "height", 160, NULL, - HEIGHT_TEXT, HEIGHT_LONGTEXT, true ); + FORMAT_TEXT, FORMAT_LONGTEXT, false ) + add_integer( CFG_PREFIX "width", -1, NULL, + WIDTH_TEXT, WIDTH_LONGTEXT, true ) + add_integer( CFG_PREFIX "height", -1, NULL, + HEIGHT_TEXT, HEIGHT_LONGTEXT, true ) add_string( CFG_PREFIX "prefix", "scene", NULL, - PREFIX_TEXT, PREFIX_LONGTEXT, false ); + PREFIX_TEXT, PREFIX_LONGTEXT, false ) add_string( CFG_PREFIX "path", NULL, NULL, - PATH_TEXT, PATH_LONGTEXT, false ); + PATH_TEXT, PATH_LONGTEXT, false ) add_bool( CFG_PREFIX "replace", false, NULL, - REPLACE_TEXT, REPLACE_LONGTEXT, false ); + REPLACE_TEXT, REPLACE_LONGTEXT, false ) /* Snapshot method */ add_integer( CFG_PREFIX "ratio", 50, NULL, - RATIO_TEXT, RATIO_LONGTEXT, false ); + RATIO_TEXT, RATIO_LONGTEXT, false ) set_callbacks( Create, Destroy ) vlc_module_end () @@ -135,11 +132,12 @@ typedef struct scene_t { struct filter_sys_t { image_handler_t *p_image; - scene_t *p_scene; + scene_t scene; char *psz_path; char *psz_prefix; char *psz_format; + vlc_fourcc_t i_format; int32_t i_width; int32_t i_height; int32_t i_ratio; /* save every n-th frame */ @@ -153,47 +151,42 @@ struct filter_sys_t static int Create( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; - filter_sys_t *p_sys = NULL; + filter_sys_t *p_sys; config_ChainParse( p_filter, CFG_PREFIX, ppsz_vfilter_options, p_filter->p_cfg ); - p_filter->p_sys = p_sys = malloc( sizeof( filter_sys_t ) ); + p_filter->p_sys = p_sys = calloc( 1, sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) return VLC_ENOMEM; - memset( p_sys, 0, sizeof(filter_sys_t) ); - - p_sys->p_scene = malloc( sizeof( scene_t ) ); - if( !p_sys->p_scene ) - { - free( p_sys ); - return VLC_ENOMEM; - } - memset( p_sys->p_scene, 0, sizeof(scene_t) ); p_sys->p_image = image_HandlerCreate( p_this ); if( !p_sys->p_image ) { msg_Err( p_this, "Couldn't get handle to image conversion routines." ); - free( p_sys->p_scene ); free( p_sys ); return VLC_EGENERIC; } - p_sys->psz_prefix = var_CreateGetString( p_this, CFG_PREFIX "prefix" ); - p_sys->psz_path = var_GetNonEmptyString( p_this, CFG_PREFIX "path" ); - if( p_sys->psz_path == NULL ) + p_sys->psz_format = var_CreateGetString( p_this, CFG_PREFIX "format" ); + p_sys->i_format = image_Type2Fourcc( p_sys->psz_format ); + if( !p_sys->i_format ) { - int i_ret; - i_ret = asprintf( &p_sys->psz_path, "%s", config_GetHomeDir()); - if( i_ret == -1 ) - p_sys->psz_path = NULL; + msg_Err( p_filter, "Could not find FOURCC for image type '%s'", + p_sys->psz_format ); + image_HandlerDelete( p_sys->p_image ); + free( p_sys->psz_format ); + free( p_sys ); + return VLC_EGENERIC; } - p_sys->psz_format = var_CreateGetString( p_this, CFG_PREFIX "format" ); p_sys->i_width = var_CreateGetInteger( p_this, CFG_PREFIX "width" ); p_sys->i_height = var_CreateGetInteger( p_this, CFG_PREFIX "height" ); p_sys->i_ratio = var_CreateGetInteger( p_this, CFG_PREFIX "ratio" ); p_sys->b_replace = var_CreateGetBool( p_this, CFG_PREFIX "replace" ); + p_sys->psz_prefix = var_CreateGetString( p_this, CFG_PREFIX "prefix" ); + p_sys->psz_path = var_GetNonEmptyString( p_this, CFG_PREFIX "path" ); + if( p_sys->psz_path == NULL ) + p_sys->psz_path = config_GetUserDir( VLC_PICTURES_DIR ); p_filter->pf_video_filter = Filter; @@ -210,9 +203,8 @@ static void Destroy( vlc_object_t *p_this ) image_HandlerDelete( p_sys->p_image ); - if( p_sys->p_scene && p_sys->p_scene->p_pic ) - picture_Release( p_sys->p_scene->p_pic ); - free( p_sys->p_scene ); + if( p_sys->scene.p_pic ) + picture_Release( p_sys->scene.p_pic ); free( p_sys->psz_format ); free( p_sys->psz_prefix ); free( p_sys->psz_path ); @@ -233,7 +225,7 @@ static void SnapshotRatio( filter_t *p_filter, picture_t *p_pic ) { filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys; - if( !p_sys || !p_pic ) return; + if( !p_pic ) return; if( p_sys->i_frames % p_sys->i_ratio != 0 ) { @@ -242,18 +234,28 @@ static void SnapshotRatio( filter_t *p_filter, picture_t *p_pic ) } p_sys->i_frames++; - if( p_sys->p_scene ) + if( p_sys->scene.p_pic ) + picture_Release( p_sys->scene.p_pic ); + + if( (p_sys->i_width <= 0) && (p_sys->i_height > 0) ) { - if( p_sys->p_scene->p_pic ) - picture_Release( p_sys->p_scene->p_pic ); - p_sys->p_scene->p_pic = picture_New( p_pic->format.i_chroma, - p_pic->format.i_width, p_pic->format.i_height, - p_pic->format.i_sar_num ); - if( p_sys->p_scene->p_pic ) - { - picture_Copy( p_sys->p_scene->p_pic, p_pic ); - SavePicture( p_filter, p_sys->p_scene->p_pic ); - } + p_sys->i_width = (p_pic->format.i_width * p_sys->i_height) / p_pic->format.i_height; + } + else if( (p_sys->i_height <= 0) && (p_sys->i_width > 0) ) + { + p_sys->i_height = (p_pic->format.i_height * p_sys->i_width) / p_pic->format.i_width; + } + else if( (p_sys->i_width <= 0) && (p_sys->i_height <= 0) ) + { + p_sys->i_width = p_pic->format.i_width; + p_sys->i_height = p_pic->format.i_height; + } + + p_sys->scene.p_pic = picture_NewFromFormat( &p_pic->format ); + if( p_sys->scene.p_pic ) + { + picture_Copy( p_sys->scene.p_pic, p_pic ); + SavePicture( p_filter, p_sys->scene.p_pic ); } } @@ -276,24 +278,7 @@ static void SavePicture( filter_t *p_filter, picture_t *p_pic ) fmt_out.i_sar_num = fmt_out.i_sar_den = 1; fmt_out.i_width = p_sys->i_width; fmt_out.i_height = p_sys->i_height; - if( strlen( p_sys->psz_format ) == 3 ) - fmt_out.i_chroma = VLC_FOURCC('p','n','g',' '); - else - fmt_out.i_chroma = VLC_FOURCC('j','p','e','g'); - - if( (fmt_out.i_width == 0) && (fmt_out.i_height > 0) ) - { - fmt_out.i_width = (fmt_in.i_width * fmt_out.i_height) / fmt_in.i_height; - } - else if( (fmt_out.i_height == 0) && (fmt_out.i_width > 0) ) - { - fmt_out.i_height = (fmt_in.i_height * fmt_out.i_width) / fmt_in.i_width; - } - else if( (fmt_out.i_width == 0) && (fmt_out.i_height == 0) ) - { - fmt_out.i_width = fmt_in.i_width; - fmt_out.i_height = fmt_in.i_height; - } + fmt_out.i_chroma = p_sys->i_format; /* * Save the snapshot to a temporary file and