Esempio n. 1
0
static VSFrameRef *new_output_video_frame
(
    vs_video_output_handler_t *vs_vohp,
    const AVFrame             *av_frame,
    enum AVPixelFormat        *output_pixel_format,
    int                       *enable_scaler,
    int                        input_pix_fmt_change,
    VSFrameContext            *frame_ctx,
    VSCore                    *core,
    const VSAPI               *vsapi
)
{
    if( vs_vohp->variable_info )
    {
        if( !av_frame->opaque
         && determine_colorspace_conversion( vs_vohp, av_frame->format, output_pixel_format, enable_scaler ) < 0 )
            goto fail;
        const VSFormat *vs_format = vsapi->getFormatPreset( vs_vohp->vs_output_pixel_format, core );
        return vsapi->newVideoFrame( vs_format, av_frame->width, av_frame->height, NULL, core );
    }
    else
    {
        if( !av_frame->opaque
         && input_pix_fmt_change
         && determine_colorspace_conversion( vs_vohp, av_frame->format, output_pixel_format, enable_scaler ) < 0 )
            goto fail;
        return vsapi->copyFrame( vs_vohp->background_frame, core );
    }
fail:
    if( frame_ctx )
        vsapi->setFilterError( "lsmas: failed to determine colorspace conversion.", frame_ctx );
    return NULL;
}
Esempio n. 2
0
VSFrameRef *new_output_video_frame
(
    lw_video_output_handler_t *vohp,
    int                        width,
    int                        height,
    enum AVPixelFormat         pixel_format,
    VSFrameContext            *frame_ctx,
    VSCore                    *core,
    const VSAPI               *vsapi
)
{
    vs_video_output_handler_t *vs_vohp = (vs_video_output_handler_t *)vohp->private_handler;
    VSFrameRef                *vs_frame;
    if( vs_vohp->variable_info )
    {
        if( determine_colorspace_conversion( vohp, pixel_format ) )
        {
            if( frame_ctx )
                vsapi->setFilterError( "lsmas: failed to determin colorspace conversion.", frame_ctx );
            return NULL;
        }
        const VSFormat *vs_format = vsapi->getFormatPreset( vs_vohp->vs_output_pixel_format, core );
        vs_frame = vsapi->newVideoFrame( vs_format, width, height, NULL, core );
    }
    else
    {
        if( pixel_format != vohp->scaler.input_pixel_format
         && determine_colorspace_conversion( vohp, pixel_format ) )
        {
            if( frame_ctx )
                vsapi->setFilterError( "lsmas: failed to determin colorspace conversion.", frame_ctx );
            return NULL;
        }
        vs_frame = vsapi->copyFrame( vs_vohp->background_frame, core );
    }
    return vs_frame;
}
Esempio n. 3
0
int vs_setup_video_rendering
(
    lw_video_output_handler_t *lw_vohp,
    AVCodecContext            *ctx,
    VSVideoInfo               *vi,
    VSMap                     *out,
    int                        width,
    int                        height
)
{
    vs_video_output_handler_t *vs_vohp = (vs_video_output_handler_t *)lw_vohp->private_handler;
    const VSAPI *vsapi = vs_vohp->vsapi;
    enum AVPixelFormat output_pixel_format;
    int                enable_scaler;
    if( determine_colorspace_conversion( vs_vohp, ctx->pix_fmt, &output_pixel_format, &enable_scaler ) )
    {
        set_error_on_init( out, vsapi, "lsmas: %s is not supported", av_get_pix_fmt_name( ctx->pix_fmt ) );
        return -1;
    }
    vs_vohp->direct_rendering &= vs_check_dr_available( ctx, ctx->pix_fmt );
    int (*dr_get_buffer)( struct AVCodecContext *, AVFrame *, int ) = vs_vohp->direct_rendering ? vs_video_get_buffer : NULL;
    setup_video_rendering( lw_vohp, enable_scaler, SWS_FAST_BILINEAR,
                           width, height, output_pixel_format,
                           ctx, dr_get_buffer );
    if( vs_vohp->variable_info )
    {
        vi->format = NULL;
        vi->width  = 0;
        vi->height = 0;
        /* Unused */
        //lw_vohp->output_width  = 0;
        //lw_vohp->output_height = 0;
    }
    else
    {
        vi->format = vsapi->getFormatPreset( vs_vohp->vs_output_pixel_format, vs_vohp->core );
        vi->width  = lw_vohp->output_width;
        vi->height = lw_vohp->output_height;
        vs_vohp->background_frame = vsapi->newVideoFrame( vi->format, vi->width, vi->height, NULL, vs_vohp->core );
        if( !vs_vohp->background_frame )
        {
            set_error_on_init( out, vsapi, "lsmas: failed to allocate memory for the background black frame data." );
            return -1;
        }
        vs_vohp->make_black_background( vs_vohp->background_frame, vsapi );
    }
    return 0;
}