Get the function code of the video PID from the PMT table
Implementation of the GETPMTPID function see: http://blog.csdn.net/myaccella/article/details/6982596
#define MAKE_PID (P) (((p[0]<<8) + p[1]) & 0X1FFF)
#define Make_word (H, L) ((h) << 8) | (l))
Structure definition of Little endian
typedef struct {
unsigned stream_type:8;
unsigned elementary_pid_high:5;
Unsigned:3;
unsigned elementary_pid_low:8;
unsigned es_info_length_high:4;
Unsigned:4;
unsigned es_info_length_low:8;
}mpegpmtstream_t;
typedef struct {
unsigned table_id:8;
unsigned section_length_high:4;
Unsigned:2;
Unsigned:1;
unsigned section_syntax_indicator:1;
unsigned section_length_low:8;
unsigned program_number_high:8;
unsigned program_number_low:8;
unsigned current_next_indicator:1;
unsigned version_number:5;
Unsigned:2;
unsigned section_number:8;
unsigned last_section_number:8;
unsigned pcr_pid_high:5;
Unsigned:3;
unsigned pcr_pid_low:8;
unsigned program_info_length_high:4;
Unsigned:4;
unsigned program_info_length_low:8;
}mpegpmtheader_t;
[HTML] View Plain copy ushort getvideopid (const char* filename) { # define tspacket_size 188 #define CRC_SIZE 4 ushort pid, pmtpid, videopid = 0; uchar buf[TSPACKET_SIZE]; uchar* p = buf; mpegpmtheader_ t* header; MpegPmtStream_t* stream; FILE* fp; int pos = 0; ushort section_len; pmtpid = getpmtpid (filename); if (pmtpid == 0) { fprintf (stderr, "Unable to get pmt pid!\n "); return 0; } fp = fopen (filename, " RB "); if (fp == null) { fprintf (stderr, "failed to open the file %s: %s\n ", filename, strerror (errno)); return 0; } while (Fread (BUF,&NBSP;1,&NBSP;TSPACKET_SIZE,&NBSP;FP) == tspacket_size) { if (Buf[0] != mpeg_ts_sync_byte) { // @MPEG_ts_sync_byte = 0x47 fprintf (stderr, "no sync byte!\n"); break; } p = buf; pid = make_pid ((p+1)); if ( pid != pmtpid ) { // Not a PMT packet continue; } // Payload_unit_start_indicator must be 1 if ( BUF[1]&NBSP;>>&NBSP;6&NBSP;&&NBSP;0X01)) { fprintf (stderr, "no payload_unit_start_indicator!\n"); continue; } // Skip the TS header p += mpeg_ts_header_size; //@MPEG_TS_HEADER_SIZE = 4 // Adaptation field exist or not if ((buf[3] >> 4 & 0x03) & 0x2) {