diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-14 09:08:56 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-14 09:08:56 +0100 |
| commit | 31660ca5df7e1a906defdab36823aa8791025a61 (patch) | |
| tree | db027c279be3e73f6f7eb6e395bff778bb2aeac2 /src/blind-from-video.c | |
| parent | Fix blind-split and add example (diff) | |
| download | blind-31660ca5df7e1a906defdab36823aa8791025a61.tar.gz blind-31660ca5df7e1a906defdab36823aa8791025a61.tar.bz2 blind-31660ca5df7e1a906defdab36823aa8791025a61.tar.xz | |
blind-from-video and blind-split: add -L
This, combined with blind-to-video, allows the user to split
a video file by frames (rather than time as with ffmpeg) into
multiple files without ever storing the video in a raw format.
This is feature is important because ever short video can take
a 100 GB in raw format.
Diffstat (limited to 'src/blind-from-video.c')
| -rw-r--r-- | src/blind-from-video.c | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/blind-from-video.c b/src/blind-from-video.c index 6dafeef..178ab17 100644 --- a/src/blind-from-video.c +++ b/src/blind-from-video.c @@ -14,7 +14,7 @@ #include <string.h> #include <unistd.h> -USAGE("[-r frame-rate] [-w width -h height] [-d] input-file output-file") +USAGE("[-r frame-rate] [-w width -h height] [-dL] input-file output-file") static int draft = 0; @@ -94,7 +94,7 @@ get_metadata(char *file, size_t *width, size_t *height) } static void -convert_segment(char *buf, size_t n, int fd, char *file) +convert_segment(char *buf, size_t n, int fd, const char *file) { typedef double pixel_t[4]; size_t i, ptr; @@ -135,7 +135,7 @@ convert_segment(char *buf, size_t n, int fd, char *file) } static void -convert(char *infile, int outfd, char *outfile, size_t width, size_t height, char *frame_rate) +convert(const char *infile, int outfd, const char *outfile, size_t width, size_t height, const char *frame_rate) { char geometry[2 * 3 * sizeof(size_t) + 2], buf[BUFSIZ]; const char *cmd[13]; @@ -206,17 +206,20 @@ main(int argc, char *argv[]) char head[STREAM_HEAD_MAX]; char *frame_rate = NULL; char *infile; - char *outfile; + const char *outfile; char *data; ssize_t headlen; size_t length, frame_size; - int outfd; + int outfd, skip_length = 0; struct stat st; ARGBEGIN { case 'd': draft = 1; break; + case 'L': + skip_length = 1; + break; case 'r': frame_rate = EARG(); break; @@ -245,7 +248,20 @@ main(int argc, char *argv[]) eprintf("video frame too large\n"); frame_size *= 4 * sizeof(double); - outfd = eopen(outfile, O_RDWR | O_CREAT | O_TRUNC, 0666); + if (!strcmp(outfile, "-")) { + outfile = "<stdout>"; + outfd = STDOUT_FILENO; + if (!skip_length) + eprintf("standard out as output file is only allowed with -L\n"); + } else { + outfd = eopen(outfile, O_RDWR | O_CREAT | O_TRUNC, 0666); + } + + if (skip_length) { + sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", frames, width, height, "xyza", 0, &headlen); + ewriteall(outfd, head, (size_t)headlen, outfile); + } + convert(infile, outfd, outfile, width, height, frame_rate); if (fstat(outfd, &st)) @@ -256,12 +272,14 @@ main(int argc, char *argv[]) eprintf("<subprocess>: incomplete frame"); frames = length / frame_size; - sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", frames, width, height, "xyza", 0, &headlen); - ewriteall(outfd, head, (size_t)headlen, outfile); - data = mmap(0, length + (size_t)headlen, PROT_READ | PROT_WRITE, MAP_SHARED, outfd, 0); - memmove(data + headlen, data, length); - memcpy(data, head, (size_t)headlen); - munmap(data, length + (size_t)headlen); + if (!skip_length) { + sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", frames, width, height, "xyza", 0, &headlen); + ewriteall(outfd, head, (size_t)headlen, outfile); + data = mmap(0, length + (size_t)headlen, PROT_READ | PROT_WRITE, MAP_SHARED, outfd, 0); + memmove(data + headlen, data, length); + memcpy(data, head, (size_t)headlen); + munmap(data, length + (size_t)headlen); + } close(outfd); return 0; |
