├── Makefile ├── README.md └── sei_parser.c /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc sei_parser.c -o sei_parser 3 | 4 | clean: 5 | rm sei_parser 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | H.264 Supplemental Enhancement Information (SEI) parser 2 | ======================================================= 3 | 4 | Extracts the SEI information of a raw H.264 video stream to check whether the frame_packing flag is set appropriately for 3D stereoscopic video to be detected correctly by players 5 | 6 | Can be compiled under both Linux and Windows. 7 | -------------------------------------------------------------------------------- /sei_parser.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Extracts the SEI information of a raw H.264 video stream 3 | * to check whether the frame_packing flag is set appropriately 4 | * for 3D stereoscopic video to be detected correctly by players 5 | * Compilable for Linux and Windows 6 | */ 7 | 8 | 9 | #define _CRT_SECURE_NO_WARNINGS // suppress windows compile warning for insecure fopen calls 10 | #include 11 | #include 12 | 13 | int mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; 14 | 15 | int readBit(unsigned char data[], int* bitpos) { 16 | int bit = (data[*bitpos/8] & mask[*bitpos%8]) != 0 ? 1 : 0; 17 | (*bitpos)++; 18 | return bit; 19 | } 20 | 21 | long readUnsigned(unsigned char data[], int* bitpos, int length) { 22 | long value = 0; 23 | while (length-->0) 24 | if (readBit(data, bitpos) == 1) 25 | value += 1<=2 && payload[i] == 0x03 && payload[i-1] == 0x00 && payload[i-2] == 0x00) { 99 | i--; 100 | emu_count = 0; 101 | } 102 | } 103 | if (i != payload_size) { 104 | fprintf(stderr, "EOF reached while reading SEI payload"); 105 | free(payload); 106 | return; 107 | } 108 | parse_sei_payload(payload, payload_size); 109 | free(payload); 110 | } 111 | 112 | void seek_sei(char* filename) { 113 | int offset = 0; 114 | int checklen = 0; 115 | FILE* f = fopen(filename, "r"); 116 | while (!feof(f)) { 117 | if (checklen < 2 && fgetc(f) == 0x00) 118 | checklen++; 119 | else if (checklen == 2 && fgetc(f) == 0x01) 120 | checklen++; 121 | else if (checklen == 3 && fgetc(f) == 0x06) { 122 | parse_sei_unit(f); 123 | checklen = 0; 124 | } 125 | else 126 | checklen = 0; 127 | } 128 | fclose(f); 129 | } 130 | 131 | int main(int argc, char** args) { 132 | if (argc != 2) 133 | printf("Usage: sei_parser \n or simply drag&drop a h264-file on this program\n2011-11-03-schiermike\n\n"); 134 | else 135 | seek_sei(args[1]); 136 | 137 | printf("Press any key to quit...\n"); 138 | getchar(); 139 | 140 | return 0; 141 | } 142 | --------------------------------------------------------------------------------