[MPlayer-dev-eng] fixing mencoder

D Richard Felker III dalias at aerifal.cx
Wed Apr 10 19:31:09 CEST 2002


this morning i committed a patch that provides a temporary fix to
mencoder, which has been broken by the new video filter system. i'd
like to get it fixed properly, which seems to involve moving the
encoder initialization to mencoder vo's config function, but so far
this seems not to be working. i'm attaching a patch that's my work so
far on this. keep in mind that it is broken and will segfault; i'm
just looking for comments in what might be wrong (either details, or
reasons why my entire approach to the problem is bad). hopefully once
this is all done we can get rid of the old cropping/scaling code and
just use the new filters entirely.

rich

-------------- next part --------------
Index: mencoder.c
===================================================================
RCS file: /cvsroot/mplayer/main/mencoder.c,v
retrieving revision 1.112
diff -u -r1.112 mencoder.c
--- mencoder.c	10 Apr 2002 12:43:26 -0000	1.112
+++ mencoder.c	10 Apr 2002 17:33:12 -0000
@@ -59,6 +59,12 @@
 #include <lame/lame.h>
 #endif
 
+#ifdef HAVE_DIVX4ENCORE
+ENC_FRAME enc_frame;
+ENC_RESULT enc_result;
+void* enc_handle=NULL;
+#endif
+
 #ifdef USE_LIBAVCODEC
 #ifdef USE_LIBAVCODEC_SO
 #include <libffmpeg/avcodec.h>
@@ -429,6 +435,87 @@
   // we should do codec initialization here!
   printf("vo.config(%d x %d, %s) called!\n",width,height,vo_format_name(format));
   out_fmt=format;
+switch(out_video_codec){
+case VCODEC_COPY:
+case VCODEC_RAW:
+case VCODEC_RAWRGB:        
+case VCODEC_NULL:
+case VCODEC_FRAMENO:
+    break;
+case VCODEC_DIVX4:
+#ifndef HAVE_DIVX4ENCORE
+    printf("No support for Divx4 encore compiled in\n");
+    mencoder_exit(1,NULL);
+#else
+    // init divx4linux:
+    divx4_param.x_dim=width;
+    divx4_param.y_dim=height;
+    encore(NULL,ENC_OPT_INIT,&divx4_param,NULL);
+    enc_handle=divx4_param.handle;
+    switch(out_fmt){
+    case IMGFMT_YV12:	enc_frame.colorspace=ENC_CSP_YV12; break;
+    case IMGFMT_IYUV:
+    case IMGFMT_I420:	enc_frame.colorspace=ENC_CSP_I420; break;
+    case IMGFMT_YUY2:	enc_frame.colorspace=ENC_CSP_YUY2; break;
+    case IMGFMT_UYVY:	enc_frame.colorspace=ENC_CSP_UYVY; break;
+    case IMGFMT_RGB24:
+    case IMGFMT_BGR24:
+    	enc_frame.colorspace=ENC_CSP_RGB24; break;
+    default:
+	mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported picture format (%s)!\n",
+	    vo_format_name(out_fmt));
+	mencoder_exit(1,NULL);
+    }
+    break;
+#endif
+case VCODEC_LIBAVCODEC:
+#ifndef USE_LIBAVCODEC
+    printf("No support for FFmpeg's libavcodec compiled in\n");
+#else
+    lavc_venc_context.width = width;
+    lavc_venc_context.height = height;
+
+    if (avcodec_open(&lavc_venc_context, lavc_venc_codec) != 0)
+    {
+	printf(MSGTR_CantOpenCodec);
+	mencoder_exit(1,NULL);
+    }
+
+    if (lavc_venc_context.codec->encode == NULL)
+    {
+	printf("avcodec init failed (ctx->codec->encode == NULL)!\n");
+	mencoder_exit(1,NULL);
+    }
+
+    if (out_fmt != IMGFMT_YV12 && out_fmt != IMGFMT_I420 && out_fmt != IMGFMT_IYUV)
+    {
+        printf("Not supported image format! (%s)\n",
+    	    vo_format_name(out_fmt));
+	mencoder_exit(1,NULL);
+    }
+
+    memset(&lavc_venc_picture, 0, sizeof(lavc_venc_picture));
+    
+    {
+	int size = lavc_venc_context.width * lavc_venc_context.height;
+
+/* Y */	lavc_venc_picture.data[0] = vo_image_ptr;
+	if (out_fmt == IMGFMT_YV12)
+	{
+/* U */		lavc_venc_picture.data[2] = lavc_venc_picture.data[0] + size;
+/* V */		lavc_venc_picture.data[1] = lavc_venc_picture.data[2] + size/4;
+	}
+	else /* IMGFMT_I420 */
+	{
+/* U */		lavc_venc_picture.data[1] = lavc_venc_picture.data[0] + size;
+/* V */		lavc_venc_picture.data[2] = lavc_venc_picture.data[1] + size/4;
+	}
+	lavc_venc_picture.linesize[0] = lavc_venc_context.width;
+	lavc_venc_picture.linesize[1] = lavc_venc_context.width / 2;
+	lavc_venc_picture.linesize[2] = lavc_venc_context.width / 2;
+    }
+#endif
+}
   return 0; // OK!
 }
 
@@ -506,15 +593,9 @@
 aviwrite_t* muxer=NULL;
 aviwrite_stream_t* mux_a=NULL;
 aviwrite_stream_t* mux_v=NULL;
 FILE* muxer_f=NULL;
 int muxer_f_size=0;
 
-#ifdef HAVE_DIVX4ENCORE
-ENC_FRAME enc_frame;
-ENC_RESULT enc_result;
-void* enc_handle=NULL;
-#endif
-
 #ifdef HAVE_MP3LAME
 lame_global_flags *lame;
 #endif
@@ -673,11 +754,11 @@
 
 sh_video->vfilter=vf_open_filter(NULL,"vo",&video_out);
 // Dirty hack to fix mencoder until someone does all the new filter/vo stuff right :)
-if (out_video_codec == VCODEC_LIBAVCODEC || out_video_codec == VCODEC_DIVX4)
-{
-    sh_video->vfilter=vf_open_filter(sh_video->vfilter, "format", "yv12");
-    out_fmt = IMGFMT_YV12;
-}
+//if (out_video_codec == VCODEC_LIBAVCODEC || out_video_codec == VCODEC_DIVX4)
+//{
+//    sh_video->vfilter=vf_open_filter(sh_video->vfilter, "format", "yv12");
+//    out_fmt = IMGFMT_YV12;
+//}
 sh_video->vfilter=append_filters(sh_video->vfilter);
 
 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
@@ -1098,6 +1179,7 @@
 printf("Writing AVI header...\n");
 aviwrite_write_header(muxer,muxer_f);
 
+/* old location of out_fmt stuff */
 switch(mux_v->codec){
 case VCODEC_COPY:
 case VCODEC_RAW:
@@ -1112,30 +1194,11 @@
     printf("No support for Divx4 encore compiled in\n");
     mencoder_exit(1,NULL);
 #else
-    // init divx4linux:
-    divx4_param.x_dim=vo_w;
-    divx4_param.y_dim=vo_h;
     divx4_param.framerate=(float)mux_v->h.dwRate/mux_v->h.dwScale;
     if(!divx4_param.bitrate) divx4_param.bitrate=800000;
     else if(divx4_param.bitrate<=16000) divx4_param.bitrate*=1000;
     if(!divx4_param.quality) divx4_param.quality=5; // the quality of compression ( 1 - fastest, 5 - best )
     divx4_param.handle=NULL;
-    encore(NULL,ENC_OPT_INIT,&divx4_param,NULL);
-    enc_handle=divx4_param.handle;
-    switch(out_fmt){
-    case IMGFMT_YV12:	enc_frame.colorspace=ENC_CSP_YV12; break;
-    case IMGFMT_IYUV:
-    case IMGFMT_I420:	enc_frame.colorspace=ENC_CSP_I420; break;
-    case IMGFMT_YUY2:	enc_frame.colorspace=ENC_CSP_YUY2; break;
-    case IMGFMT_UYVY:	enc_frame.colorspace=ENC_CSP_UYVY; break;
-    case IMGFMT_RGB24:
-    case IMGFMT_BGR24:
-    	enc_frame.colorspace=ENC_CSP_RGB24; break;
-    default:
-	mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported picture format (%s)!\n",
-	    vo_format_name(out_fmt));
-	mencoder_exit(1,NULL);
-    }
     switch(pass){
     case 1:
 	if (VbrControl_init_2pass_vbr_analysis(passtmpfile, divx4_param.quality) == -1)
@@ -1173,24 +1236,7 @@
 	avcodec_inited=1;
     }
     
-#if 0
-    {
-	extern AVCodec *first_avcodec;
-	AVCodec *p = first_avcodec;
-	
-	lavc_venc_codec = NULL;
-	while (p)
-	{
-	    if (p->encode != NULL && strcmp(lavc_param_vcodec, p->name) == 0)
-		break;
-	    p = p->next;
-	}
-	lavc_venc_codec = p;
-    }
-#else
-    /* XXX: implement this in avcodec (i will send a patch to ffmpeglist) -- alex */
     lavc_venc_codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_vcodec);
-#endif
 
     if (!lavc_venc_codec)
     {
@@ -1200,11 +1246,6 @@
 
     memset(&lavc_venc_context, 0, sizeof(lavc_venc_context));
     
-//    lavc_venc_context.width = mux_v->bih->biWidth;
-//    lavc_venc_context.height = mux_v->bih->biHeight;
-    /* scaling only for YV12 (and lavc supports only YV12 ;) */
-    lavc_venc_context.width = vo_w;
-    lavc_venc_context.height = vo_h;
     if (lavc_param_vbitrate >= 0) /* != -1 */
 	lavc_venc_context.bit_rate = lavc_param_vbitrate*1000;
     else
@@ -1271,92 +1312,8 @@
 	}
 	break;
     }
-
-    if (avcodec_open(&lavc_venc_context, lavc_venc_codec) != 0)
-    {
-	printf(MSGTR_CantOpenCodec);
-	mencoder_exit(1,NULL);
-    }
-
-    if (lavc_venc_context.codec->encode == NULL)
-    {
-	printf("avcodec init failed (ctx->codec->encode == NULL)!\n");
-	mencoder_exit(1,NULL);
-    }
-
-#if 1
-    if (out_fmt != IMGFMT_YV12 && out_fmt != IMGFMT_I420 && out_fmt != IMGFMT_IYUV)
-    {
-        printf("Not supported image format! (%s)\n",
-    	    vo_format_name(out_fmt));
-	mencoder_exit(1,NULL);
-    }
-
-    memset(&lavc_venc_picture, 0, sizeof(lavc_venc_picture));
-    
-    {
-	int size = lavc_venc_context.width * lavc_venc_context.height;
-
-/* Y */	lavc_venc_picture.data[0] = vo_image_ptr;
-	if (out_fmt == IMGFMT_YV12)
-	{
-/* U */		lavc_venc_picture.data[2] = lavc_venc_picture.data[0] + size;
-/* V */		lavc_venc_picture.data[1] = lavc_venc_picture.data[2] + size/4;
-	}
-	else /* IMGFMT_I420 */
-	{
-/* U */		lavc_venc_picture.data[1] = lavc_venc_picture.data[0] + size;
-/* V */		lavc_venc_picture.data[2] = lavc_venc_picture.data[1] + size/4;
-	}
-	lavc_venc_picture.linesize[0] = lavc_venc_context.width;
-	lavc_venc_picture.linesize[1] = lavc_venc_context.width / 2;
-	lavc_venc_picture.linesize[2] = lavc_venc_context.width / 2;
-    }
-#else
-    switch(out_fmt)
-    {
-	case IMGFMT_YV12:
-	    lavc_venc_context.pix_fmt = PIX_FMT_YUV420P;
-	    break;
-#if 0 /* it's faulting :( -- libavcodec's bug! -- alex */
-	case IMGFMT_YUY2: /* or UYVY */
-	    lavc_venc_context.pix_fmt = PIX_FMT_YUV422;
-	    break;
-	case IMGFMT_BGR24:
-	    lavc_venc_context.pix_fmt = PIX_FMT_BGR24;
-	    break;
-	case IMGFMT_RGB24:
-	    lavc_venc_context.pix_fmt = PIX_FMT_RGB24;
-	    break;
-#endif
-	default:
-	    printf("Not supported image format! (%s)\n",
-		vo_format_name(out_fmt));
-	    mencoder_exit(1,NULL);
-    }
-
-    printf("Using picture format: %s\n", vo_format_name(out_fmt));
-
-    memset(&lavc_venc_picture, 0, sizeof(lavc_venc_picture));
-    
-    printf("ahh: avpict_getsize=%d, vo_image_ptr=%d\n", avpicture_get_size(lavc_venc_context.pix_fmt,
-	lavc_venc_context.width, lavc_venc_context.height),
-	vo_h*vo_w*3/2);
-    
-    avpicture_fill(&lavc_venc_picture, vo_image_ptr,
-	lavc_venc_context.pix_fmt, lavc_venc_context.width,
-	lavc_venc_context.height);
-
-    {
-	char buf[1024];
-	
-	avcodec_string((char *)&buf[0], 1023, &lavc_venc_context, 1);
-	printf("%s\n", buf);
-    }
-#endif
-
 #endif
 }
 if(sh_audio)
 switch(mux_a->codec){
 #ifdef HAVE_MP3LAME


More information about the MPlayer-dev-eng mailing list