changeset 9069:0d2b25a821c9

raw mpeg4-es support (you need to set -fps manually!)
author arpi
date Thu, 23 Jan 2003 02:12:15 +0000
parents 8f1659a47aa4
children 8b2dde0dccf6
files etc/codecs.conf libmpdemux/demux_mpg.c libmpdemux/demuxer.c libmpdemux/demuxer.h libmpdemux/video.c
diffstat 5 files changed, 79 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/etc/codecs.conf	Thu Jan 23 01:16:49 2003 +0000
+++ b/etc/codecs.conf	Thu Jan 23 02:12:15 2003 +0000
@@ -309,6 +309,7 @@
   format 0x4
   fourcc UMP4
   fourcc 3IV2,3iv2  ; 3ivx Delta 4   
+  format 0x10000004  ; mpeg 4 es
   driver ffmpeg
   dll mpeg4 ;opendivx
   out YV12,I420,IYUV
--- a/libmpdemux/demux_mpg.c	Thu Jan 23 01:16:49 2003 +0000
+++ b/libmpdemux/demux_mpg.c	Thu Jan 23 02:12:15 2003 +0000
@@ -247,6 +247,7 @@
 
 int num_elementary_packets100=0;
 int num_elementary_packets101=0;
+int num_elementary_packets12x=0;
 int num_elementary_packets1B6=0;
 int num_elementary_packetsPES=0;
 int num_mp3audio_packets=0;
@@ -314,7 +315,8 @@
   } else {
     if(head>=0x100 && head<0x1B0){
       if(head==0x100) ++num_elementary_packets100; else
-      if(head==0x101) ++num_elementary_packets101;
+      if(head==0x101) ++num_elementary_packets101; else
+      if(head>=0x120 && head<=0x12F) ++num_elementary_packets12x;
       mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... elementary video packet found: %03X\n",head);
     } else
     if((head>=0x1C0 && head<0x1F0) || head==0x1BD){
--- a/libmpdemux/demuxer.c	Thu Jan 23 01:16:49 2003 +0000
+++ b/libmpdemux/demuxer.c	Thu Jan 23 02:12:15 2003 +0000
@@ -292,6 +292,7 @@
     case DEMUXER_TYPE_FILM: return demux_film_fill_buffer(demux);
     case DEMUXER_TYPE_BMP: return demux_bmp_fill_buffer(demux);
     case DEMUXER_TYPE_FLI: return demux_fli_fill_buffer(demux);
+    case DEMUXER_TYPE_MPEG4_ES:
     case DEMUXER_TYPE_MPEG_ES: return demux_mpg_es_fill_buffer(demux);
     case DEMUXER_TYPE_MPEG_PS: return demux_mpg_fill_buffer(demux);
     case DEMUXER_TYPE_AVI: return demux_avi_fill_buffer(demux);
@@ -502,6 +503,7 @@
 extern int num_elementary_packets101;
 extern int num_elementary_packetsPES;
 extern int num_elementary_packets1B6;
+extern int num_elementary_packets12x;
 extern int num_mp3audio_packets;
 
 // commandline options, flags:
@@ -813,6 +815,7 @@
   num_elementary_packets100=0;
   num_elementary_packets101=0;
   num_elementary_packets1B6=0;
+  num_elementary_packets12x=0;
   num_elementary_packetsPES=0;
   num_mp3audio_packets=0;
 
@@ -823,8 +826,10 @@
       mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat,"MPEG-PS");
     file_format=DEMUXER_TYPE_MPEG_PS;
   } else {
-    mp_msg(MSGT_DEMUX,MSGL_V,"MPEG packet stats: p100: %d  p101: %d  PES: %d  MP3: %d \n",
-	num_elementary_packets100,num_elementary_packets101,num_elementary_packetsPES,num_mp3audio_packets);
+    mp_msg(MSGT_DEMUX,MSGL_V,"MPEG packet stats: p100: %d  p101: %d p1B6: %d p12x: %d PES: %d  MP3: %d \n",
+	num_elementary_packets100,num_elementary_packets101,
+	num_elementary_packets1B6,num_elementary_packets12x,
+	num_elementary_packetsPES,num_mp3audio_packets);
 //MPEG packet stats: p100: 458  p101: 458  PES: 0  MP3: 1103  (.m2v)
     if(num_mp3audio_packets>50 && num_mp3audio_packets>2*num_elementary_packets100
 	&& abs(num_elementary_packets100-num_elementary_packets101)>2)
@@ -836,7 +841,16 @@
         --pes;continue; // tricky...
       }
       file_format=DEMUXER_TYPE_MPEG_ES; //  <-- hack is here :)
-    } else {
+    } else 
+#if 0
+    // fuzzy mpeg4-es detection. do NOT enable without heavy testing of mpeg formats detection!
+    if(num_elementary_packets1B6>3 && num_elementary_packets12x>=1 &&
+       num_elementary_packetsPES==0 && num_elementary_packets100<=num_elementary_packets12x &&
+       demuxer->synced<2){
+      file_format=DEMUXER_TYPE_MPEG4_ES;
+    } else
+#endif
+    {
       if(demuxer->synced==2)
         mp_msg(MSGT_DEMUXER,MSGL_ERR,"MPEG: " MSGTR_MissingVideoStreamBug);
       else
@@ -849,15 +863,15 @@
  }
 }
 //=============== Try to open as MPEG-ES file: =================
-if(file_format==DEMUXER_TYPE_MPEG_ES){ // little hack, see above!
-  demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_ES,audio_id,video_id,dvdsub_id);
+if(file_format==DEMUXER_TYPE_MPEG_ES || file_format==DEMUXER_TYPE_MPEG4_ES){ // little hack, see above!
+  demuxer=new_demuxer(stream,file_format,audio_id,video_id,dvdsub_id);
   if(!ds_fill_buffer(demuxer->video)){
     mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_InvalidMPEGES);
     file_format=DEMUXER_TYPE_UNKNOWN;
     free_demuxer(demuxer);
     demuxer = NULL;
   } else {
-    mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat,"MPEG-ES");
+    mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat,(file_format==DEMUXER_TYPE_MPEG_ES)?"MPEG-ES":"MPEG4-ES");
   }
 }
 #ifdef HAVE_LIBDV095
@@ -1044,6 +1058,7 @@
   }
   break;
  }
+ case DEMUXER_TYPE_MPEG4_ES:
  case DEMUXER_TYPE_MPEG_ES: {
    sh_audio=NULL;   // ES streams has no audio channel
    d_video->sh=new_sh_video(demuxer,0); // create dummy video stream header, id=0
@@ -1207,6 +1222,7 @@
   case DEMUXER_TYPE_ASF:
       demux_seek_asf(demuxer,rel_seek_secs,flags);  break;
   
+  case DEMUXER_TYPE_MPEG4_ES:
   case DEMUXER_TYPE_MPEG_ES:
   case DEMUXER_TYPE_MPEG_PS:
       demux_seek_mpg(demuxer,rel_seek_secs,flags);  break;
@@ -1312,6 +1328,7 @@
 
 int demux_control(demuxer_t *demuxer, int cmd, void *arg) {
     switch(demuxer->type) {
+	case DEMUXER_TYPE_MPEG4_ES:
 	case DEMUXER_TYPE_MPEG_ES:
 	case DEMUXER_TYPE_MPEG_PS:
 	    return demux_mpg_control(demuxer,cmd,arg);
--- a/libmpdemux/demuxer.h	Thu Jan 23 01:16:49 2003 +0000
+++ b/libmpdemux/demuxer.h	Thu Jan 23 02:12:15 2003 +0000
@@ -35,11 +35,12 @@
 #define DEMUXER_TYPE_SMJPEG 24
 #define DEMUXER_TYPE_XMMS 25
 #define DEMUXER_TYPE_RAWVIDEO 26
+#define DEMUXER_TYPE_MPEG4_ES 27
 
 // This should always match the higest demuxer type number.
 // Unless you want to disallow users to force the demuxer to some types
 #define DEMUXER_TYPE_MIN 0
-#define DEMUXER_TYPE_MAX 26
+#define DEMUXER_TYPE_MAX 27
 
 #define DEMUXER_TYPE_DEMUXERS (1<<16)
 // A virtual demuxer type for the network code
--- a/libmpdemux/video.c	Thu Jan 23 01:16:49 2003 +0000
+++ b/libmpdemux/video.c	Thu Jan 23 02:12:15 2003 +0000
@@ -89,6 +89,46 @@
    if (!demux_is_mpeg_rtp_stream(d_video->demuxer)) break;
    // otherwise fall through to...
 #endif
+ case DEMUXER_TYPE_MPEG4_ES: {
+   videobuf_len=0; videobuf_code_len=0;
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for Video Object Start code... ");fflush(stdout);
+   while(1){
+      int i=sync_video_packet(d_video);
+      if(i<=0x11F) break; // found it!
+      if(!i || !skip_video_packet(d_video)){
+        mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
+	return 0;
+      }
+   }
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
+   if(!videobuffer) videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE);
+   if(!videobuffer){ 
+     mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
+     return 0;
+   }
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for Video Object Layer Start code... ");fflush(stdout);
+   while(1){
+      int i=sync_video_packet(d_video);
+      printf("0x%X\n",i);
+      if(i>=0x120 && i<=0x12F) break; // found it!
+      if(!i || !read_video_packet(d_video)){
+        mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
+	return 0;
+      }
+   }
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\nSearching for Video Object Plane Start code... ");fflush(stdout);
+   while(1){
+      int i=sync_video_packet(d_video);
+      if(i==0x1B6) break; // found it!
+      if(!i || !read_video_packet(d_video)){
+        mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
+	return 0;
+      }
+   }
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
+   sh_video->format=0x10000004;
+   break;
+ }
  case DEMUXER_TYPE_PVA:
  case DEMUXER_TYPE_MPEG_ES:
  case DEMUXER_TYPE_MPEG_PS: {
@@ -316,6 +356,16 @@
 	    telecine=1;
 	}
 
+  } else if(demuxer->file_format==DEMUXER_TYPE_MPEG4_ES){
+      //
+        while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
+          int i=sync_video_packet(d_video);
+          if(!read_video_packet(d_video)) return -1; // EOF
+	  if(i==0x1B6) break;
+        }
+	*start=videobuffer; in_size=videobuf_len;
+	videobuf_len=0;
+
   } else {
       // frame-based file formats: (AVI,ASF,MOV)
     in_size=ds_get_packet(d_video,start);