#include #include // ################################################## // # // ################################################## #define TS_HEADER_LENGTH 4 void dump_ts_packet(char *buf){ int i, j; for(i = 0; i < 5; i = i + 1){ // line printf(" %02d: ", i); for(j = 0; j < 16; j = j + 1){ printf("%02x ", (buf[i*16 + j] & 0xff)); } printf("\n"); } } int main(int argc, char* argv[]){ FILE *fp_in; unsigned int c; unsigned int pid; struct PMT{ unsigned int program_number; unsigned int program_map_PID; }; struct COMPONENT{ unsigned int stream_type; char stream_type_char[32]; unsigned int elementary_PID; unsigned int ES_info_length; char descripter[128]; }; int count = 0; // パケット数のカウンタ char buf[188]; if(( fp_in = fopen(argv[1], "rb")) == NULL){ return -1; } // ################### // ##### 最初の同期バイトを探す ##### // ################### while(1){ c = fgetc(fp_in); if(c == 0x47){ break; } } fseek(fp_in, -1, SEEK_CUR); // ################### // ##### 188バイト単位に読み出す ##### // ################### while(1){ if(fread(buf, 1, 188, fp_in) < 1){ break; } // ##### TSパケットヘッダからPIDを取得 ##### pid = ((((char)buf[0+1] & 0xff) << 8 | (buf[1+1] & 0xff)) & 0x1fff); printf("%04d(0x%04x): 0x%04x", count, count*188, pid); if(pid == 0){ // ################### // ##### PAT解析 ##### // ################### printf(" PAT"); } printf("\n"); count = count + 1; } fclose(fp_in); return 0; }