Example #1
0
static int read_video( lsmash_handler_t *h, int frame_number, void *buf )
{
    libav_handler_t *hp = (libav_handler_t *)h->video_private;
    lwlibav_video_decode_handler_t *vdhp = &hp->vdh;
    if( vdhp->error )
        return 0;
    lwlibav_video_output_handler_t *vohp = &hp->voh;
    ++frame_number;            /* frame_number is 1-origin. */
    if( frame_number == 1 )
    {
        au_video_output_handler_t *au_vohp = (au_video_output_handler_t *)vohp->private_handler;
        memcpy( buf, au_vohp->back_ground, vohp->output_frame_size );
    }
    if( lwlibav_get_video_frame( vdhp, vohp, frame_number ) < 0 )
        return 0;
    return convert_colorspace( vohp, vdhp->ctx, vdhp->frame_buffer, buf );
}
Example #2
0
static int read_video( lsmash_handler_t *h, int sample_number, void *buf )
{
    avs_handler_t *hp = (avs_handler_t *)h->video_private;
    AVS_VideoFrame *as_frame = hp->func.avs_get_frame( hp->clip, sample_number );
    if( hp->func.avs_clip_get_error( hp->clip ) )
        return 0;
    if( avs_is_interleaved( hp->vi ) )
    {
        uint8_t *read_ptr = (uint8_t *)avs_get_read_ptr( as_frame );
        int      pitch    = avs_get_pitch( as_frame );
        if( avs_is_rgb( hp->vi ) )
        {
            hp->av_frame->data    [0] = read_ptr + pitch * (hp->vi->height - 1);
            hp->av_frame->linesize[0] = -pitch;
        }
        else
        {
            hp->av_frame->data    [0] = read_ptr;
            hp->av_frame->linesize[0] = pitch;
        }
    }
    else
        for( int i = 0; i < 3; i++ )
        {
            static const int as_plane[3] = { AVS_PLANAR_Y, AVS_PLANAR_U, AVS_PLANAR_V };
            hp->av_frame->data    [i] = (uint8_t *)avs_get_read_ptr_p( as_frame, as_plane[i] );
            hp->av_frame->linesize[i] = avs_get_pitch_p( as_frame, as_plane[i] );
        }
    hp->av_frame->width       = hp->vi->width;
    hp->av_frame->height      = hp->vi->height;
    hp->av_frame->format      = as_to_av_input_pixel_format( hp->vi->pixel_type, hp->bit_depth, &hp->av_frame->width );
    hp->av_frame->color_range = AVCOL_RANGE_UNSPECIFIED;
    hp->av_frame->colorspace  = AVCOL_SPC_UNSPECIFIED;
    /* Here, update_scaler_configuration_if_needed() is required to activate the scaler. */
    if( update_scaler_configuration_if_needed( &hp->voh.scaler, NULL, hp->av_frame ) < 0 )
        return 0;
    int frame_size = convert_colorspace( &hp->voh, hp->av_frame, buf );
    hp->func.avs_release_video_frame( as_frame );
    return frame_size;
}
Example #3
0
static int read_video
(
    lsmash_handler_t *h,
    int               sample_number,
    void             *buf
)
{
    vpy_handler_t *hp = (vpy_handler_t *)h->video_private;
    const VSFrameRef *vs_frame = hp->vsapi->getFrame( sample_number, hp->node, NULL, 0 );
    if( !vs_frame )
        return 0;
    int is_rgb = vs_is_rgb_format( hp->vi->format->colorFamily );
    for( int i = 0; i < hp->vi->format->numPlanes; i++ )
    {
        static const int component_reorder[2][3] =
            {
                { 0, 1, 2 },    /* YUV -> YUV */
                { 2, 0, 1 }     /* RGB -> GBR */
            };
        int j = component_reorder[is_rgb][i];
        hp->av_frame->data    [j] = (uint8_t *)hp->vsapi->getReadPtr( vs_frame, i );
        hp->av_frame->linesize[j] = hp->vsapi->getStride( vs_frame, i );
    }
    const VSMap *props = hp->vsapi->getFramePropsRO( vs_frame );
    if( hp->vsapi->propNumElements( props, "_ColorRange" ) > 0 )
        hp->ctx->color_range = hp->vsapi->propGetInt( props, "_ColorRange", 0, NULL )
                             ? AVCOL_RANGE_MPEG
                             : AVCOL_RANGE_JPEG;
    else
        hp->ctx->color_range = AVCOL_RANGE_UNSPECIFIED;
    if( hp->vsapi->propNumElements( props, "_ColorSpace" ) > 0 )
        hp->ctx->colorspace = hp->vsapi->propGetInt( props, "_ColorSpace", 0, NULL );
    else
        hp->ctx->colorspace = AVCOL_SPC_UNSPECIFIED;
    hp->av_frame->format = hp->ctx->pix_fmt;
    int frame_size = convert_colorspace( &hp->voh, hp->ctx, hp->av_frame, buf );
    hp->vsapi->freeFrame( vs_frame );
    return frame_size;
}