Beispiel #1
0
/*****************************************************************************
 * Init: initialize Transform video thread output method
 *****************************************************************************/
static int Init( vout_thread_t *p_vout )
{
    video_format_t fmt;

    I_OUTPUTPICTURES = 0;
    memset( &fmt, 0, sizeof(video_format_t) );

    /* 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;
    fmt = p_vout->fmt_out;

    /* Try to open the real video output */
    msg_Dbg( p_vout, "spawning the real video output" );

    if( p_vout->p_sys->b_rotation )
    {
        fmt.i_width = p_vout->fmt_out.i_height;
        fmt.i_visible_width = p_vout->fmt_out.i_visible_height;
        fmt.i_x_offset = p_vout->fmt_out.i_y_offset;

        fmt.i_height = p_vout->fmt_out.i_width;
        fmt.i_visible_height = p_vout->fmt_out.i_visible_width;
        fmt.i_y_offset = p_vout->fmt_out.i_x_offset;

        fmt.i_sar_num = p_vout->fmt_out.i_sar_den;
        fmt.i_sar_den = p_vout->fmt_out.i_sar_num;
    }

    p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt );

    /* Everything failed */
    if( p_vout->p_sys->p_vout == NULL )
    {
        msg_Err( p_vout, "cannot open vout, aborting" );
        return VLC_EGENERIC;
    }

    vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES );

    vout_filter_AddChild( p_vout, p_vout->p_sys->p_vout, MouseEvent );

    return VLC_SUCCESS;
}
Beispiel #2
0
/*****************************************************************************
 * Init: initialize Crop video thread output method
 *****************************************************************************/
static int Init( vout_thread_t *p_vout )
{
    char *psz_var;
    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 = var_InheritBool( p_vout, "autocrop" );
#ifdef BEST_AUTOCROP
    p_vout->p_sys->i_ratio_max =
        var_InheritInteger( p_vout, "autocrop-ratio-max" );
    p_vout->p_sys->i_threshold =
        var_InheritInteger( p_vout, "autocrop-luminance-threshold" );
    p_vout->p_sys->i_skipPercent =
        var_InheritInteger( p_vout, "autocrop-skip-percent" );
    p_vout->p_sys->i_nonBlackPixel =
        var_InheritInteger( p_vout, "autocrop-non-black-pixels" );
    p_vout->p_sys->i_diff =
        var_InheritInteger( p_vout, "autocrop-diff" );
    p_vout->p_sys->i_time =
        var_InheritInteger( p_vout, "autocrop-time" );
    var_SetString( p_vout, "ratio-crop", "0" );

    if (p_vout->p_sys->b_autocrop)
        p_vout->p_sys->i_ratio = 0;
    else
    {
        p_vout->p_sys->i_ratio = var_InheritInteger( 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 = var_InheritString( 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 =
                     ( 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;
        }

        /* Check for validity */
        if( p_vout->p_sys->i_x + p_vout->p_sys->i_width
                                                   > p_vout->output.i_width )
        {
            p_vout->p_sys->i_x = 0;
            if( p_vout->p_sys->i_width > p_vout->output.i_width )
            {
                p_vout->p_sys->i_width = p_vout->output.i_width;
            }
        }

        if( p_vout->p_sys->i_y + p_vout->p_sys->i_height
                                                   > p_vout->output.i_height )
        {
            p_vout->p_sys->i_y = 0;
            if( p_vout->p_sys->i_height > p_vout->output.i_height )
            {
                p_vout->p_sys->i_height = p_vout->output.i_height;
            }
        }

        free( psz_var );
    }
    else
#ifdef BEST_AUTOCROP
    if (p_vout->p_sys->i_ratio)
    {
        p_vout->p_sys->i_aspect    =  p_vout->p_sys->i_ratio * 432;
        p_vout->p_sys->i_width  = p_vout->fmt_out.i_visible_width;
        p_vout->p_sys->i_height = p_vout->output.i_aspect
                                * p_vout->output.i_height / p_vout->p_sys->i_aspect
                                * p_vout->p_sys->i_width / p_vout->output.i_width;
        p_vout->p_sys->i_height += p_vout->p_sys->i_height % 2;
        p_vout->p_sys->i_x = p_vout->fmt_out.i_x_offset;
        p_vout->p_sys->i_y = (p_vout->output.i_height - p_vout->p_sys->i_height) / 2;
    }
    else
#endif
    {
        p_vout->p_sys->i_width  = p_vout->fmt_out.i_visible_width;
        p_vout->p_sys->i_height = p_vout->fmt_out.i_visible_height;
        p_vout->p_sys->i_x = p_vout->fmt_out.i_x_offset;
        p_vout->p_sys->i_y = p_vout->fmt_out.i_y_offset;
    }

    /* Pheeew. Parsing done. */
    msg_Dbg( p_vout, "cropping at %ix%i+%i+%i, %sautocropping",
                     p_vout->p_sys->i_width, p_vout->p_sys->i_height,
                     p_vout->p_sys->i_x, p_vout->p_sys->i_y,
                     p_vout->p_sys->b_autocrop ? "" : "not " );
    /* Set current output image properties */
    p_vout->p_sys->i_aspect = (int64_t)VOUT_ASPECT_FACTOR *
        p_vout->fmt_out.i_sar_num * p_vout->p_sys->i_width /
        (p_vout->fmt_out.i_sar_den * p_vout->p_sys->i_height);

#ifdef BEST_AUTOCROP
    msg_Info( p_vout, "ratio %d",  p_vout->p_sys->i_aspect / 432);
#endif
    fmt.i_width = fmt.i_visible_width = p_vout->p_sys->i_width;
    fmt.i_height = fmt.i_visible_height = p_vout->p_sys->i_height;
    fmt.i_x_offset = fmt.i_y_offset = 0;
    fmt.i_chroma = p_vout->render.i_chroma;
    fmt.i_sar_num = p_vout->p_sys->i_aspect * fmt.i_height;
    fmt.i_sar_den = VOUT_ASPECT_FACTOR * fmt.i_width;

    /* Try to open the real video output */
    p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt );
    if( p_vout->p_sys->p_vout == NULL )
    {
        msg_Err( p_vout, "failed to create vout" );
        dialog_Fatal( p_vout, _("Cropping failed"), "%s",
                        _("VLC could not open the video output module.") );
        return VLC_EGENERIC;
    }

    vlc_mutex_init( &p_vout->p_sys->lock );
#ifdef BEST_AUTOCROP
    var_AddCallback( p_vout, "ratio-crop", FilterCallback, NULL );
#endif

    vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES );

    vout_filter_AddChild( p_vout, p_vout->p_sys->p_vout, MouseEvent );

    return VLC_SUCCESS;
}
Beispiel #3
0
/*****************************************************************************
 * Init: initialize opencv_wrapper video thread output method
 *****************************************************************************/
static int Init( vout_thread_t *p_vout )
{
    video_format_t fmt;
    vout_sys_t *p_sys = p_vout->p_sys;
    I_OUTPUTPICTURES = 0;

    /* Initialize the output video format */
    memset( &fmt, 0, sizeof(video_format_t) );
    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;           //set to input video format

    fmt = p_vout->fmt_out;
    if (p_sys->i_wrapper_output == PROCESSED)   //set to processed video format
    {
        fmt.i_width = fmt.i_width * p_sys->f_scale;
        fmt.i_height = fmt.i_height * p_sys->f_scale;
        fmt.i_visible_width = fmt.i_visible_width * p_sys->f_scale;
        fmt.i_visible_height = fmt.i_visible_height * p_sys->f_scale;
        fmt.i_x_offset = fmt.i_x_offset * p_sys->f_scale;
        fmt.i_y_offset = fmt.i_y_offset * p_sys->f_scale;

        if (p_sys->i_internal_chroma == GREY)
            fmt.i_chroma = VLC_CODEC_I420;
        else if (p_sys->i_internal_chroma == RGB)
            fmt.i_chroma = VLC_CODEC_RGB32;
    }

    /* Load the internal opencv filter */
    /* We don't need to set up video formats for this filter as it not actually using a picture_t */
    p_sys->p_opencv = vlc_object_create( p_vout, sizeof(filter_t) );
    vlc_object_attach( p_sys->p_opencv, p_vout );

    if (p_vout->p_sys->psz_inner_name)
        p_sys->p_opencv->p_module =
            module_need( p_sys->p_opencv, p_sys->psz_inner_name, NULL, false );

    if( !p_sys->p_opencv->p_module )
    {
        msg_Err( p_vout, "can't open internal opencv filter: %s", p_vout->p_sys->psz_inner_name );
        p_vout->p_sys->psz_inner_name = NULL;
        vlc_object_release( p_sys->p_opencv );
        p_sys->p_opencv = NULL;
    }

    /* Try to open the real video output */
    if (p_sys->i_verbosity > VERB_WARN)
        msg_Dbg( p_vout, "spawning the real video output" );

    p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt );

    /* Everything failed */
    if( p_vout->p_sys->p_vout == NULL )
    {
        msg_Err( p_vout, "can't open vout, aborting" );
        return VLC_EGENERIC;
    }

    vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES );

    vout_filter_AddChild( p_vout, p_vout->p_sys->p_vout, NULL );

    return VLC_SUCCESS;
}