diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-10 05:43:46 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-10 05:43:46 +0100 |
| commit | d7a0f85091578faae3e0ace1ca8b32ca0a92c087 (patch) | |
| tree | fbee5fc9bb10a176e6ed86ecdd84d5b9ff44eba3 /src | |
| parent | m (diff) | |
| download | blind-d7a0f85091578faae3e0ace1ca8b32ca0a92c087.tar.gz blind-d7a0f85091578faae3e0ace1ca8b32ca0a92c087.tar.bz2 blind-d7a0f85091578faae3e0ace1ca8b32ca0a92c087.tar.xz | |
m + Add vu-cut
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
| -rw-r--r-- | src/vu-concat.c | 2 | ||||
| -rw-r--r-- | src/vu-cut.c | 92 | ||||
| -rw-r--r-- | src/vu-dissolve.c | 2 | ||||
| -rw-r--r-- | src/vu-reverse.c | 2 |
4 files changed, 95 insertions, 3 deletions
diff --git a/src/vu-concat.c b/src/vu-concat.c index a882e94..3239209 100644 --- a/src/vu-concat.c +++ b/src/vu-concat.c @@ -64,7 +64,7 @@ main(int argc, char *argv[]) for (ptr = 0; ptr < streams[i].ptr; ptr += (size_t)r) { r = write(STDOUT_FILENO, streams[i].buf + ptr, streams[i].ptr - ptr); if (r < 0) - eprintf("write <stdout>"); + eprintf("write <stdout>:"); } } close(streams[i].fd); diff --git a/src/vu-cut.c b/src/vu-cut.c new file mode 100644 index 0000000..011e31c --- /dev/null +++ b/src/vu-cut.c @@ -0,0 +1,92 @@ +/* See LICENSE file for copyright and license details. */ +#include "arg.h" +#include "stream.h" +#include "util.h" + +#include <fcntl.h> +#include <limits.h> +#include <stdint.h> +#include <string.h> +#include <unistd.h> + +static void +usage(void) +{ + eprintf("usage: %s start-point (end-point | 'end') file\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + struct stream stream; + size_t frame_size, start = 0, end = 0, ptr, max, n, ptw; + ssize_t r; + char buf[BUFSIZ]; + int to_end = 0; + + ARGBEGIN { + default: + usage(); + } ARGEND; + + if (argc != 3) + usage(); + + if (!strcmp(argv[0], "end")) { + eprintf("refusing to create video with zero frames\n"); + } else if (tozu(argv[0], 0, SIZE_MAX, &start)) { + eprintf("the start point must be an integer in [0, %zu]\n", SIZE_MAX); + } + + if (!strcmp(argv[1], "end")) { + to_end = 1; + } else if (tozu(argv[1], 0, SIZE_MAX, &end)) { + eprintf("the end point must be an integer in [0, %zu]\n", SIZE_MAX); + } + + stream.file = argv[2]; + stream.fd = open(stream.file, O_RDONLY); + if (stream.fd < 0) + eprintf("open %s:", stream.file); + einit_stream(&stream); + if (to_end) + end = stream.frames; + else if (end > stream.frames) + eprintf("end point is after end of video\n"); + stream.frames = end - start; + fprint_stream_head(stdout, &stream); + fflush(stdout); + if (ferror(stdout)) + eprintf("<stdout>:"); + if (stream.width > SIZE_MAX / stream.height) + eprintf("%s: video is too large\n", stream.file); + frame_size = stream.width * stream.height; + if (stream.frames > SSIZE_MAX / frame_size) + eprintf("%s: video is too large\n", stream.file); + + if (start >= end) + eprintf("%s\n", start > end ? + "start point is after end point" : + "refusing to create video with zero frames"); + end *= frame_size; + start *= frame_size; + + for (ptr = start; ptr < end;) { + max = end - ptr; + max = sizeof(buf) < max ? sizeof(buf) : max; + r = read(stream.fd, buf + ptr, max); + if (r < 0) + eprintf("read %s:", stream.file); + if (r == 0) + eprintf("%s: file is shorter than expected\n", stream.file); + ptr += n = (size_t)r; + for (ptw = 0; ptw < n; ptw += (size_t)r) { + r = write(STDOUT_FILENO, buf + ptw, n - ptw); + if (r < 0) + eprintf("write <stdout>:"); + } + } + + close(stream.fd); + return 0; +} diff --git a/src/vu-dissolve.c b/src/vu-dissolve.c index 38c233f..0bf5311 100644 --- a/src/vu-dissolve.c +++ b/src/vu-dissolve.c @@ -75,7 +75,7 @@ main(int argc, char *argv[]) for (h = stream.height; h--;) { for (w = stream.width * stream.pixel_size; w; w -= n) { if (!eread_stream(&stream, w)) - eprintf("<stdin>: file is truncated\n"); + eprintf("<stdin>: file is shorter than expected\n"); n = stream.ptr - (stream.ptr % stream.pixel_size); process(&stream, n, f, fm); for (i = 0; i < n; i += (size_t)r) { diff --git a/src/vu-reverse.c b/src/vu-reverse.c index 1e807fd..bf96a60 100644 --- a/src/vu-reverse.c +++ b/src/vu-reverse.c @@ -54,7 +54,7 @@ main(int argc, char *argv[]) if (r < 0) eprintf("pread %s:", stream.file); else if (r == 0) - eprintf("%s: file is shorter than expected", stream.file); + eprintf("%s: file is shorter than expected\n", stream.file); ptr += n = (size_t)r; for (ptw = 0; ptw < n;) { r = write(STDOUT_FILENO, buf + ptw, n - ptw); |
