示例#1
0
int lwlibav_get_desired_video_track
(
    const char                     *file_path,
    lwlibav_video_decode_handler_t *vdhp,
    int                             threads
)
{
    int error = vdhp->stream_index < 0
             || vdhp->frame_count == 0
             || lavf_open_file( &vdhp->format, file_path, &vdhp->lh );
    AVCodecContext *ctx = !error ? vdhp->format->streams[ vdhp->stream_index ]->codec : NULL;
    if( error || open_decoder( ctx, vdhp->codec_id, threads ) )
    {
        if( vdhp->index_entries )
            av_freep( &vdhp->index_entries );
        if( vdhp->frame_list )
            lw_freep( &vdhp->frame_list );
        if( vdhp->order_converter )
            lw_freep( &vdhp->order_converter );
        if( vdhp->keyframe_list )
            lw_freep( &vdhp->keyframe_list );
        if( vdhp->format )
        {
            lavf_close_file( &vdhp->format );
            vdhp->format = NULL;
        }
        return -1;
    }
    vdhp->ctx = ctx;
    ctx->refcounted_frames = 1;
    return 0;
}
void libavsmash_video_free_decode_handler
(
    libavsmash_video_decode_handler_t *vdhp
)
{
    if( !vdhp )
        return;
    lw_freep( &vdhp->keyframe_list );
    lw_freep( &vdhp->order_converter );
    av_frame_free( &vdhp->frame_buffer );
    av_frame_free( &vdhp->first_valid_frame );
    cleanup_configuration( &vdhp->config );
    lw_free( vdhp );
}
示例#3
0
static int get_first_video_track( lsmash_handler_t *h, video_option_t *opt )
{
    if( h->audio_pcm_sample_count == 0 || h->audio_format.Format.nSamplesPerSec == 0 )
        return -1;  /* Only available if audio stream is present. */
    if( opt->dummy.framerate_den == 0 )
        return -1;
    h->framerate_num = opt->dummy.framerate_num;
    h->framerate_den = opt->dummy.framerate_den;
    h->video_sample_count = ((uint64_t)h->framerate_num * h->audio_pcm_sample_count - 1)
                            / ((uint64_t)h->framerate_den * h->audio_format.Format.nSamplesPerSec) + 1;
    static const struct
    {
        int                   pixel_size;
        output_colorspace_tag compression;
    } colorspace_table[3] =
    {
        { YUY2_SIZE,  OUTPUT_TAG_YUY2 },
        { RGB24_SIZE, OUTPUT_TAG_RGB  },
        { YC48_SIZE,  OUTPUT_TAG_YC48 }
    };
    int linesize = MAKE_AVIUTL_PITCH( opt->dummy.width * (colorspace_table[ opt->dummy.colorspace ].pixel_size << 3) );
    dummy_handler_t *hp = (dummy_handler_t *)h->video_private;
    hp->dummy_size = linesize * opt->dummy.height;
    if( hp->dummy_size <= 0 )
        return -1;
    hp->dummy_data = lw_malloc_zero( hp->dummy_size );
    if( !hp->dummy_data )
        return -1;
    uint8_t *pic = hp->dummy_data;
    switch( colorspace_table[ opt->dummy.colorspace ].compression )
    {
    case OUTPUT_TAG_YC48 :
    case OUTPUT_TAG_RGB :
        break;
    case OUTPUT_TAG_YUY2 :
        for( int i = 0; i < opt->dummy.height; i++ )
        {
            for( int j = 0; j < linesize; j += 2 )
            {
                pic[j    ] = 0;
                pic[j + 1] = 128;
            }
            pic += linesize;
        }
        break;
    default :
        lw_freep( &hp->dummy_data );
        return -1;
    }
    /* BITMAPINFOHEADER */
    h->video_format.biSize        = sizeof( BITMAPINFOHEADER );
    h->video_format.biWidth       = opt->dummy.width;
    h->video_format.biHeight      = opt->dummy.height;
    h->video_format.biBitCount    = colorspace_table[ opt->dummy.colorspace ].pixel_size << 3;
    h->video_format.biCompression = colorspace_table[ opt->dummy.colorspace ].compression;
    return 0;
}
示例#4
0
void lwlibav_cleanup_video_decode_handler
(
    lwlibav_video_decode_handler_t *vdhp
)
{
    lwlibav_extradata_handler_t *exhp = &vdhp->exh;
    if( exhp->entries )
    {
        for( int i = 0; i < exhp->entry_count; i++ )
            if( exhp->entries[i].extradata )
                av_free( exhp->entries[i].extradata );
        free( exhp->entries );
    }
    av_free_packet( &vdhp->packet );
    if( vdhp->frame_list )
        lw_freep( &vdhp->frame_list );
    if( vdhp->order_converter )
        lw_freep( &vdhp->order_converter );
    if( vdhp->keyframe_list )
        lw_freep( &vdhp->keyframe_list );
    if( vdhp->index_entries )
        av_freep( &vdhp->index_entries );
    if( vdhp->frame_buffer )
        av_frame_free( &vdhp->frame_buffer );
    if( vdhp->first_valid_frame )
        av_frame_free( &vdhp->first_valid_frame );
    if( vdhp->movable_frame_buffer )
        av_frame_free( &vdhp->movable_frame_buffer );
    if( vdhp->ctx )
    {
        avcodec_close( vdhp->ctx );
        vdhp->ctx = NULL;
    }
    if( vdhp->format )
        lavf_close_file( &vdhp->format );
}
示例#5
0
void lw_cleanup_video_output_handler
(
    lw_video_output_handler_t *vohp
)
{
    if( vohp->free_private_handler )
        vohp->free_private_handler( vohp->private_handler );
    vohp->private_handler = NULL;
    if( vohp->frame_order_list )
        lw_freep( &vohp->frame_order_list );
    for( int i = 0; i < REPEAT_CONTROL_CACHE_NUM; i++ )
        if( vohp->frame_cache_buffers[i] )
            av_frame_free( &vohp->frame_cache_buffers[i] );
    if( vohp->scaler.sws_ctx )
    {
        sws_freeContext( vohp->scaler.sws_ctx );
        vohp->scaler.sws_ctx = NULL;
    }
}
示例#6
0
int lwlibav_audio_get_desired_track
(
    const char                     *file_path,
    lwlibav_audio_decode_handler_t *adhp,
    int                             threads
)
{
    AVCodecContext *ctx = NULL;
    if( adhp->stream_index < 0
     || adhp->frame_count == 0
     || lavf_open_file( &adhp->format, file_path, &adhp->lh ) < 0
     || find_and_open_decoder( &ctx, adhp->format->streams[ adhp->stream_index ]->codecpar,
                               adhp->preferred_decoder_names, threads, 0 ) < 0 )
    {
        av_freep( &adhp->index_entries );
        lw_freep( &adhp->frame_list );
        if( adhp->format )
            lavf_close_file( &adhp->format );
        return -1;
    }
    adhp->ctx = ctx;
    return 0;
}