#define PADD_LONGTEXT N_( \
"If enabled, video will be padded to fit in canvas after scaling. " \
"Otherwise, video will be cropped to fix in canvas after scaling." )
+#define CANVAS_HELP N_( "Automatically resize and pad a video" )
#define CFG_PREFIX "canvas-"
*****************************************************************************/
vlc_module_begin ()
set_shortname( N_("Canvas") )
- set_description( N_("Automatically resize and pad a video") )
+ set_description( N_("Canvas video filter") )
set_capability( "video filter2", 0 )
+ set_help( CANVAS_HELP )
set_callbacks( Activate, Destroy )
set_category( CAT_VIDEO )
int i_padd,i_offset;
char *psz_aspect, *psz_parser;
bool b_padd;
+ unsigned i_fmt_in_aspect;
if( !p_filter->b_allow_fmt_out_change )
{
return VLC_EGENERIC;
}
+ i_fmt_in_aspect = (int64_t)p_filter->fmt_in.video.i_sar_num *
+ p_filter->fmt_in.video.i_width *
+ VOUT_ASPECT_FACTOR /
+ p_filter->fmt_in.video.i_sar_den /
+ p_filter->fmt_in.video.i_height;
psz_aspect = var_CreateGetNonEmptyString( p_filter, CFG_PREFIX "aspect" );
if( psz_aspect )
{
/* aspect = subpic_sar * canvas_width / canvas_height
* where subpic_sar = subpic_ph * subpic_par / subpic_pw */
i_canvas_aspect = (uint64_t) p_filter->fmt_in.video.i_height
- * p_filter->fmt_in.video.i_aspect
+ * i_fmt_in_aspect
* i_canvas_width
/ (i_canvas_height * p_filter->fmt_in.video.i_width);
}
if( b_padd )
{
/* Padd */
- if( i_canvas_aspect > p_filter->fmt_in.video.i_aspect )
+ if( i_canvas_aspect > i_fmt_in_aspect )
{
/* The canvas has a wider aspect than the subpicture:
* ie, pillarbox the [scaled] subpicture */
* where canvas_sar = canvas_width / (canvas_height * canvas_par)
* then simplify */
fmt.video.i_width = i_canvas_width
- * p_filter->fmt_in.video.i_aspect
+ * i_fmt_in_aspect
/ i_canvas_aspect;
if( fmt.video.i_width & 1 ) fmt.video.i_width -= 1;
* ie, letterbox the [scaled] subpicture */
fmt.video.i_height = i_canvas_height
* i_canvas_aspect
- / p_filter->fmt_in.video.i_aspect;
+ / i_fmt_in_aspect;
if( fmt.video.i_height & 1 ) fmt.video.i_height -= 1;
i_padd = (i_canvas_height - fmt.video.i_height ) / 2;
else
{
/* Crop */
- if( i_canvas_aspect < p_filter->fmt_in.video.i_aspect )
+ if( i_canvas_aspect < i_fmt_in_aspect )
{
/* The canvas has a narrower aspect than the subpicture:
* ie, crop the [scaled] subpicture horizontally */
fmt.video.i_width = i_canvas_width
- * p_filter->fmt_in.video.i_aspect
+ * i_fmt_in_aspect
/ i_canvas_aspect;
if( fmt.video.i_width & 1 ) fmt.video.i_width -= 1;
* ie, crop the [scaled] subpicture vertically */
fmt.video.i_height = i_canvas_height
* i_canvas_aspect
- / p_filter->fmt_in.video.i_aspect;
+ / i_fmt_in_aspect;
if( fmt.video.i_height & 1 ) fmt.video.i_height -= 1;
i_padd = (fmt.video.i_height - i_canvas_height) / 2;
fmt = *filter_chain_GetFmtOut( p_sys->p_chain );
es_format_Copy( &p_filter->fmt_out, &fmt );
- p_filter->fmt_out.video.i_aspect = i_canvas_aspect;
+ p_filter->fmt_out.video.i_sar_num =
+ i_canvas_aspect * p_filter->fmt_out.video.i_height;
+ p_filter->fmt_out.video.i_sar_den =
+ VOUT_ASPECT_FACTOR * p_filter->fmt_out.video.i_width;
if( p_filter->fmt_out.video.i_width != i_canvas_width
|| p_filter->fmt_out.video.i_height != i_canvas_height )
static int alloc_init( filter_t *p_filter, void *p_data )
{
p_filter->p_owner = p_data;
- p_filter->pf_vout_buffer_new = video_new;
- p_filter->pf_vout_buffer_del = video_del;
+ p_filter->pf_video_buffer_new = video_new;
+ p_filter->pf_video_buffer_del = video_del;
return VLC_SUCCESS;
}