help in creating a videodev-dumpfile input source. It will help in develouping and work on the video filter without using a real camera. Created checkdumpfile as new Makefile target to generate a helper tool to gain some basic information on the videodump.test16bit
parent
8d96a401fd
commit
701f2f313e
@ -0,0 +1,103 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#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");
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in new issue