#define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "lavf", __VA_ARGS__ )
#undef DECLARE_ALIGNED
#include <libavformat/avformat.h>
+#include <libavutil/mem.h>
#include <libavutil/pixdesc.h>
#include <libavutil/dict.h>
typedef struct
{
AVFormatContext *lavf;
+ AVFrame *frame;
int stream_id;
int next_frame;
int vfr_input;
AVCodecContext *c = h->lavf->streams[h->stream_id]->codec;
AVPacket *pkt = p_pic->opaque;
- AVFrame frame;
- avcodec_get_frame_defaults( &frame );
+
+ avcodec_get_frame_defaults( h->frame );
while( i_frame >= h->next_frame )
{
pkt->size = 0;
c->reordered_opaque = pkt->pts;
- if( avcodec_decode_video2( c, &frame, &finished, pkt ) < 0 )
+ if( avcodec_decode_video2( c, h->frame, &finished, pkt ) < 0 )
x264_cli_log( "lavf", X264_LOG_WARNING, "video decoding failed on frame %d\n", h->next_frame );
}
/* if the packet successfully decoded but the data from it is not desired, free it */
h->next_frame++;
}
- memcpy( p_pic->img.stride, frame.linesize, sizeof(p_pic->img.stride) );
- memcpy( p_pic->img.plane, frame.data, sizeof(p_pic->img.plane) );
+ memcpy( p_pic->img.stride, h->frame->linesize, sizeof(p_pic->img.stride) );
+ memcpy( p_pic->img.plane, h->frame->data, sizeof(p_pic->img.plane) );
int is_fullrange = 0;
p_pic->img.width = c->width;
p_pic->img.height = c->height;
if( info )
{
info->fullrange = is_fullrange;
- info->interlaced = frame.interlaced_frame;
- info->tff = frame.top_field_first;
+ info->interlaced = h->frame->interlaced_frame;
+ info->tff = h->frame->top_field_first;
}
if( h->vfr_input )
{
p_pic->pts = p_pic->duration = 0;
- if( c->has_b_frames && frame.reordered_opaque != AV_NOPTS_VALUE )
- p_pic->pts = frame.reordered_opaque;
+ if( c->has_b_frames && h->frame->reordered_opaque != AV_NOPTS_VALUE )
+ p_pic->pts = h->frame->reordered_opaque;
else if( pkt->dts != AV_NOPTS_VALUE )
p_pic->pts = pkt->dts; // for AVI files
else if( info )
if( !strcmp( psz_filename, "-" ) )
psz_filename = "pipe:";
+ h->frame = avcodec_alloc_frame();
+ if( !h->frame )
+ return -1;
+
/* if resolution was passed in, place it and colorspace into options. this allows raw video support */
AVDictionary *options = NULL;
if( opt->resolution )
lavf_hnd_t *h = handle;
avcodec_close( h->lavf->streams[h->stream_id]->codec );
avformat_close_input( &h->lavf );
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0)
+ avcodec_free_frame( &h->frame );
+#else
+ av_freep( &h->frame );
+#endif
free( h );
return 0;
}