[MPlayer-dev-eng] [PATCH] softpulldown

Tobias Diedrich ranma at gmx.at
Sun Aug 3 03:40:19 CEST 2003


This patch adds a 'softpulldown' video filter. It uses the mpeg2 video
header information to make 29.97 fps out of 23.976 fps softtelecined
material. This should help especially for dvds which are partly
softtelecined.

Before I commit it I'd like to know if the way I added the needed flags
to mp_image_t is ok.

BTW, while developing this I noticed that libmpdemux/mpeg_hdr.c does
use the data in stream order and does no reordering, which means that
the display_time adjustments are often made for the wrong frame.

Two other things I noticed:
1) In mplayer.c, VOCTRL_DUPLICATE_FRAME is only called if
   vo_config_count>0, but vo_config_count is not increased by the
   yuv4mpeg output plugin.
2) This filter does not work properly with vo_yuv4mpeg because
   it supports slices and only writes a frame on flip_page.
   AFAICS there is no big benefit to slices support in vo_yuv4mpeg
   (As far as I understand it slices are needed for direct rendering),
   so would it be ok to disable slices support of vo_yuv4mpeg?

-- 
Tobias						PGP: http://9ac7e0bc.2ya.com
This mail is made of 100% recycled bits
-------------- next part --------------
Index: libmpcodecs/Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/Makefile,v
retrieving revision 1.101
diff -u -r1.101 Makefile
--- libmpcodecs/Makefile	13 Jul 2003 18:37:20 -0000	1.101
+++ libmpcodecs/Makefile	3 Aug 2003 01:36:53 -0000
@@ -14,7 +14,7 @@
 VIDEO_SRCS_OPT=vd_realvid.c vd_ffmpeg.c vd_dshow.c vd_dmo.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_xanim.c vd_xvid.c vd_libdv.c vd_qtvideo.c vd_theora.c
 VIDEO_SRCS=dec_video.c vd.c $(VIDEO_SRCS_NAT) $(VIDEO_SRCS_LIB) $(VIDEO_SRCS_OPT)
 
-VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c vf_ivtc.c vf_ilpack.c vf_dsize.c vf_decimate.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c vf_ivtc.c vf_ilpack.c vf_dsize.c vf_decimate.c vf_softpulldown.c
 ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c ve_xvid.c ve_qtvideo.c ve_nuv.c
 
 NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c native/decode144.c native/decode288.c
Index: libmpcodecs/mp_image.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/mp_image.h,v
retrieving revision 1.24
diff -u -r1.24 mp_image.h
--- libmpcodecs/mp_image.h	21 Jun 2003 01:47:25 -0000	1.24
+++ libmpcodecs/mp_image.h	3 Aug 2003 01:36:55 -0000
@@ -64,6 +64,9 @@
 
 #define MP_MAX_PLANES	4
 
+#define MP_IMGMPEG2FLAG_TOP_FIELD_FIRST 0x01
+#define MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD 0x02
+
 typedef struct mp_image_s {
     unsigned short flags;
     unsigned char type;
@@ -76,6 +79,7 @@
     char * qscale;
     int qstride;
     int pict_type; // 0->unknown, 1->I, 2->P, 3->B
+    int mpeg2_flags;
     int qscale_type; // 0->mpeg1/4/h263, 1->mpeg2
     int num_planes;
     /* these are only used by planar formats Y,U(Cb),V(Cr) */
Index: libmpcodecs/vd_libmpeg2.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vd_libmpeg2.c,v
retrieving revision 1.24
diff -u -r1.24 vd_libmpeg2.c
--- libmpcodecs/vd_libmpeg2.c	9 Jun 2003 12:10:42 -0000	1.24
+++ libmpcodecs/vd_libmpeg2.c	3 Aug 2003 01:36:55 -0000
@@ -143,6 +143,12 @@
 		(info->sequence->picture_height+15)&(~15) );
 	    if(!mpi) return 0; // VO ERROR!!!!!!!!
 	    mpeg2_set_buf(mpeg2dec, mpi->planes, mpi);
+	    if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST)
+		mpi->mpeg2_flags |= MP_IMGMPEG2FLAG_TOP_FIELD_FIRST;
+	    else mpi->mpeg2_flags &= ~MP_IMGMPEG2FLAG_TOP_FIELD_FIRST;
+	    if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD)
+		mpi->mpeg2_flags |= MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD;
+	    else mpi->mpeg2_flags &= ~MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD;
 
 #ifdef MPEG12_POSTPROC
 	    if(!mpi->qscale){
Index: libmpcodecs/vf.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf.c,v
retrieving revision 1.85
diff -u -r1.85 vf.c
--- libmpcodecs/vf.c	13 Jul 2003 22:51:20 -0000	1.85
+++ libmpcodecs/vf.c	3 Aug 2003 01:36:58 -0000
@@ -69,6 +69,7 @@
 extern vf_info_t vf_info_ilpack;
 extern vf_info_t vf_info_dsize;
 extern vf_info_t vf_info_decimate;
+extern vf_info_t vf_info_softpulldown;
 
 // list of available filters:
 static vf_info_t* filter_list[]={
@@ -127,6 +128,7 @@
     &vf_info_ilpack,
     &vf_info_dsize,
     &vf_info_decimate,
+    &vf_info_softpulldown,
     NULL
 };
 
@@ -435,6 +437,7 @@
 
 void vf_clone_mpi_attributes(mp_image_t* dst, mp_image_t* src){
     dst->pict_type= src->pict_type;
+    dst->mpeg2_flags = src->mpeg2_flags;
     dst->qscale_type= src->qscale_type;
     if(dst->width == src->width && dst->height == src->height){
 	dst->qstride= src->qstride;
Index: libmpeg2/header.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpeg2/header.c,v
retrieving revision 1.12
diff -u -r1.12 header.c
--- libmpeg2/header.c	6 Apr 2003 16:38:42 -0000	1.12
+++ libmpeg2/header.c	3 Aug 2003 01:37:03 -0000
@@ -506,7 +506,8 @@
     case FRAME_PICTURE:
 	if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)) {
 	    picture->nb_fields = (buffer[3] & 2) ? 3 : 2;
-	    flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0;
+	    flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST    : 0;
+	    flags |= (buffer[3] &   2) ? PIC_FLAG_REPEAT_FIRST_FIELD : 0;
 	} else
 	    picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2;
 	break;
Index: libmpeg2/mpeg2.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpeg2/mpeg2.h,v
retrieving revision 1.6
diff -u -r1.6 mpeg2.h
--- libmpeg2/mpeg2.h	6 Apr 2003 16:36:02 -0000	1.6
+++ libmpeg2/mpeg2.h	3 Aug 2003 01:37:04 -0000
@@ -67,6 +67,7 @@
 #define PIC_FLAG_COMPOSITE_DISPLAY 32
 #define PIC_FLAG_SKIP 64
 #define PIC_FLAG_PTS 128
+#define PIC_FLAG_REPEAT_FIRST_FIELD 256
 #define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000
 
 typedef struct {
--- libmpcodecs/vf_softpulldown.c	1970-01-01 01:00:00.000000000 +0100
+++ libmpcodecs/vf_softpulldown.c	2003-08-03 00:50:58.000000000 +0200
@@ -0,0 +1,160 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../config.h"
+#include "../mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "../libvo/fastmemcpy.h"
+#include "../libvo/sub.h"
+
+struct vf_priv_s {
+	int state;
+	long long in;
+	long long out;
+};
+
+static inline void *my_memcpy_pic(void * dst, void * src, int bytesPerLine, int height, int dstStride, int srcStride)
+{
+	int i;
+	void *retval=dst;
+
+	for(i=0; i<height; i++)
+	{
+		memcpy(dst, src, bytesPerLine);
+		src+= srcStride;
+		dst+= dstStride;
+	}
+
+	return retval;
+}
+
+static int put_image(struct vf_instance_s* vf, mp_image_t *mpi)
+{
+	mp_image_t *dmpi;
+	int ret = 0;
+	int flags = mpi->mpeg2_flags;
+	int state = vf->priv->state;
+
+	dmpi = vf_get_image(vf->next, mpi->imgfmt,
+	                    MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+	                    MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
+
+	vf->priv->in++;
+
+	if ((state == 0 &&
+	     !(flags & MP_IMGMPEG2FLAG_TOP_FIELD_FIRST)) ||
+	    (state == 1 &&
+	     flags & MP_IMGMPEG2FLAG_TOP_FIELD_FIRST))
+		mp_msg(MSGT_VFILTER, MSGL_WARN,
+		       "softpulldown: Unexpected mpeg2 flags: state=%d top_field_first=%d repeat_first_field=%d\n",
+		       state,
+		       (flags & MP_IMGMPEG2FLAG_TOP_FIELD_FIRST) == 1,
+		       (flags & MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD) == 1);
+
+	if (state == 0) {
+		ret = vf_next_put_image(vf, mpi);
+		vf->priv->out++;
+		if (flags & MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD) {
+			my_memcpy_pic(dmpi->planes[0],
+			           mpi->planes[0], mpi->w, mpi->h/2,
+			           dmpi->stride[0]*2, mpi->stride[0]*2);
+			if (mpi->flags & MP_IMGFLAG_PLANAR) {
+				my_memcpy_pic(dmpi->planes[1],
+				              mpi->planes[1],
+				              mpi->chroma_width,
+				              mpi->chroma_height/2,
+				              dmpi->stride[1]*2,
+				              mpi->stride[1]*2);
+				my_memcpy_pic(dmpi->planes[2],
+				              mpi->planes[2],
+				              mpi->chroma_width,
+				              mpi->chroma_height/2,
+				              dmpi->stride[2]*2,
+				              mpi->stride[2]*2);
+			}
+			state=1;
+		}
+	} else {
+		my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
+		              mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
+		              dmpi->stride[0]*2, mpi->stride[0]*2);
+		if (mpi->flags & MP_IMGFLAG_PLANAR) {
+			my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
+			              mpi->planes[1]+mpi->stride[1],
+			              mpi->chroma_width, mpi->chroma_height/2,
+			              dmpi->stride[1]*2, mpi->stride[1]*2);
+			my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
+			              mpi->planes[2]+mpi->stride[2],
+			              mpi->chroma_width, mpi->chroma_height/2,
+			              dmpi->stride[2]*2, mpi->stride[2]*2);
+		}
+		ret = vf_next_put_image(vf, dmpi);
+		vf->priv->out++;
+		if (flags & MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD) {
+			ret |= vf_next_put_image(vf, mpi);
+			vf->priv->out++;
+			state=0;
+		} else {
+			my_memcpy_pic(dmpi->planes[0],
+			              mpi->planes[0], mpi->w, mpi->h/2,
+			              dmpi->stride[0]*2, mpi->stride[0]*2);
+			if (mpi->flags & MP_IMGFLAG_PLANAR) {
+				my_memcpy_pic(dmpi->planes[1],
+				              mpi->planes[1],
+				              mpi->chroma_width,
+				              mpi->chroma_height/2,
+				              dmpi->stride[1]*2,
+				              mpi->stride[1]*2);
+				my_memcpy_pic(dmpi->planes[2],
+				              mpi->planes[2],
+				              mpi->chroma_width,
+				              mpi->chroma_height/2,
+				              dmpi->stride[2]*2,
+				              mpi->stride[2]*2);
+			}
+		}
+	}
+
+	vf->priv->state = state;
+
+	return ret;
+}
+
+static int config(struct vf_instance_s* vf,
+        int width, int height, int d_width, int d_height,
+	unsigned int flags, unsigned int outfmt)
+{
+	return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void uninit(struct vf_instance_s* vf)
+{
+	mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out);
+	free(vf->priv);
+}
+
+static int open(vf_instance_t *vf, char* args)
+{
+	struct vf_priv_s *p;
+	vf->config = config;
+	vf->put_image = put_image;
+	vf->uninit = uninit;
+	vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+	vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+	vf->priv->state = 0;
+	return 1;
+}
+
+vf_info_t vf_info_softpulldown = {
+    "mpeg2 soft 3:2 pulldown",
+    "softpulldown",
+    "Tobias Diedrich",
+    "",
+    open,
+    NULL
+};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20030803/cd224ea7/attachment.pgp>


More information about the MPlayer-dev-eng mailing list