Main Page | Data Structures | File List | Data Fields | Globals

h264_analyze.c

Go to the documentation of this file.
00001 /* 
00002  * h264bitstream - a library for reading and writing H.264 video
00003  * Copyright (C) 2005-2006 Auroras Entertainment, LLC
00004  * 
00005  * Written by Alex Izvorski <aizvorski@gmail.com>
00006  * 
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 }

Generated on Sat Jul 22 22:05:00 2006 by  doxygen 1.4.4