--- libmpdemux/demux_mov.c.orig	2006-05-21 18:24:54.000000000 +0200
+++ libmpdemux/demux_mov.c	2006-05-21 18:27:16.000000000 +0200
@@ -1748,6 +1748,8 @@
   return 0;
 }
 
+extern int audio_id, video_id, dvdsub_id;
+
 static demuxer_t* mov_read_header(demuxer_t* demuxer){
     mov_priv_t* priv=demuxer->priv;
     int t_no;
@@ -1767,7 +1769,42 @@
     lschunks(demuxer, 0, priv->moov_end, NULL);
     // just in case we have hit eof while parsing...
     demuxer->stream->eof = 0;
-//    mp_msg(MSGT_DEMUX, MSGL_INFO, "--------------\n");
+    mp_msg(MSGT_DEMUX, MSGL_V, "-------------- tracks #: %d\n", priv->track_db);
+
+    // in case there's a generic MPEG track...
+    for (t_no = 0; t_no < priv->track_db; t_no++) {
+        mov_track_t* trak=priv->tracks[t_no];
+	int i;
+	if (trak->type != MOV_TRAK_GENERIC)
+	    continue;
+
+	mp_msg(MSGT_DEMUX, MSGL_DBG2, "MOV: Generic track #%d, subtype %.4s\n",
+	       t_no, (char*) &trak->media_handler);
+	// There are lot and lot and lot of more generic track types.
+	if (trak->media_handler != MOV_FOURCC('M','P','E','G'))
+	    continue;
+	if (trak->samples_size < 1) {
+	    mp_msg(MSGT_DEMUX, MSGL_WARN, "MOV: Urgh. Found MPEG generic track, but with zero samples...? Skipping.\n");
+	    continue;
+	}
+
+	mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found MPEG generic track, switching to MPEG demux.\n");
+	if (priv->track_db > 1)
+	    mp_msg(MSGT_DEMUX, MSGL_WARN, "MOV: There are some other tracks in the file - I'm not going to play them since this situation just wouldn't arise in practice; complain to developers if it really did. Sorry and have a nice day.\n");
+	if (trak->samples_size > 1)
+	    mp_msg(MSGT_DEMUX, MSGL_WARN, "MOV: There are multiple (%d) samples with MPEG streams. Who on earth would do that?! I will play just the first one (OTOH, the MPEG code could manage to resync and go on playing the other samples as well, if you are lucky). You can tweak the code in libmpdemux/demux_mov.c - it's fun! ;-)\n", trak->samples_size);
+
+	// FIXME: Also honor trak->samples[0].size.
+	demuxer->stream->start_pos = trak->samples[0].pos;
+	// Hack from demux_rtp.c:
+	{
+	// DEMUXER_TYPE_UNKNOWN? I don't know if there can't be other kinds
+	// of MPEG here as well. --pasky
+	demuxer_t* od = demux_open(demuxer->stream, DEMUXER_TYPE_MPEG_PS,
+	                           audio_id, video_id, dvdsub_id, NULL);
+	return new_demuxers_demuxer(od, od, od);
+	}
+    }
 
     // find the best (longest) streams:
     for(t_no=0;t_no<priv->track_db;t_no++){
@@ -1817,11 +1854,12 @@
 		for (i=0; i<trak->samples_size; i++)
 		{
 		    int len=trak->samples[i].size;
-		    char buf[len];
+		    char *buf = malloc(len);
 		    stream_seek(demuxer->stream, trak->samples[i].pos);
 		    snprintf(name, 20, "t%02d-s%03d.%s", t_no,i,
 			(trak->media_handler==MOV_FOURCC('f','l','s','h')) ?
 			    "swf":"dump");
+		    mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Saving sample %d to file %s ...\n",i,name);
 		    fd = open(name, O_CREAT|O_WRONLY);
 //		    { int j;
 //			for(j=0;j<trak->stdata_len-3; j++)
@@ -1836,7 +1874,7 @@
 			// unzip:
 			z_stream zstrm;
 			int zret;
-			char buf2[newlen];
+			char *buf2 = malloc(newlen);
 
 			len-=4;
 			stream_read(demuxer->stream, buf, len);
@@ -1855,6 +1893,7 @@
 	    		    mp_msg(MSGT_DEMUX, MSGL_WARN, "Warning! unzipped frame size differs hdr: %d  zlib: %ld\n",newlen,zstrm.total_out);
 			
 			write(fd, buf2, newlen);
+			free(buf2);
 		    } else {
 #else
 			len-=4;
@@ -1866,6 +1905,7 @@
 			write(fd, buf, len);
 		    }
 		    close(fd);
+		    free(buf);
 		}
 	    }
 	}
