Index: libmpcodecs/ve_xvid4.c
===================================================================
--- libmpcodecs/ve_xvid4.c	(revision 33477)
+++ libmpcodecs/ve_xvid4.c	(working copy)
@@ -164,6 +164,7 @@
 static int xvidenc_packed = 0;
 static int xvidenc_closed_gop = 1;
 static int xvidenc_interlaced = 0;
+static int xvidenc_top= -1;
 static int xvidenc_quarterpel = 0;
 static int xvidenc_gmc = 0;
 static int xvidenc_trellis = 1;
@@ -257,6 +258,7 @@
 	{"noclosed_gop", &xvidenc_closed_gop, CONF_TYPE_FLAG, 0, 1, 0, NULL},
 	{"interlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"nointerlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+	{"top", &xvidenc_top, CONF_TYPE_INT, CONF_RANGE, -1, 1, NULL},
 	{"cartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"nocartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 1, 0, NULL},
 	{"hq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 0, 1, NULL},
@@ -1296,6 +1298,25 @@
 		return BAD;
 	}
 
+	/* Set interlacing flags */
+	if (frame->vol_flags & XVID_VOL_INTERLACING) {
+		if (xvidenc_top==-1) {
+			// this piece doesn't work - don't know why mpi->fields are always 0
+			//mp_msg(MSGT_DECVIDEO, MSGL_INFO, "mpi->fields=%X %d\n", mpi->fields, mpi->fields);
+			if ((mpi->fields & MP_IMGFIELD_ORDERED) && (mpi->fields & MP_IMGFIELD_INTERLACED))
+				if (mpi->fields & MP_IMGFIELD_TOP_FIRST)
+					frame->vop_flags |= XVID_VOP_TOPFIELDFIRST;
+				else
+					frame->vop_flags &= ~XVID_VOP_TOPFIELDFIRST;
+		}
+		else {
+			if (xvidenc_top==1)
+				frame->vop_flags |= XVID_VOP_TOPFIELDFIRST;
+			else
+				frame->vop_flags &= ~XVID_VOP_TOPFIELDFIRST;
+		}
+	}
+
 	/* Bind source frame */
 	frame->input.plane[0]  = mpi->planes[0];
 	frame->input.plane[1]  = mpi->planes[1];
Index: DOCS/man/en/mplayer.1
===================================================================
--- DOCS/man/en/mplayer.1	(revision 33477)
+++ DOCS/man/en/mplayer.1	(working copy)
@@ -10097,6 +10097,19 @@
 which you can activate with \-vf scale=<width>:<height>:1.
 .
 .TP
+.B "top=<\-1\-1>\ \ \ "
+.PD 0
+.RSs
+.IPs \-1
+automatic
+.IPs 0
+bottom field first
+.IPs 1
+top field first
+.RE
+.PD 1
+.
+.TP
 .B min_iquant=<0\-31>
 minimum I-frame quantizer (default: 2)
 .
