changeset 1872:2fe0e11bab3c

file writer implemented
author arpi
date Sat, 08 Sep 2001 23:27:51 +0000
parents cb5dde69354b
children f27465a65e41
files libvo/vo_mpegpes.c
diffstat 1 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_mpegpes.c	Sat Sep 08 20:48:02 2001 +0000
+++ b/libvo/vo_mpegpes.c	Sat Sep 08 23:27:51 2001 +0000
@@ -9,6 +9,8 @@
 
 LIBVO_EXTERN (mpegpes)
 
+int vo_mpegpes_fd=-1;
+
 static vo_info_t vo_info = 
 {
 	"Mpeg-PES file",
@@ -20,7 +22,11 @@
 static uint32_t
 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
 {
-
+    vo_mpegpes_fd=open("grab.mpg","ab");
+    if(vo_mpegpes_fd<0){	
+	perror("vo_mpegpes");
+	return -1;
+    }
     return 0;
 }
 
@@ -43,10 +49,41 @@
     return 0;
 }
 
+static void my_write(unsigned char* data,int len){
+    while(len>0){
+	int ret=write(vo_mpegpes_fd,data,len);
+	if(ret<=0) break; // error
+	len-=ret; data+=ret;
+    }
+}
 
 static uint32_t draw_frame(uint8_t * src[])
 {
+    vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
+    int payload_size=p->size+5;
+    int x;
+    unsigned char pes_header[4+2+5];
 
+    // construct PES header:
+	      // startcode:
+	      pes_header[0]=pes_header[1]=0;
+	      pes_header[2]=p->id>>8; pes_header[3]=p->id&255;
+	      // packetsize:
+	      pes_header[4]=payload_size>>8;
+	      pes_header[5]=payload_size&255;
+	      // stuffing:
+	      // presentation time stamp:
+	      x=(0x02 << 4) | (((p->timestamp >> 30) & 0x07) << 1) | 1;
+	      pes_header[6]=x;
+	      x=((((p->timestamp >> 15) & 0x7fff) << 1) | 1);
+	      pes_header[7]=x>>8; pes_header[8]=x&255;
+	      x=((((p->timestamp) & 0x7fff) << 1) | 1);
+	      pes_header[9]=x>>8; pes_header[10]=x&255;
+    my_write(pes_header,4+2+5);
+    // data:
+    my_write(p->data,p->size);
+
+//    printf("PES: draw frame!  pts=%d   size=%d  \n",p->timestamp,p->size);
 
     return 0;
 }
@@ -61,6 +98,8 @@
 static void
 uninit(void)
 {
+    close(vo_mpegpes_fd);
+    vo_mpegpes_fd=-1;
 }