[MPlayer-dev-eng] [PATCH] encode duplicate frames in mencoder

D Richard Felker III dalias at aerifal.cx
Tue Apr 27 19:34:27 CEST 2004


This patch makes it possible to actually encode duplicate frames with
mencoder, rather than writing the stupid 0-byte avi chunks that cause
trouble (especially with -of mpeg!). Unfortunately it doesn't work
right now for B frames because it actually exploits a hack in lavc.
The same principle is possible without this hack, but it would take
extra time to copy a backup of the previous encoded frame.

Would someone who understands lavc (Michael?) look at this and see if
my hack^H^H^H^Hcode in ve_lavc.c can be corrected without slowing it
down? This feature is very important to people wanting to make
VCD/DVD, so IMO it should be added as soon as it works.

Rich


-------------- next part --------------
Index: cfg-mencoder.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-mencoder.h,v
retrieving revision 1.82
diff -u -r1.82 cfg-mencoder.h
--- cfg-mencoder.h	24 Mar 2004 15:16:36 -0000	1.82
+++ cfg-mencoder.h	27 Apr 2004 17:21:33 -0000
@@ -207,6 +207,9 @@
 	{"autoexpand", &auto_expand, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"noautoexpand", &auto_expand, CONF_TYPE_FLAG, 0, 1, 0, NULL},
 	
+	{"encodedups", &encode_duplicates, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"noencodedups", &encode_duplicates, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+	
 	// info header strings
 	{"info", info_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
 
Index: mencoder.c
===================================================================
RCS file: /cvsroot/mplayer/main/mencoder.c,v
retrieving revision 1.241
diff -u -r1.241 mencoder.c
--- mencoder.c	17 Apr 2004 16:46:40 -0000	1.241
+++ mencoder.c	27 Apr 2004 17:21:33 -0000
@@ -189,6 +189,7 @@
 #endif
 
 int auto_expand=1;
+int encode_duplicates;
 
 // infos are empty by default
 char *info_name=NULL;
@@ -1312,7 +1313,8 @@
 	if(file_format != DEMUXER_TYPE_TV && !verbose) printf(MSGTR_DuplicateFrames,-skip_flag);
     while(skip_flag<0){
 	duplicatedframes++;
-	muxer_write_chunk(mux_v,0,0);
+	if (!encode_duplicates || vf_next_control(sh_video->vfilter, VFCTRL_DUPLICATE_FRAME, 0) != CONTROL_TRUE)
+	    muxer_write_chunk(mux_v,0,0);
 	++skip_flag;
     }
 } else
Index: libmpcodecs/vf.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf.h,v
retrieving revision 1.21
diff -u -r1.21 vf.h
--- libmpcodecs/vf.h	20 May 2003 17:42:33 -0000	1.21
+++ libmpcodecs/vf.h	27 Apr 2004 17:21:33 -0000
@@ -64,6 +64,7 @@
 #define VFCTRL_DRAW_OSD 7
 #define VFCTRL_CHANGE_RECTANGLE 9 /* Change the rectangle boundaries */
 #define VFCTRL_FLIP_PAGE 10 /* Tell the vo to flip pages */
+#define VFCTRL_DUPLICATE_FRAME 11 /* For encoding - encode zero-change frame */
 
 #include "vfcap.h"
 
Index: libmpcodecs/ve_lavc.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/ve_lavc.c,v
retrieving revision 1.93
diff -u -r1.93 ve_lavc.c
--- libmpcodecs/ve_lavc.c	24 Mar 2004 15:16:36 -0000	1.93
+++ libmpcodecs/ve_lavc.c	27 Apr 2004 17:21:34 -0000
@@ -681,6 +681,22 @@
 }
 
 static int control(struct vf_instance_s* vf, int request, void* data){
+    AVFrame *pic= vf->priv->pic;
+    AVFrame *coded= vf->priv->context->coded_frame;
+    switch(request) {
+    case VFCTRL_DUPLICATE_FRAME:
+        if (!pic || !coded) break;
+        pic->data[0]=coded->data[0];
+        pic->data[1]=coded->data[1];
+        pic->data[2]=coded->data[2];
+        pic->linesize[0]=coded->linesize[0];
+        pic->linesize[1]=coded->linesize[1];
+        pic->linesize[2]=coded->linesize[2];
+
+	if (avcodec_encode_video(lavc_venc_context, mux_v->buffer, mux_v->buffer_size, pic) > 0)
+            return CONTROL_TRUE;
+	break;
+    }
 
     return CONTROL_UNKNOWN;
 }


More information about the MPlayer-dev-eng mailing list