comparison libmpcodecs/vf_lavc.c @ 8339:ff0bddb59e81

support for lavc build 4641 no #ifdefs this time as the difference is big and iam lazy, feel free to add #ifdef LIBAVCODEC_BUILD ...
author michael
date Wed, 04 Dec 2002 10:49:03 +0000
parents e4f87bbf682c
children a17ce1496ca6
comparison
equal deleted inserted replaced
8338:61d7bc41a41f 8339:ff0bddb59e81
19 #include <ffmpeg/avcodec.h> 19 #include <ffmpeg/avcodec.h>
20 #else 20 #else
21 #include "libavcodec/avcodec.h" 21 #include "libavcodec/avcodec.h"
22 #endif 22 #endif
23 23
24 #if LIBAVCODEC_BUILD < 4641
25 #error your version of libavcodec is too old, get a newer one, and dont send a bugreport, THIS IS NO BUG
26 #endif
27
24 extern int avcodec_inited; 28 extern int avcodec_inited;
25 29
26 struct vf_priv_s { 30 struct vf_priv_s {
27 unsigned char* outbuf; 31 unsigned char* outbuf;
28 int outbuf_size; 32 int outbuf_size;
29 AVCodecContext* context; 33 AVCodecContext* context;
34 AVVideoFrame* pic;
30 AVCodec* codec; 35 AVCodec* codec;
31 vo_mpegpes_t pes; 36 vo_mpegpes_t pes;
32 }; 37 };
33 38
34 #define lavc_venc_context (*vf->priv->context) 39 #define lavc_venc_context (*vf->priv->context)
78 } 83 }
79 84
80 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ 85 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
81 mp_image_t* dmpi; 86 mp_image_t* dmpi;
82 int out_size; 87 int out_size;
83 AVPicture lavc_venc_picture; 88 AVVideoFrame *pic= vf->priv->pic;
84 89
85 lavc_venc_picture.data[0]=mpi->planes[0]; 90 pic->data[0]=mpi->planes[0];
86 lavc_venc_picture.data[1]=mpi->planes[1]; 91 pic->data[1]=mpi->planes[1];
87 lavc_venc_picture.data[2]=mpi->planes[2]; 92 pic->data[2]=mpi->planes[2];
88 lavc_venc_picture.linesize[0]=mpi->stride[0]; 93 pic->linesize[0]=mpi->stride[0];
89 lavc_venc_picture.linesize[1]=mpi->stride[1]; 94 pic->linesize[1]=mpi->stride[1];
90 lavc_venc_picture.linesize[2]=mpi->stride[2]; 95 pic->linesize[2]=mpi->stride[2];
91 96
92 out_size = avcodec_encode_video(&lavc_venc_context, 97 out_size = avcodec_encode_video(&lavc_venc_context,
93 vf->priv->outbuf, vf->priv->outbuf_size, &lavc_venc_picture); 98 vf->priv->outbuf, vf->priv->outbuf_size, pic);
94 99
95 if(out_size<=0) return 1; 100 if(out_size<=0) return 1;
96 101
97 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES, 102 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES,
98 MP_IMGTYPE_EXPORT, 0, 103 MP_IMGTYPE_EXPORT, 0,
141 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, "mpeg1video"); 146 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, "mpeg1video");
142 return 0; 147 return 0;
143 } 148 }
144 149
145 vf->priv->context=avcodec_alloc_context(); 150 vf->priv->context=avcodec_alloc_context();
151 vf->priv->pic=avcodec_alloc_picture();
146 152
147 // TODO: parse args -> 153 // TODO: parse args ->
148 if(args) sscanf(args, "%d:%f", &p_quality, &p_fps); 154 if(args) sscanf(args, "%d:%f", &p_quality, &p_fps);
149 155
150 if(p_quality<32){ 156 if(p_quality<32){
151 // fixed qscale 157 // fixed qscale
152 lavc_venc_context.flags = CODEC_FLAG_QSCALE; 158 lavc_venc_context.flags = CODEC_FLAG_QSCALE;
159 #if LIBAVCODEC_BUILD >= 4641
160 vf->priv->pic->quality = (p_quality<1) ? 1 : p_quality;
161 #else
153 lavc_venc_context.quality = (p_quality<1) ? 1 : p_quality; 162 lavc_venc_context.quality = (p_quality<1) ? 1 : p_quality;
163 #endif
154 } else { 164 } else {
155 // fixed bitrate (in kbits) 165 // fixed bitrate (in kbits)
156 lavc_venc_context.bit_rate = 1000*p_quality; 166 lavc_venc_context.bit_rate = 1000*p_quality;
157 } 167 }
158 lavc_venc_context.frame_rate = (p_fps<1.0) ? 0 : (p_fps * FRAME_RATE_BASE); 168 lavc_venc_context.frame_rate = (p_fps<1.0) ? 0 : (p_fps * FRAME_RATE_BASE);