/*****************************************************************************
* lavf.c: libavformat input
*****************************************************************************
- * Copyright (C) 2009-2012 x264 project
+ * Copyright (C) 2009-2014 x264 project
*
* Authors: Mike Gurlitz <mike.gurlitz@gmail.com>
* Steven Walters <kemuri9@gmail.com>
#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;
{
switch( csp )
{
- case PIX_FMT_YUVJ420P: *fullrange = 1; return PIX_FMT_YUV420P;
- case PIX_FMT_YUVJ422P: *fullrange = 1; return PIX_FMT_YUV422P;
- case PIX_FMT_YUVJ444P: *fullrange = 1; return PIX_FMT_YUV444P;
+ case AV_PIX_FMT_YUVJ420P: *fullrange = 1; return AV_PIX_FMT_YUV420P;
+ case AV_PIX_FMT_YUVJ422P: *fullrange = 1; return AV_PIX_FMT_YUV422P;
+ case AV_PIX_FMT_YUVJ444P: *fullrange = 1; return AV_PIX_FMT_YUV444P;
default: return csp;
}
}
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 )
{
av_dict_set( &options, "video_size", opt->resolution, 0 );
- const char *csp = opt->colorspace ? opt->colorspace : av_get_pix_fmt_name( PIX_FMT_YUV420P );
+ const char *csp = opt->colorspace ? opt->colorspace : av_get_pix_fmt_name( AV_PIX_FMT_YUV420P );
av_dict_set( &options, "pixel_format", csp, 0 );
}
h->stream_id = i;
h->next_frame = 0;
AVCodecContext *c = h->lavf->streams[i]->codec;
- info->fps_num = h->lavf->streams[i]->r_frame_rate.num;
- info->fps_den = h->lavf->streams[i]->r_frame_rate.den;
+ info->fps_num = h->lavf->streams[i]->avg_frame_rate.num;
+ info->fps_den = h->lavf->streams[i]->avg_frame_rate.den;
info->timebase_num = h->lavf->streams[i]->time_base.num;
info->timebase_den = h->lavf->streams[i]->time_base.den;
/* lavf is thread unsafe as calling av_read_frame invalidates previously read AVPackets */
/* avisynth stores rgb data vertically flipped. */
if( !strcasecmp( get_filename_extension( psz_filename ), "avs" ) &&
- (c->pix_fmt == PIX_FMT_BGRA || c->pix_fmt == PIX_FMT_BGR24) )
+ (c->pix_fmt == AV_PIX_FMT_BGRA || c->pix_fmt == AV_PIX_FMT_BGR24) )
info->csp |= X264_CSP_VFLIP;
*p_handle = h;
{
lavf_hnd_t *h = handle;
avcodec_close( h->lavf->streams[h->stream_id]->codec );
- av_close_input_file( h->lavf );
+ 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;
}