[Mplayer-cvslog] CVS: main mencoder.c,1.62,1.63

Alex Beregszaszi alex at mplayer.dev.hu
Sat Jan 26 20:52:29 CET 2002


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv2254

Modified Files:
	mencoder.c 
Log Message:
lavc audio encode (needs to be fixed) and better fourcc handling for lavc

Index: mencoder.c
===================================================================
RCS file: /cvsroot/mplayer/main/mencoder.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- mencoder.c	26 Jan 2002 16:32:06 -0000	1.62
+++ mencoder.c	26 Jan 2002 19:52:26 -0000	1.63
@@ -1,4 +1,3 @@
-
 #define VCODEC_COPY 0
 #define VCODEC_FRAMENO 1
 #define VCODEC_DIVX4 2
@@ -9,6 +8,7 @@
 #define ACODEC_COPY 0
 #define ACODEC_PCM 1
 #define ACODEC_VBRMP3 2
+#define ACODEC_LIBAVCODEC 3
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -61,16 +61,27 @@
 #else
 #include "libavcodec/avcodec.h"
 #endif
+extern int avcodec_inited;
+
+/* for video encoder */
 static AVCodec *lavc_venc_codec=NULL;
 static AVCodecContext lavc_venc_context;
 static AVPicture lavc_venc_picture;
-extern int avcodec_inited;
-
+/* video options */
 char *lavc_param_vcodec = NULL;
 int lavc_param_vbitrate = -1;
 int lavc_param_vhq = 0; /* default is realtime encoding */
 int lavc_param_vme = 3;
 int lavc_param_keyint = -1;
+
+/* for audio encoder */
+static AVCodec *lavc_aenc_codec=NULL;
+static AVCodecContext lavc_aenc_context;
+/* audio options */
+char *lavc_param_acodec = NULL;
+int lavc_param_abitrate = -1;
+int lavc_param_samplerate = -1;
+int lavc_param_channels = -1;
 #endif
 
 #ifdef HAVE_LIBCSS
@@ -203,7 +214,7 @@
 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h, int x0,int y0){
   int y;
 //  printf("draw_slice %dx%d %d;%d\n",w,h,x0,y0);
-  if(scale_srcW)
+  if(scale_srcW || scale_srcH)
   {
       uint8_t* dstPtr[3]= {
       		vo_image, 
@@ -234,12 +245,14 @@
       memcpy(d,s,w);
   }
   } // !swscaler
+  return(0);
 }
 
 static uint32_t draw_frame(uint8_t *src[]){
   // printf("This function shouldn't be called - report bug!\n");
   // later: add YUY2->YV12 conversion here!
   vo_image_ptr=src[0];
+  return(0);
 }
 
 vo_functions_t video_out;
@@ -613,7 +626,6 @@
 
 switch(mux_v->codec){
 case VCODEC_COPY:
-    printf("sh_video->bih: %x\n", sh_video->bih);
     if (sh_video->bih)
 	mux_v->bih=sh_video->bih;
     else
@@ -632,7 +644,6 @@
 	mux_v->bih->biBitCount, mux_v->bih->biCompression);
     break;
 case VCODEC_RAW:
-    printf("sh_video->bih: %x\n", sh_video->bih);
     if (sh_video->bih)
 	mux_v->bih=sh_video->bih;
     else
@@ -702,11 +713,39 @@
     mux_v->bih->biBitCount=24;
     mux_v->bih->biCompression=mmioFOURCC(lavc_param_vcodec[0],
 	lavc_param_vcodec[1], lavc_param_vcodec[2], lavc_param_vcodec[3]); /* FIXME!!! */
+    if (lavc_param_vcodec)
+    {
+        const char *vcodec = lavc_param_vcodec;
+        if (!strcasecmp(vcodec, "mpeg1video"))
+        {
+	    mux_v->bih->biCompression = mmioFOURCC('m', 'p', 'g', '1');
+        }
+        else if (!strcasecmp(vcodec, "h263") || !strcasecmp(vcodec, "h263p"))
+        {
+	    mux_v->bih->biCompression = mmioFOURCC('h', '2', '6', '3');
+        }
+        else if (!strcasecmp(vcodec, "rv10"))
+        {
+	    mux_v->bih->biCompression = mmioFOURCC('R', 'V', '1', '0');
+        }
+        else if (!strcasecmp(vcodec, "mjpeg"))
+        {
+	    mux_v->bih->biCompression = mmioFOURCC('M', 'J', 'P', 'G');
+        }
+        else if (!strcasecmp(vcodec, "mpeg4"))
+        {
+	    mux_v->bih->biCompression = mmioFOURCC('M', 'P', '4', 'S');
+        }
+        else if (!strcasecmp(vcodec, "msmpeg4"))
+        {
+	    mux_v->bih->biCompression = mmioFOURCC('d', 'i', 'v', '3');
+        }
+    }
     mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
 
     printf("videocodec: libavcodec (%dx%d fourcc=%x [%.4s])\n",
 	mux_v->bih->biWidth, mux_v->bih->biHeight, mux_v->bih->biCompression,
-	    &mux_v->bih->biCompression);
+	    (char *)&mux_v->bih->biCompression);
 #endif
 }
 
@@ -716,7 +755,7 @@
     mux_v->bih->biCompression = mmioFOURCC(force_fourcc[0], force_fourcc[1],
 					    force_fourcc[2], force_fourcc[3]);
     printf("Forcing output fourcc to %x [%.4s]\n",
-	mux_v->bih->biCompression, &mux_v->bih->biCompression);
+	mux_v->bih->biCompression, (char *)&mux_v->bih->biCompression);
 }
 
 // ============= AUDIO ===============
@@ -733,7 +772,6 @@
 
 switch(mux_a->codec){
 case ACODEC_COPY:
-    printf("sh_audio->wf: %x\n", sh_audio->wf);
     mux_a->h.dwSampleSize=sh_audio->audio.dwSampleSize;
     mux_a->h.dwScale=sh_audio->audio.dwScale;
     mux_a->h.dwRate=sh_audio->audio.dwRate;
@@ -789,6 +827,48 @@
     ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nFramesPerBlock=1;
     ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nCodecDelay=0;
     break;
+case ACODEC_LIBAVCODEC:
+#ifndef USE_LIBAVCODEC
+    printf("No support for FFmpeg's libavcodec compiled in\n");
+    return 0; /* FIXME */
+#else
+    {
+	mux_a->h.dwSampleSize=2*sh_audio->channels;
+	mux_a->h.dwScale=1;
+	mux_a->h.dwRate=sh_audio->samplerate;
+	mux_a->wf=malloc(sizeof(WAVEFORMATEX));
+	mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize;
+	mux_a->wf->wFormatTag=0x1; // FIXME !!
+	mux_a->wf->nChannels=sh_audio->channels;
+	mux_a->wf->nSamplesPerSec=sh_audio->samplerate;
+	mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
+	mux_a->wf->wBitsPerSample=16;
+	mux_a->wf->cbSize=0; // FIXME for l3codeca.acm
+	if (lavc_param_acodec)
+	{
+	    const char *acodec = lavc_param_acodec;
+	    if (!strcasecmp(acodec, "mp2"))
+	    {
+		mux_a->wf->wFormatTag = 0x50;
+	    }
+	    else if (!strcasecmp(acodec, "ac3"))
+	    {
+		mux_a->wf->wFormatTag = 0x2000;
+	    }
+	    else if (!strcasecmp(acodec, "pcm_alaw"))
+	    {
+		mux_a->wf->wFormatTag = 0x6;
+	    }
+	    else if (!strcasecmp(acodec, "pcm_mulaw"))
+	    {
+		mux_a->wf->wFormatTag = 0x7;
+	    }
+	}
+	printf("audiocodec: libavcodec (format=%x chans=%d rate=%d bits=%d)\n",
+	    mux_a->wf->wFormatTag, mux_a->wf->nChannels, mux_a->wf->nSamplesPerSec,
+	    mux_a->wf->wBitsPerSample);
+    }
+#endif
 }
 }
 
@@ -1044,7 +1124,56 @@
 }
 break;
 #endif
+case ACODEC_LIBAVCODEC:
+#ifndef USE_LIBAVCODEC
+    printf("No support for FFmpeg's libavcodec compiled in\n");
+#else
+    if (!avcodec_inited)
+    {
+	avcodec_init();
+	avcodec_register_all();
+	avcodec_inited=1;
+    }
     
+    lavc_aenc_codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_acodec);
+
+    if (!lavc_aenc_codec)
+    {
+	printf(MSGTR_MissingLAVCcodec, lavc_param_acodec);
+	return 0; /* FIXME */
+    }
+
+    memset(&lavc_aenc_context, 0, sizeof(lavc_aenc_context));
+    lavc_aenc_context.sample_rate = mux_a->wf->nSamplesPerSec;
+    if (lavc_param_abitrate != -1)
+	lavc_aenc_context.bit_rate = lavc_param_abitrate;
+    else
+	lavc_aenc_context.bit_rate = 128000; /* 128kbit is default */
+    lavc_aenc_context.channels = mux_a->wf->nChannels;
+
+#if 0 /* used for audio too? */
+    /* ignored by libavcodec? */
+    if (lavc_param_vhq)
+    {
+	printf("High quality encoding selected (non real time)!\n");
+	lavc_aenc_context.flags = CODEC_FLAG_HQ;
+    }
+    else
+	lavc_aenc_context.flags = 0;
+#endif
+
+    if (avcodec_open(&lavc_aenc_context, lavc_aenc_codec) != 0)
+    {
+	printf(MSGTR_CantOpenCodec);
+	return 0; /* FIXME */
+    }
+
+    if (lavc_aenc_context.codec->encode == NULL)
+    {
+	printf("avcodec init failed (ctx->codec->encode == NULL)!\n");
+	return 0;
+    }
+#endif
 }
 
 signal(SIGINT,exit_sighandler);  // Interrupt from keyboard
@@ -1087,6 +1216,30 @@
 		len=mux_a->h.dwSampleSize*(mux_a->h.dwRate/2);
 		len=dec_audio(sh_audio,mux_a->buffer,len);
 		break;
+	    case ACODEC_LIBAVCODEC:
+	    {
+#if 0
+#if 1
+		int in_len =
+		    (((sh_audio->i_bps/2)/mux_a->h.dwSampleSize) < 1) ? mux_a->h.dwSampleSize :
+		    sh_audio->i_bps/2;
+//		len=sh_audio->i_bps/2;
+//		len/=mux_a->h.dwSampleSize;if(len<1) len=1;
+//		len*=mux_a->h.dwSampleSize;
+#else
+		int in_len=mux_a->h.dwSampleSize*(mux_a->h.dwRate/2);
+#endif
+		char *in_buf = malloc(in_len);
+		int dec_len = dec_audio(sh_audio,in_buf,in_len);
+		len=avcodec_encode_audio(&lavc_aenc_context, mux_a->buffer, mux_a->buffer_size, in_buf);
+		free(in_buf);
+//		printf("lavc audio len: input: %d, decoded: %d, encoded: %d\n",
+//		    in_len, dec_len, len);
+		break;
+#else
+		printf("lavc audio encode not yet working\n");
+#endif
+	    }
 	    }
 	} else {
 	    // VBR - encode/copy an audio frame




More information about the MPlayer-cvslog mailing list