From 4a0bec23f06a4e119531fb8a62c07d346116c709 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 14 Jan 2017 08:41:44 +0100 Subject: Fix blind-split and add example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-cut.c | 2 +- src/blind-split.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/blind-cut.c b/src/blind-cut.c index e2a7fa6..6112120 100644 --- a/src/blind-cut.c +++ b/src/blind-cut.c @@ -43,7 +43,7 @@ main(int argc, char *argv[]) efflush(stdout, ""); echeck_frame_size(stream.width, stream.height, stream.pixel_size, 0, stream.file); frame_size = stream.width * stream.height * stream.pixel_size; - if (stream.frames > SSIZE_MAX / frame_size) + if (stream.frames > (size_t)SSIZE_MAX / frame_size) eprintf("%s: video is too large\n", stream.file); if (start >= end) diff --git a/src/blind-split.c b/src/blind-split.c index ff6ce38..6b06da5 100644 --- a/src/blind-split.c +++ b/src/blind-split.c @@ -26,7 +26,7 @@ main(int argc, char *argv[]) einit_stream(&stream); echeck_frame_size(stream.width, stream.height, stream.pixel_size, 0, stream.file); frame_size = stream.width * stream.height * stream.pixel_size; - if (stream.frames > SSIZE_MAX / frame_size) + if (stream.frames > (size_t)SSIZE_MAX / frame_size) eprintf("%s: video is too large\n", stream.file); parts = (size_t)argc / 2; @@ -55,12 +55,17 @@ main(int argc, char *argv[]) efflush(fp, argv[i * 2]); for (end = ends[i] * frame_size; ptr < end; ptr += n) { - if (stream.ptr == sizeof(stream.buf)) - n = stream.ptr < end - ptr ? stream.ptr : end - ptr; - else if (!(n = eread_stream(&stream, end - ptr))) + n = end - ptr; + if (stream.ptr) { + n = stream.ptr < n ? stream.ptr : n; + ewriteall(fd, stream.buf, n, argv[i * 2]); + memmove(stream.buf, stream.buf + n, stream.ptr -= n); + } else if ((n = eread_stream(&stream, n))) { + ewriteall(fd, stream.buf, n, argv[i * 2]); + stream.ptr = 0; + } else { eprintf("%s: file is shorter than expected\n", stream.file); - ewriteall(STDOUT_FILENO, stream.buf, n, ""); - memmove(stream.buf, stream.buf + n, stream.ptr -= n); + } } if (fclose(fp)) -- cgit v1.2.3-70-g09d2