You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SimpleSkyCam/checkdumpfile.cc

116 lines
2.2 KiB

/*
* tool to check and gain some basic information about videodum-files
*/
/* enable files > 2GB on 32 bit systems */
#define _LARGEFILE64_SOURCE 1
#define _FILE_OFFSET_BITS 64
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef BUILD_WINDOWS
#else
#include <arpa/inet.h>
#endif
#include <string>
std::string convert_from_pixelformat (uint32_t fmt) {
char txt[5];
snprintf (txt, 5, "%c%c%c%c", ((char*)&fmt)[0], ((char*)&fmt)[1], ((char*)&fmt)[2], ((char*)&fmt)[3]);
return txt;
};
int main(int argc, char **argv) {
int fd;
int cnt = 0;
char *inbuf = NULL;
int inbufsize = 0;
uint32_t i;
uint32_t size;
if (argc != 2) {
printf ("please give a file name as parameter.\n");
printf ("checkdumpfile FILE\n");
printf ("\n");
return -1;
}
printf ("reading file :'%s'\n", argv[1]);
if ((fd = open (argv[1], O_RDONLY)) < 0) {
printf ("could not open file: %s\n", strerror(errno));
}
//
// read header w, h, pixfmt
if (read (fd, &i, 4) != 4) {
printf ("could not read all bytes.\n");
close (fd);
return -1;
}
printf (" Width: %d\n", ntohl(i));
if (read (fd, &i, 4) != 4) {
printf ("could not read all bytes.\n");
close (fd);
return -1;
}
printf (" Height: %d\n", ntohl(i));
if (read (fd, &i, 4) != 4) {
printf ("could not read all bytes.\n");
close (fd);
return -1;
}
printf(" Pixfmt: %s\n", convert_from_pixelformat(ntohl(i)).c_str());
//
// read frame
while (read (fd, &size, 4) == 4) {
size = ntohl(size);
if (read (fd, &i, 4) != 4) {
printf ("could not read all bytes.\n");
close (fd);
return -1;
}
i = ntohl(i);
if (inbuf == NULL){
inbuf = (char*) malloc (size);
inbufsize = size;
}
else if (inbufsize < size) {
inbuf = (char*)realloc(inbuf, size);
inbufsize = size;
}
if (inbuf == NULL) {
printf ("Error could not allocate enough memory\n");
close (fd);
return -1;
}
if (read (fd, inbuf, size) != size) {
printf ("could not read to next frame.\n");
close (fd);
return -1;
}
printf ("Frame: %-9d Timestamp:%-9d Size:%d\n", cnt++, i, size);
}
printf ("\nFile seems to be fine.\n");
close (fd);
return 0;
}