[MPlayer-dev-eng] [PATCH] Field-reordering filter

Steinar H. Gunderson sgunderson at bigfoot.com
Sat Jan 9 12:31:41 CET 2010


On Sat, Jan 09, 2010 at 12:23:23PM +0100, Steinar H. Gunderson wrote:
> I've usually done this with a combination of expand and crop, but with recent
> mplayer it seems some 4:2:0 format is chosen for my encoding pipeline, which
> ruins that completely (the Y crop offset of 1 gets rounded to 0). This filter
> doesn't have any such restrictions; even for 4:2:0 (given MPEG-2-style
> chroma packing) I think it should be right just to shift one line. (Or, hmm,
> perhaps I need to filter?)

OK, of course I need to filter. Here's a version that refuses formats with
vertically subsampled chroma.

/* Steinar */

diff -Nur orig/mplayer-export-2010-01-02/DOCS/man/en/mplayer.1 mplayer-export-2010-01-02/DOCS/man/en/mplayer.1
--- orig/mplayer-export-2010-01-02/DOCS/man/en/mplayer.1	2009-12-29 14:43:03.000000000 +0100
+++ mplayer-export-2010-01-02/DOCS/man/en/mplayer.1	2010-01-09 02:49:37.000000000 +0100
@@ -6995,6 +6995,17 @@
 .RE
 .
 .TP
+.B freorder
+Switch the field order of interlaced video (top-field-first to bottom-field-first
+or vice versa) by shifting the entire frame one line up. This is useful when
+you have BFF video (for instance, from DV tape) and want to encode using a codec
+that only understands TFF, when combining BFF and TFF mateiral, or when flipping
+video or playing it backwards. Unlike the phase filter, this filter does not delay
+the stream by one field (1/50s = 20ms for PAL video), but it introduces a
+one-line black border at the bottom.
+.RE
+.
+.TP
 .B telecine[=start]
 Apply 3:2 'telecine' process to increase framerate by 20%.
 This most likely will not work correctly with MPlayer, but it can
diff -Nur orig/mplayer-export-2010-01-02/etc/codecs.conf mplayer-export-2010-01-02/etc/codecs.conf
--- orig/mplayer-export-2010-01-02/etc/codecs.conf	2010-01-01 00:45:07.000000000 +0100
+++ mplayer-export-2010-01-02/etc/codecs.conf	2010-01-06 21:06:17.000000000 +0100
diff -Nur orig/mplayer-export-2010-01-02/libmpcodecs/vf.c mplayer-export-2010-01-02/libmpcodecs/vf.c
--- orig/mplayer-export-2010-01-02/libmpcodecs/vf.c	2010-01-01 00:09:35.000000000 +0100
+++ mplayer-export-2010-01-02/libmpcodecs/vf.c	2010-01-09 02:37:29.000000000 +0100
@@ -100,6 +100,7 @@
 extern const vf_info_t vf_info_blackframe;
 extern const vf_info_t vf_info_geq;
 extern const vf_info_t vf_info_ow;
+extern const vf_info_t vf_info_freorder;
 
 // list of available filters:
 static const vf_info_t* const filter_list[]={
@@ -193,6 +194,7 @@
     &vf_info_yadif,
     &vf_info_blackframe,
     &vf_info_ow,
+    &vf_info_freorder,
     NULL
 };
 
diff -Nur orig/mplayer-export-2010-01-02/libmpcodecs/vf_freorder.c mplayer-export-2010-01-02/libmpcodecs/vf_freorder.c
--- orig/mplayer-export-2010-01-02/libmpcodecs/vf_freorder.c	1970-01-01 01:00:00.000000000 +0100
+++ mplayer-export-2010-01-02/libmpcodecs/vf_freorder.c	2010-01-09 12:28:31.000000000 +0100
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+#include "libavutil/avutil.h"
+
+#include "m_option.h"
+#include "m_struct.h"
+
+static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts) {
+    vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->w, mpi->h);
+    vf->dmpi->fields = mpi->fields ^ MP_IMGFIELD_TOP_FIRST;
+
+    memcpy_pic(vf->dmpi->planes[0], mpi->planes[0] + mpi->stride[0],
+               mpi->w, mpi->h - 1,
+               vf->dmpi->stride[0], mpi->stride[0]);
+    if (mpi->flags & MP_IMGFLAG_PLANAR) {
+        memcpy_pic(vf->dmpi->planes[1], mpi->planes[1] + mpi->stride[1],
+                   mpi->w, mpi->h - 1,
+                   vf->dmpi->stride[1], mpi->stride[1]);
+        memcpy_pic(vf->dmpi->planes[2], mpi->planes[2] + mpi->stride[2],
+                   mpi->w, mpi->h - 1,
+                   vf->dmpi->stride[2], mpi->stride[2]);
+    } else {
+	vf->dmpi->planes[1] = mpi->planes[1];  // Pass palette through.
+    }
+    return vf_next_put_image(vf,vf->dmpi, pts);
+}
+
+static int query_format(struct vf_instance_s* vf, unsigned int fmt) {
+    // Refuse formats with vertically subsampled chroma.
+    switch (fmt) {
+    case IMGFMT_YVU9:
+    case IMGFMT_IF09:
+    case IMGFMT_YV12:
+    case IMGFMT_I420:
+    case IMGFMT_IYUV:
+        return 0;
+    }
+    return vf_next_query_format(vf,fmt);
+}
+
+static int open(vf_instance_t *vf, char* args){
+    vf->query_format = query_format;
+    vf->put_image = put_image;
+    mp_msg(MSGT_VFILTER, MSGL_INFO, "Switch field orders\n");
+    return 1;
+}
+
+const vf_info_t vf_info_freorder = {
+    "switch field order (TFF->BFF or vice versa)",
+    "freorder",
+    "Steinar H. Gunderson",
+    "",
+    open,
+    NULL
+};
diff -Nur orig/mplayer-export-2010-01-02/Makefile mplayer-export-2010-01-02/Makefile
--- orig/mplayer-export-2010-01-02/Makefile	2009-12-31 19:25:35.000000000 +0100
+++ mplayer-export-2010-01-02/Makefile	2010-01-09 01:57:43.000000000 +0100
@@ -422,6 +423,7 @@
               libmpcodecs/vf_flip.c \
               libmpcodecs/vf_format.c \
               libmpcodecs/vf_framestep.c \
+              libmpcodecs/vf_freorder.c \
               libmpcodecs/vf_gradfun.c \
               libmpcodecs/vf_halfpack.c \
               libmpcodecs/vf_harddup.c \

-- 
Homepage: http://www.sesse.net/



More information about the MPlayer-dev-eng mailing list