#include <errno.h>
#define MAX_READ 1024
-#define MAX_FILENAME 30
+#define MAX_FILENAME 32
+#define MAX_VER_ID 64
+
+/*
+info:
+http://www.dv.co.yu/mpgscript/mpeghdr.htm
+*/
int main (int argc,char **argv)
{
- int file_fd,n_exit,count;
- char buf;
+ int file_fd,exit,count;
+ unsigned char buf;
+ unsigned char header[3];
+ char mpeg_ver_id[MAX_VER_ID];
char filename[MAX_FILENAME];
strcpy(filename,argv[1]);
- printf("test: %s\n",filename);
if((file_fd=open(filename,O_RDONLY))<=0) {
puts("open failed");
return -23;
}
- if((lseek(file_fd,atoi(argv[2])-MAX_READ,SEEK_SET))<0) {
- perror("lseek");
- return -23;
- }
+ count=0;
+ exit=0;
+ while(!exit) {
+ printf("count=%d\n",count++);
+ read(file_fd,&buf,1);
+ if(buf==0xff) {
+ read(file_fd,&buf,1);
+ if(buf>=0xe0) {
+ puts("got frame header:");
+ exit=1;
+ header[0]=buf;
+ read(file_fd,header+1,2);
+
+ printf("debug: %x%x%x \n",header[0],header[1],header[2]);
+
+ if(((header[0]&0x18)>>3)==0x00) strcpy(mpeg_ver_id,"MPEG Version 2.5");
+ else if(((header[0]&0x18)>>3)==0x10) strcpy(mpeg_ver_id,"MPEG Version 2 (ISO/IEC 13818-3)");
+ else if(((header[0]&0x18)>>3)==0x11) strcpy(mpeg_ver_id,"MPEG Version 1 (ISO/IEC 11172-3)");
+ else strcpy(mpeg_ver_id,"unknown");
- count=1;
- n_exit=1;
- while(n_exit) {
- n_exit=read(file_fd,&buf,1);
- count++;
- putchar(buf);
- if(count==MAX_READ) break;
+ printf("version: %s\n",mpeg_ver_id);
+ }
+ }
}
close(file_fd);