mirror of
https://github.com/mpv-player/mpv
synced 2025-02-21 15:27:00 +00:00
support for lavc build 4641
no #ifdefs this time as the difference is big and iam lazy, feel free to add #ifdef LIBAVCODEC_BUILD ... git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8340 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
dc871c209f
commit
ad05ae27cb
@ -32,6 +32,10 @@ LIBVD_EXTERN(ffmpeg)
|
|||||||
#include "libavcodec/avcodec.h"
|
#include "libavcodec/avcodec.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LIBAVCODEC_BUILD < 4641
|
||||||
|
#error your version of libavcodec is too old, get a newer one, and dont send a bugreport, THIS IS NO BUG
|
||||||
|
#endif
|
||||||
|
|
||||||
int avcodec_inited=0;
|
int avcodec_inited=0;
|
||||||
|
|
||||||
#if defined(FF_POSTPROCESS) && defined(MBR)
|
#if defined(FF_POSTPROCESS) && defined(MBR)
|
||||||
@ -40,12 +44,15 @@ int quant_store[MBR+1][MBC+1];
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
AVCodecContext *avctx;
|
AVCodecContext *avctx;
|
||||||
|
AVVideoFrame *pic;
|
||||||
float last_aspect;
|
float last_aspect;
|
||||||
int do_slices;
|
int do_slices;
|
||||||
int do_dr1;
|
int do_dr1;
|
||||||
int vo_inited;
|
int vo_inited;
|
||||||
int convert;
|
int convert;
|
||||||
int best_csp;
|
int best_csp;
|
||||||
|
int b_age;
|
||||||
|
int ip_age[2];
|
||||||
} vd_ffmpeg_ctx;
|
} vd_ffmpeg_ctx;
|
||||||
|
|
||||||
//#ifdef FF_POSTPROCESS
|
//#ifdef FF_POSTPROCESS
|
||||||
@ -54,11 +61,8 @@ typedef struct {
|
|||||||
|
|
||||||
#include "cfgparser.h"
|
#include "cfgparser.h"
|
||||||
|
|
||||||
#if LIBAVCODEC_BUILD >= 4632
|
static int get_buffer(AVCodecContext *avctx, AVVideoFrame *pic);
|
||||||
static int get_buffer(struct AVCodecContext *avctx, int width, int height, int pict_type);
|
static void release_buffer(AVCodecContext *avctx, AVVideoFrame *pic);
|
||||||
#else
|
|
||||||
static void get_buffer(struct AVCodecContext *avctx, int width, int height, int pict_type);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FF_BUG_AUTODETECT
|
#ifdef FF_BUG_AUTODETECT
|
||||||
static int lavc_param_workaround_bugs= FF_BUG_AUTODETECT;
|
static int lavc_param_workaround_bugs= FF_BUG_AUTODETECT;
|
||||||
@ -150,7 +154,11 @@ static int init(sh_video_t *sh){
|
|||||||
if(sh->format == mmioFOURCC('H','F','Y','U'))
|
if(sh->format == mmioFOURCC('H','F','Y','U'))
|
||||||
ctx->do_dr1=0;
|
ctx->do_dr1=0;
|
||||||
#endif
|
#endif
|
||||||
|
ctx->b_age= ctx->ip_age[0]= ctx->ip_age[1]= 256*256*256*64;
|
||||||
|
|
||||||
|
#if LIBAVCODEC_BUILD >= 4641
|
||||||
|
ctx->pic = avcodec_alloc_picture();
|
||||||
|
#endif
|
||||||
#if LIBAVCODEC_BUILD >= 4624
|
#if LIBAVCODEC_BUILD >= 4624
|
||||||
ctx->avctx = avcodec_alloc_context();
|
ctx->avctx = avcodec_alloc_context();
|
||||||
#else
|
#else
|
||||||
@ -161,8 +169,9 @@ static int init(sh_video_t *sh){
|
|||||||
|
|
||||||
#if LIBAVCODEC_BUILD > 4615
|
#if LIBAVCODEC_BUILD > 4615
|
||||||
if(ctx->do_dr1){
|
if(ctx->do_dr1){
|
||||||
avctx->flags|= CODEC_FLAG_EMU_EDGE | CODEC_FLAG_DR1;
|
avctx->flags|= CODEC_FLAG_EMU_EDGE;
|
||||||
avctx->get_buffer_callback= get_buffer;
|
avctx->get_buffer= get_buffer;
|
||||||
|
avctx->release_buffer= release_buffer;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -284,6 +293,8 @@ static void uninit(sh_video_t *sh){
|
|||||||
|
|
||||||
if (avctx)
|
if (avctx)
|
||||||
free(avctx);
|
free(avctx);
|
||||||
|
if (ctx->pic)
|
||||||
|
free(ctx->pic);
|
||||||
if (ctx)
|
if (ctx)
|
||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
@ -295,16 +306,17 @@ static void draw_slice(struct AVCodecContext *s,
|
|||||||
int stride[3];
|
int stride[3];
|
||||||
int start=0, i;
|
int start=0, i;
|
||||||
int skip_stride= (s->width+15)>>4;
|
int skip_stride= (s->width+15)>>4;
|
||||||
#if LIBAVCODEC_BUILD > 4615
|
#if LIBAVCODEC_BUILD >= 4641
|
||||||
UINT8 *skip= &s->mbskip_table[(y>>4)*skip_stride];
|
UINT8 *skip= &s->coded_picture->mbskip_table[(y>>4)*skip_stride];
|
||||||
int threshold= s->pict_type==B_TYPE ? -99 : s->dr_ip_buffer_count;
|
int threshold= s->coded_picture->age;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
stride[0]=linesize;
|
stride[0]=linesize;
|
||||||
#if LIBAVCODEC_BUILD > 4615
|
#if LIBAVCODEC_BUILD >= 4641
|
||||||
if(s->dr_uvstride)
|
if(s->coded_picture->linesize[1]){
|
||||||
stride[1]=stride[2]= s->dr_uvstride;
|
stride[1]= s->coded_picture->linesize[1];
|
||||||
else
|
stride[2]= s->coded_picture->linesize[2];
|
||||||
|
}else
|
||||||
#endif
|
#endif
|
||||||
stride[1]=stride[2]=stride[0]/2;
|
stride[1]=stride[2]=stride[0]/2;
|
||||||
#if 0
|
#if 0
|
||||||
@ -368,17 +380,15 @@ static int init_vo(sh_video_t *sh){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LIBAVCODEC_BUILD > 4615
|
#if LIBAVCODEC_BUILD >= 4641
|
||||||
#if LIBAVCODEC_BUILD >= 4632
|
static int get_buffer(AVCodecContext *avctx, AVVideoFrame *pic){
|
||||||
static int get_buffer(struct AVCodecContext *avctx, int width, int height, int pict_type){
|
|
||||||
#else
|
|
||||||
static void get_buffer(struct AVCodecContext *avctx, int width, int height, int pict_type){
|
|
||||||
#endif
|
|
||||||
sh_video_t * sh = avctx->opaque;
|
sh_video_t * sh = avctx->opaque;
|
||||||
vd_ffmpeg_ctx *ctx = sh->context;
|
vd_ffmpeg_ctx *ctx = sh->context;
|
||||||
mp_image_t* mpi=NULL;
|
mp_image_t* mpi=NULL;
|
||||||
int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE;
|
int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE;
|
||||||
int type= MP_IMGTYPE_IPB;
|
int type= MP_IMGTYPE_IPB;
|
||||||
|
int width= avctx->width;
|
||||||
|
int height= avctx->height;
|
||||||
int align=15;
|
int align=15;
|
||||||
|
|
||||||
if(avctx->pix_fmt == PIX_FMT_YUV410P)
|
if(avctx->pix_fmt == PIX_FMT_YUV410P)
|
||||||
@ -386,14 +396,13 @@ static void get_buffer(struct AVCodecContext *avctx, int width, int height, int
|
|||||||
|
|
||||||
if(init_vo(sh)<0){
|
if(init_vo(sh)<0){
|
||||||
printf("init_vo failed\n");
|
printf("init_vo failed\n");
|
||||||
#if LIBAVCODEC_BUILD >= 4632
|
|
||||||
return -1;
|
avctx->get_buffer= avcodec_default_get_buffer;
|
||||||
#else
|
avctx->release_buffer= avcodec_default_release_buffer;
|
||||||
return;
|
return avctx->get_buffer(avctx, pic);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pict_type==B_TYPE)
|
if(!pic->reference)
|
||||||
flags|=(!avctx->hurry_up && ctx->do_slices) ?
|
flags|=(!avctx->hurry_up && ctx->do_slices) ?
|
||||||
MP_IMGFLAG_DRAW_CALLBACK:0;
|
MP_IMGFLAG_DRAW_CALLBACK:0;
|
||||||
else
|
else
|
||||||
@ -419,17 +428,9 @@ static void get_buffer(struct AVCodecContext *avctx, int width, int height, int
|
|||||||
avctx->draw_horiz_band= draw_slice;
|
avctx->draw_horiz_band= draw_slice;
|
||||||
} else
|
} else
|
||||||
avctx->draw_horiz_band= NULL;
|
avctx->draw_horiz_band= NULL;
|
||||||
avctx->dr_buffer[0]= mpi->planes[0];
|
pic->data[0]= mpi->planes[0];
|
||||||
avctx->dr_buffer[1]= mpi->planes[1];
|
pic->data[1]= mpi->planes[1];
|
||||||
avctx->dr_buffer[2]= mpi->planes[2];
|
pic->data[2]= mpi->planes[2];
|
||||||
|
|
||||||
if(avctx->dr_stride && avctx->dr_stride !=mpi->stride[0]){
|
|
||||||
mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Error: stride changed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(avctx->dr_uvstride && avctx->dr_uvstride !=mpi->stride[1]){
|
|
||||||
mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Error: uvstride changed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(mpi->width >= ((width +align)&(~align)));
|
assert(mpi->width >= ((width +align)&(~align)));
|
||||||
assert(mpi->height >= ((height+align)&(~align)));
|
assert(mpi->height >= ((height+align)&(~align)));
|
||||||
@ -446,11 +447,14 @@ static void get_buffer(struct AVCodecContext *avctx, int width, int height, int
|
|||||||
assert(mpi->planes[2] > mpi->planes[1] || mpi->planes[2] + c_size <= mpi->planes[1]);
|
assert(mpi->planes[2] > mpi->planes[1] || mpi->planes[2] + c_size <= mpi->planes[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
avctx->dr_stride = mpi->stride[0];
|
/* Note, some (many) codecs in libavcodec must have stride1==stride2 && no changes between frames
|
||||||
avctx->dr_uvstride = mpi->stride[1];
|
* lavc will check that and die with an error message, if its not true
|
||||||
|
*/
|
||||||
|
pic->linesize[0]= mpi->stride[0];
|
||||||
|
pic->linesize[1]= mpi->stride[1];
|
||||||
|
pic->linesize[2]= mpi->stride[2];
|
||||||
|
|
||||||
avctx->dr_opaque_frame = mpi;
|
pic->opaque = mpi;
|
||||||
avctx->dr_ip_buffer_count=2; //FIXME
|
|
||||||
//printf("%X\n", (int)mpi->planes[0]);
|
//printf("%X\n", (int)mpi->planes[0]);
|
||||||
#if 0
|
#if 0
|
||||||
if(mpi->flags&MP_IMGFLAG_DIRECT)
|
if(mpi->flags&MP_IMGFLAG_DIRECT)
|
||||||
@ -460,9 +464,30 @@ else if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)
|
|||||||
else
|
else
|
||||||
printf(".");
|
printf(".");
|
||||||
#endif
|
#endif
|
||||||
#if LIBAVCODEC_BUILD >= 4632
|
if(pic->reference){
|
||||||
|
pic->age= ctx->ip_age[0];
|
||||||
|
|
||||||
|
ctx->ip_age[0]= ctx->ip_age[1]+1;
|
||||||
|
ctx->ip_age[1]= 1;
|
||||||
|
ctx->b_age++;
|
||||||
|
}else{
|
||||||
|
pic->age= ctx->b_age;
|
||||||
|
|
||||||
|
ctx->ip_age[0]++;
|
||||||
|
ctx->ip_age[1]++;
|
||||||
|
ctx->b_age=1;
|
||||||
|
}
|
||||||
|
//pic->age= 256*256*256*64;
|
||||||
|
//printf("G%X %X\n", pic->linesize[0], pic->data[0]);
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
static void release_buffer(struct AVCodecContext *avctx, AVVideoFrame *pic){
|
||||||
|
int i;
|
||||||
|
for(i=0; i<4; i++){
|
||||||
|
pic->data[i]= NULL;
|
||||||
|
}
|
||||||
|
//printf("R%X %X\n", pic->linesize[0], pic->data[0]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -479,8 +504,8 @@ typedef struct dp_hdr_s {
|
|||||||
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
||||||
int got_picture=0;
|
int got_picture=0;
|
||||||
int ret;
|
int ret;
|
||||||
AVPicture lavc_picture;
|
|
||||||
vd_ffmpeg_ctx *ctx = sh->context;
|
vd_ffmpeg_ctx *ctx = sh->context;
|
||||||
|
AVVideoFrame *pic= ctx->pic;
|
||||||
AVCodecContext *avctx = ctx->avctx;
|
AVCodecContext *avctx = ctx->avctx;
|
||||||
mp_image_t* mpi=NULL;
|
mp_image_t* mpi=NULL;
|
||||||
int dr1= ctx->do_dr1;
|
int dr1= ctx->do_dr1;
|
||||||
@ -524,7 +549,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = avcodec_decode_video(avctx, &lavc_picture,
|
ret = avcodec_decode_video(avctx, pic,
|
||||||
&got_picture, data, len);
|
&got_picture, data, len);
|
||||||
if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n");
|
if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n");
|
||||||
|
|
||||||
@ -535,6 +560,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|||||||
static long long int all_len=0;
|
static long long int all_len=0;
|
||||||
static int frame_number=0;
|
static int frame_number=0;
|
||||||
static double all_frametime=0.0;
|
static double all_frametime=0.0;
|
||||||
|
AVVideoFrame *pic= avctx->coded_picture;
|
||||||
|
|
||||||
if(!fvstats) {
|
if(!fvstats) {
|
||||||
time_t today2;
|
time_t today2;
|
||||||
@ -554,12 +580,12 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|||||||
|
|
||||||
all_len+=len;
|
all_len+=len;
|
||||||
all_frametime+=sh->frametime;
|
all_frametime+=sh->frametime;
|
||||||
fprintf(fvstats, "frame= %5d q= %2d f_size= %6d s_size= %8.0fkB ",
|
fprintf(fvstats, "frame= %5d q= %f2.0d f_size= %6d s_size= %8.0fkB ",
|
||||||
++frame_number, avctx->quality, len, (double)all_len/1024);
|
++frame_number, pic->quality, len, (double)all_len/1024);
|
||||||
fprintf(fvstats, "time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
|
fprintf(fvstats, "time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
|
||||||
all_frametime, (double)(len*8)/sh->frametime/1000.0,
|
all_frametime, (double)(len*8)/sh->frametime/1000.0,
|
||||||
(double)(all_len*8)/all_frametime/1000.0);
|
(double)(all_len*8)/all_frametime/1000.0);
|
||||||
switch(avctx->pict_type){
|
switch(pic->pict_type){
|
||||||
case I_TYPE:
|
case I_TYPE:
|
||||||
fprintf(fvstats, "type= I\n");
|
fprintf(fvstats, "type= I\n");
|
||||||
break;
|
break;
|
||||||
@ -582,8 +608,8 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|||||||
if(init_vo(sh)<0) return NULL;
|
if(init_vo(sh)<0) return NULL;
|
||||||
|
|
||||||
#if LIBAVCODEC_BUILD > 4615
|
#if LIBAVCODEC_BUILD > 4615
|
||||||
if(dr1 && avctx->dr_opaque_frame){
|
if(dr1 && pic->opaque){
|
||||||
mpi= (mp_image_t*)avctx->dr_opaque_frame;
|
mpi= (mp_image_t*)pic->opaque;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -592,9 +618,9 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|||||||
mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
|
mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
|
||||||
avctx->width, avctx->height);
|
avctx->width, avctx->height);
|
||||||
if(!mpi) return NULL;
|
if(!mpi) return NULL;
|
||||||
yuv422ptoyuy2(lavc_picture.data[0],lavc_picture.data[1],lavc_picture.data[2],
|
yuv422ptoyuy2(pic->data[0],pic->data[1],pic->data[2],
|
||||||
mpi->planes[0],avctx->width,avctx->height,
|
mpi->planes[0],avctx->width,avctx->height,
|
||||||
lavc_picture.linesize[0],lavc_picture.linesize[1],mpi->stride[0]);
|
pic->linesize[0],pic->linesize[1],mpi->stride[0]);
|
||||||
return mpi;
|
return mpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,12 +633,12 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!dr1){
|
if(!dr1){
|
||||||
mpi->planes[0]=lavc_picture.data[0];
|
mpi->planes[0]=pic->data[0];
|
||||||
mpi->planes[1]=lavc_picture.data[1];
|
mpi->planes[1]=pic->data[1];
|
||||||
mpi->planes[2]=lavc_picture.data[2];
|
mpi->planes[2]=pic->data[2];
|
||||||
mpi->stride[0]=lavc_picture.linesize[0];
|
mpi->stride[0]=pic->linesize[0];
|
||||||
mpi->stride[1]=lavc_picture.linesize[1];
|
mpi->stride[1]=pic->linesize[1];
|
||||||
mpi->stride[2]=lavc_picture.linesize[2];
|
mpi->stride[2]=pic->linesize[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(avctx->pix_fmt==PIX_FMT_YUV422P && mpi->chroma_y_shift==1){
|
if(avctx->pix_fmt==PIX_FMT_YUV422P && mpi->chroma_y_shift==1){
|
||||||
@ -622,21 +648,11 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* to comfirm with newer lavc style */
|
/* to comfirm with newer lavc style */
|
||||||
#if LIBAVCODEC_BUILD >= 4633
|
#if LIBAVCODEC_BUILD >= 4641
|
||||||
mpi->qscale=avctx->display_qscale_table;
|
mpi->qscale =pic->qscale_table;
|
||||||
mpi->qstride=avctx->qstride;
|
mpi->qstride=pic->qstride;
|
||||||
|
mpi->pict_type=pic->pict_type;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
|
||||||
static int last_non_b_type= 0;
|
|
||||||
|
|
||||||
if(avctx->pict_type == B_TYPE)
|
|
||||||
mpi->pict_type= B_TYPE;
|
|
||||||
else{
|
|
||||||
mpi->pict_type= last_non_b_type;
|
|
||||||
last_non_b_type= avctx->pict_type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mpi;
|
return mpi;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ extern void mencoder_write_chunk(aviwrite_stream_t *s,int len,unsigned int flags
|
|||||||
#include "libavcodec/avcodec.h"
|
#include "libavcodec/avcodec.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LIBAVCODEC_BUILD < 4601
|
#if LIBAVCODEC_BUILD < 4641
|
||||||
#error your version of libavcodec is too old, get a newer one, and dont send a bugreport, THIS IS NO BUG
|
#error your version of libavcodec is too old, get a newer one, and dont send a bugreport, THIS IS NO BUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -181,6 +181,7 @@ struct config lavcopts_conf[]={
|
|||||||
struct vf_priv_s {
|
struct vf_priv_s {
|
||||||
aviwrite_stream_t* mux;
|
aviwrite_stream_t* mux;
|
||||||
AVCodecContext *context;
|
AVCodecContext *context;
|
||||||
|
AVVideoFrame *pic;
|
||||||
AVCodec *codec;
|
AVCodec *codec;
|
||||||
FILE *stats_file;
|
FILE *stats_file;
|
||||||
};
|
};
|
||||||
@ -406,7 +407,7 @@ static int config(struct vf_instance_s* vf,
|
|||||||
{
|
{
|
||||||
printf("Using constant qscale = %d (VBR)\n", lavc_param_vqscale);
|
printf("Using constant qscale = %d (VBR)\n", lavc_param_vqscale);
|
||||||
lavc_venc_context->flags |= CODEC_FLAG_QSCALE;
|
lavc_venc_context->flags |= CODEC_FLAG_QSCALE;
|
||||||
lavc_venc_context->quality = lavc_param_vqscale;
|
vf->priv->pic->quality = lavc_param_vqscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (avcodec_open(lavc_venc_context, vf->priv->codec) != 0) {
|
if (avcodec_open(lavc_venc_context, vf->priv->codec) != 0) {
|
||||||
@ -459,19 +460,19 @@ static int query_format(struct vf_instance_s* vf, unsigned int fmt){
|
|||||||
|
|
||||||
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
||||||
int out_size;
|
int out_size;
|
||||||
AVPicture lavc_venc_picture;
|
AVVideoFrame *pic= vf->priv->pic;
|
||||||
|
|
||||||
lavc_venc_picture.data[0]=mpi->planes[0];
|
pic->data[0]=mpi->planes[0];
|
||||||
lavc_venc_picture.data[1]=mpi->planes[1];
|
pic->data[1]=mpi->planes[1];
|
||||||
lavc_venc_picture.data[2]=mpi->planes[2];
|
pic->data[2]=mpi->planes[2];
|
||||||
lavc_venc_picture.linesize[0]=mpi->stride[0];
|
pic->linesize[0]=mpi->stride[0];
|
||||||
lavc_venc_picture.linesize[1]=mpi->stride[1];
|
pic->linesize[1]=mpi->stride[1];
|
||||||
lavc_venc_picture.linesize[2]=mpi->stride[2];
|
pic->linesize[2]=mpi->stride[2];
|
||||||
|
|
||||||
out_size = avcodec_encode_video(lavc_venc_context, mux_v->buffer, mux_v->buffer_size,
|
out_size = avcodec_encode_video(lavc_venc_context, mux_v->buffer, mux_v->buffer_size,
|
||||||
&lavc_venc_picture);
|
pic);
|
||||||
|
|
||||||
mencoder_write_chunk(mux_v,out_size,lavc_venc_context->key_frame?0x10:0);
|
mencoder_write_chunk(mux_v,out_size,lavc_venc_context->coded_picture->key_frame?0x10:0);
|
||||||
|
|
||||||
#if LIBAVCODEC_BUILD >= 4620
|
#if LIBAVCODEC_BUILD >= 4620
|
||||||
/* store stats if there are any */
|
/* store stats if there are any */
|
||||||
@ -574,6 +575,7 @@ static int vf_open(vf_instance_t *vf, char* args){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vf->priv->pic = avcodec_alloc_picture();
|
||||||
#if LIBAVCODEC_BUILD >= 4624
|
#if LIBAVCODEC_BUILD >= 4624
|
||||||
vf->priv->context = avcodec_alloc_context();
|
vf->priv->context = avcodec_alloc_context();
|
||||||
#else
|
#else
|
||||||
|
@ -21,12 +21,17 @@
|
|||||||
#include "libavcodec/avcodec.h"
|
#include "libavcodec/avcodec.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LIBAVCODEC_BUILD < 4641
|
||||||
|
#error your version of libavcodec is too old, get a newer one, and dont send a bugreport, THIS IS NO BUG
|
||||||
|
#endif
|
||||||
|
|
||||||
extern int avcodec_inited;
|
extern int avcodec_inited;
|
||||||
|
|
||||||
struct vf_priv_s {
|
struct vf_priv_s {
|
||||||
unsigned char* outbuf;
|
unsigned char* outbuf;
|
||||||
int outbuf_size;
|
int outbuf_size;
|
||||||
AVCodecContext* context;
|
AVCodecContext* context;
|
||||||
|
AVVideoFrame* pic;
|
||||||
AVCodec* codec;
|
AVCodec* codec;
|
||||||
vo_mpegpes_t pes;
|
vo_mpegpes_t pes;
|
||||||
};
|
};
|
||||||
@ -80,17 +85,17 @@ static int config(struct vf_instance_s* vf,
|
|||||||
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
||||||
mp_image_t* dmpi;
|
mp_image_t* dmpi;
|
||||||
int out_size;
|
int out_size;
|
||||||
AVPicture lavc_venc_picture;
|
AVVideoFrame *pic= vf->priv->pic;
|
||||||
|
|
||||||
lavc_venc_picture.data[0]=mpi->planes[0];
|
pic->data[0]=mpi->planes[0];
|
||||||
lavc_venc_picture.data[1]=mpi->planes[1];
|
pic->data[1]=mpi->planes[1];
|
||||||
lavc_venc_picture.data[2]=mpi->planes[2];
|
pic->data[2]=mpi->planes[2];
|
||||||
lavc_venc_picture.linesize[0]=mpi->stride[0];
|
pic->linesize[0]=mpi->stride[0];
|
||||||
lavc_venc_picture.linesize[1]=mpi->stride[1];
|
pic->linesize[1]=mpi->stride[1];
|
||||||
lavc_venc_picture.linesize[2]=mpi->stride[2];
|
pic->linesize[2]=mpi->stride[2];
|
||||||
|
|
||||||
out_size = avcodec_encode_video(&lavc_venc_context,
|
out_size = avcodec_encode_video(&lavc_venc_context,
|
||||||
vf->priv->outbuf, vf->priv->outbuf_size, &lavc_venc_picture);
|
vf->priv->outbuf, vf->priv->outbuf_size, pic);
|
||||||
|
|
||||||
if(out_size<=0) return 1;
|
if(out_size<=0) return 1;
|
||||||
|
|
||||||
@ -143,6 +148,7 @@ static int open(vf_instance_t *vf, char* args){
|
|||||||
}
|
}
|
||||||
|
|
||||||
vf->priv->context=avcodec_alloc_context();
|
vf->priv->context=avcodec_alloc_context();
|
||||||
|
vf->priv->pic=avcodec_alloc_picture();
|
||||||
|
|
||||||
// TODO: parse args ->
|
// TODO: parse args ->
|
||||||
if(args) sscanf(args, "%d:%f", &p_quality, &p_fps);
|
if(args) sscanf(args, "%d:%f", &p_quality, &p_fps);
|
||||||
@ -150,7 +156,11 @@ static int open(vf_instance_t *vf, char* args){
|
|||||||
if(p_quality<32){
|
if(p_quality<32){
|
||||||
// fixed qscale
|
// fixed qscale
|
||||||
lavc_venc_context.flags = CODEC_FLAG_QSCALE;
|
lavc_venc_context.flags = CODEC_FLAG_QSCALE;
|
||||||
|
#if LIBAVCODEC_BUILD >= 4641
|
||||||
|
vf->priv->pic->quality = (p_quality<1) ? 1 : p_quality;
|
||||||
|
#else
|
||||||
lavc_venc_context.quality = (p_quality<1) ? 1 : p_quality;
|
lavc_venc_context.quality = (p_quality<1) ? 1 : p_quality;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
// fixed bitrate (in kbits)
|
// fixed bitrate (in kbits)
|
||||||
lavc_venc_context.bit_rate = 1000*p_quality;
|
lavc_venc_context.bit_rate = 1000*p_quality;
|
||||||
|
Loading…
Reference in New Issue
Block a user