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; }
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; }