commit d08f0bf0255fac18cd11992679dcb48c085de298
parent 55aee7c24247c6aeaa6ab32641989306f8f93625
Author: Mattias Andrée <maandree@kth.se>
Date: Wed, 11 Jan 2017 22:31:28 +0100
Fix vu-cut
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/stream.c b/src/stream.c
@@ -80,6 +80,7 @@ eninit_stream(int status, struct stream *stream)
stream->buf[3] != 'v' || stream->buf[4] != 'f')
goto bad_format;
memmove(stream->buf, stream->buf + 5, stream->ptr -= 5);
+ stream->headlen = n + 5;
enset_pixel_size(status, stream);
diff --git a/src/stream.h b/src/stream.h
@@ -24,6 +24,7 @@ struct stream
size_t ptr;
char buf[4096];
const char *file;
+ size_t headlen;
};
void eninit_stream(int status, struct stream *stream);
diff --git a/src/vu-cut.c b/src/vu-cut.c
@@ -14,7 +14,7 @@ int
main(int argc, char *argv[])
{
struct stream stream;
- size_t frame_size, start = 0, end = 0, ptr, max, n;
+ size_t frame_size, start = 0, end = 0, ptr, max;
ssize_t r;
char buf[BUFSIZ];
int to_end = 0;
@@ -50,19 +50,19 @@ main(int argc, char *argv[])
eprintf("%s\n", start > end ?
"start point is after end point" :
"refusing to create video with zero frames");
- end *= frame_size;
- start *= frame_size;
+ end = end * frame_size + stream.headlen;
+ start = start * frame_size + stream.headlen;
- for (ptr = start; ptr < end;) {
+ posix_fadvise(stream.fd, start, end - start, POSIX_FADV_SEQUENTIAL);
+ for (ptr = start; ptr < end; ptr += (size_t)r) {
max = end - ptr;
- max = sizeof(buf) < max ? sizeof(buf) : max;
- r = read(stream.fd, buf + ptr, max);
+ max = max < sizeof(buf) ? max : sizeof(buf);
+ r = pread(stream.fd, buf, max, ptr);
if (r < 0)
- eprintf("read %s:", stream.file);
+ eprintf("pread %s:", stream.file);
if (r == 0)
eprintf("%s: file is shorter than expected\n", stream.file);
- ptr += n = (size_t)r;
- ewriteall(STDOUT_FILENO, buf, n, "<stdout>");
+ ewriteall(STDOUT_FILENO, buf, (size_t)r, "<stdout>");
}
close(stream.fd);