00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "h264_stream.h"
00023
00024 #include <stdlib.h>
00025 #include <stdint.h>
00026 #include <unistd.h>
00027 #include <fcntl.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030
00031 #define BUFSIZE 8*1024*1024
00032
00033
00034
00035 int main(int argc, char *argv[])
00036 {
00037 uint8_t* buf = (uint8_t*)malloc(BUFSIZE);
00038 h264_stream_t* h = (h264_stream_t*)malloc(sizeof(h264_stream_t));
00039 nal_t* nal = (nal_t*)malloc(sizeof(nal_t));
00040 sps_t* sps = (sps_t*)malloc(sizeof(sps_t));
00041 pps_t* pps = (pps_t*)malloc(sizeof(pps_t));
00042 slice_header_t* sh = (slice_header_t*)malloc(sizeof(slice_header_t));
00043 h->nal = nal;
00044 h->sps = sps;
00045 h->pps = pps;
00046 h->sh = sh;
00047
00048 if (argc < 2)
00049 {
00050 printf("h264_analyze, version 0.1.3\n");
00051 printf("Usage: \n");
00052 printf(" h264_analyze stream.h264\n");
00053 printf("where stream.h264 is a raw H264 stream, as produced by JM or x264\n");
00054 }
00055
00056 int fd = open(argv[1], O_RDONLY);
00057 if (fd == -1) { perror("could not open file"); exit(0); }
00058
00059 int rsz = 0;
00060 int sz = 0;
00061 int off = 0;
00062 uint8_t* p = buf;
00063
00064 int nal_start, nal_end;
00065
00066 while (rsz = read(fd, buf + sz, BUFSIZE - sz))
00067 {
00068 sz += rsz;
00069
00070 while (find_nal_unit(p, sz, &nal_start, &nal_end) > 0)
00071 {
00072 printf("!! Found NAL at offset %04X, size %04X (%d) \n",
00073 off + (p - buf) + nal_start, (nal_end - nal_start), (nal_end - nal_start));
00074 p += nal_start;
00075 read_nal_unit(h, p, nal_end - nal_start);
00076 debug_nal(h, h->nal);
00077 p += (nal_end - nal_start);
00078 sz -= nal_end;
00079 }
00080
00081 memmove(buf, p, sz);
00082 off += p - buf;
00083 p = buf;
00084 }
00085
00086 }