Mercurial > mplayer.hg
comparison libmpcodecs/ve_lavc.c @ 6673:d6adae1af0e3
#ifdef'ed divx4 2pass code - idea by Diego
author | arpi |
---|---|
date | Mon, 08 Jul 2002 21:34:24 +0000 |
parents | b2f659932839 |
children | c72555c4bc63 |
comparison
equal
deleted
inserted
replaced
6672:535b63237c14 | 6673:d6adae1af0e3 |
---|---|
18 | 18 |
19 #include "img_format.h" | 19 #include "img_format.h" |
20 #include "mp_image.h" | 20 #include "mp_image.h" |
21 #include "vf.h" | 21 #include "vf.h" |
22 | 22 |
23 #ifdef HAVE_DIVX4ENCORE | |
23 #include "divx4_vbr.h" | 24 #include "divx4_vbr.h" |
25 extern char* passtmpfile; | |
26 #endif | |
24 | 27 |
25 extern int pass; | 28 extern int pass; |
26 extern char* passtmpfile; | |
27 | 29 |
28 //===========================================================================// | 30 //===========================================================================// |
29 | 31 |
30 #ifdef USE_LIBAVCODEC_SO | 32 #ifdef USE_LIBAVCODEC_SO |
31 #include <libffmpeg/avcodec.h> | 33 #include <libffmpeg/avcodec.h> |
183 if(lavc_param_gray) lavc_venc_context.flags|= CODEC_FLAG_GRAY; | 185 if(lavc_param_gray) lavc_venc_context.flags|= CODEC_FLAG_GRAY; |
184 #endif | 186 #endif |
185 | 187 |
186 | 188 |
187 /* lavc internal 2pass bitrate control */ | 189 /* lavc internal 2pass bitrate control */ |
188 if(lavc_param_vpass==1) | 190 #ifdef HAVE_DIVX4ENCORE |
189 lavc_venc_context.flags|= CODEC_FLAG_PASS1; | 191 switch(lavc_param_vpass){ |
190 else if(lavc_param_vpass==2) | 192 #else |
191 lavc_venc_context.flags|= CODEC_FLAG_PASS2; | 193 switch(lavc_param_vpass?lavc_param_vpass:pass){ |
194 #endif | |
195 case 1: lavc_venc_context.flags|= CODEC_FLAG_PASS1; break; | |
196 case 2: lavc_venc_context.flags|= CODEC_FLAG_PASS2; break; | |
197 } | |
192 | 198 |
193 #ifdef ME_ZERO | 199 #ifdef ME_ZERO |
194 // workaround Juanjo's stupid incompatible change: | 200 // workaround Juanjo's stupid incompatible change: |
195 motion_estimation_method = lavc_param_vme; | 201 motion_estimation_method = lavc_param_vme; |
196 #else | 202 #else |
203 printf("Using constant qscale = %d (VBR)\n", lavc_param_vqscale); | 209 printf("Using constant qscale = %d (VBR)\n", lavc_param_vqscale); |
204 lavc_venc_context.flags |= CODEC_FLAG_QSCALE; | 210 lavc_venc_context.flags |= CODEC_FLAG_QSCALE; |
205 lavc_venc_context.quality = lavc_param_vqscale; | 211 lavc_venc_context.quality = lavc_param_vqscale; |
206 } | 212 } |
207 | 213 |
214 #ifdef HAVE_DIVX4ENCORE | |
208 switch(pass){ | 215 switch(pass){ |
209 case 1: | 216 case 1: |
210 if (VbrControl_init_2pass_vbr_analysis(passtmpfile, 5) == -1){ | 217 if (VbrControl_init_2pass_vbr_analysis(passtmpfile, 5) == -1){ |
211 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); | 218 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); |
212 pass=0; | 219 pass=0; |
222 pass=0; | 229 pass=0; |
223 } else | 230 } else |
224 lavc_venc_context.flags|=CODEC_FLAG_QSCALE|CODEC_FLAG_TYPE; // VBR | 231 lavc_venc_context.flags|=CODEC_FLAG_QSCALE|CODEC_FLAG_TYPE; // VBR |
225 break; | 232 break; |
226 } | 233 } |
234 #endif | |
227 | 235 |
228 if (avcodec_open(&lavc_venc_context, vf->priv->codec) != 0) { | 236 if (avcodec_open(&lavc_venc_context, vf->priv->codec) != 0) { |
229 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); | 237 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); |
230 return 0; | 238 return 0; |
231 } | 239 } |
262 lavc_venc_picture.data[2]=mpi->planes[2]; | 270 lavc_venc_picture.data[2]=mpi->planes[2]; |
263 lavc_venc_picture.linesize[0]=mpi->stride[0]; | 271 lavc_venc_picture.linesize[0]=mpi->stride[0]; |
264 lavc_venc_picture.linesize[1]=mpi->stride[1]; | 272 lavc_venc_picture.linesize[1]=mpi->stride[1]; |
265 lavc_venc_picture.linesize[2]=mpi->stride[2]; | 273 lavc_venc_picture.linesize[2]=mpi->stride[2]; |
266 | 274 |
275 #ifdef HAVE_DIVX4ENCORE | |
267 if(pass==2){ // handle 2-pass: | 276 if(pass==2){ // handle 2-pass: |
268 lavc_venc_context.flags|=CODEC_FLAG_QSCALE; // enable VBR | 277 lavc_venc_context.flags|=CODEC_FLAG_QSCALE; // enable VBR |
269 lavc_venc_context.quality=VbrControl_get_quant(); | 278 lavc_venc_context.quality=VbrControl_get_quant(); |
270 lavc_venc_context.key_frame=VbrControl_get_intra(); | 279 lavc_venc_context.key_frame=VbrControl_get_intra(); |
271 lavc_venc_context.gop_size=0x3fffffff; | 280 lavc_venc_context.gop_size=0x3fffffff; |
272 out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, | 281 out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, |
273 &lavc_venc_picture); | 282 &lavc_venc_picture); |
274 VbrControl_update_2pass_vbr_encoding(lavc_venc_context.mv_bits, | 283 VbrControl_update_2pass_vbr_encoding(lavc_venc_context.mv_bits, |
275 lavc_venc_context.i_tex_bits+lavc_venc_context.p_tex_bits, | 284 lavc_venc_context.i_tex_bits+lavc_venc_context.p_tex_bits, |
276 8*out_size); | 285 8*out_size); |
277 } else { | 286 } else |
287 #endif | |
288 { | |
278 out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, | 289 out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, |
279 &lavc_venc_picture); | 290 &lavc_venc_picture); |
280 | 291 #ifdef HAVE_DIVX4ENCORE |
281 if(pass==1){ | 292 if(pass==1){ |
282 VbrControl_update_2pass_vbr_analysis(lavc_venc_context.key_frame, | 293 VbrControl_update_2pass_vbr_analysis(lavc_venc_context.key_frame, |
283 lavc_venc_context.mv_bits, | 294 lavc_venc_context.mv_bits, |
284 lavc_venc_context.i_tex_bits+lavc_venc_context.p_tex_bits, | 295 lavc_venc_context.i_tex_bits+lavc_venc_context.p_tex_bits, |
285 8*out_size, lavc_venc_context.quality); | 296 8*out_size, lavc_venc_context.quality); |
286 } | 297 } |
287 | 298 #endif |
288 } | 299 } |
289 | 300 |
290 mencoder_write_chunk(mux_v,out_size,lavc_venc_context.key_frame?0x10:0); | 301 mencoder_write_chunk(mux_v,out_size,lavc_venc_context.key_frame?0x10:0); |
291 } | 302 } |
292 | 303 |
367 } | 378 } |
368 | 379 |
369 vf_info_t ve_info_lavc = { | 380 vf_info_t ve_info_lavc = { |
370 "libavcodec encoder", | 381 "libavcodec encoder", |
371 "lavc", | 382 "lavc", |
372 "A'rpi and Alex", | 383 "A'rpi, Alex, Michael", |
373 "for internal use by mencoder", | 384 "for internal use by mencoder", |
374 vf_open | 385 vf_open |
375 }; | 386 }; |
376 | 387 |
377 //===========================================================================// | 388 //===========================================================================// |