aboutsummaryrefslogtreecommitdiffstats
path: root/src/vu-concat.c
blob: 3ad92222d536b50a8195054debf3dee5b1796de1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* See LICENSE file for copyright and license details. */
#include "arg.h"
#include "stream.h"
#include "util.h"

#include <fcntl.h>
#include <inttypes.h>
#include <string.h>
#include <unistd.h>

static void
usage(void)
{
	eprintf("usage: %s first-stream ... last-stream\n", argv0);
}

int
main(int argc, char *argv[])
{
	struct stream stream, refstream;
	size_t ptr;
	ssize_t r;
	int i;

	ARGBEGIN {
	default:
		usage();
	} ARGEND;

	if (argc < 2)
		usage();

	for (i = 0; i < argc; i++) {
		stream.file = argv[i];
		stream.fd = open(stream.file, O_RDONLY);
		if (stream.fd < 0)
			eprintf("open %s:", stream.file);
		einit_stream(&stream);

		if (!i) {
			memcpy(&refstream, &stream, sizeof(stream));
			fprint_stream_head(stdout, &stream);
			fflush(stdout);
			if (ferror(stdout))
				eprintf("<stdout>:");
		} else {
			if (stream.width != refstream.width || stream.height != refstream.height)
				eprintf("videos do not have the same geometry\n");
			if (strcmp(stream.pixfmt, refstream.pixfmt))
				eprintf("videos use incompatible pixel formats\n");
		}

		for (; eread_stream(&stream, SIZE_MAX); stream.ptr = 0) {
			for (ptr = 0;; ptr += (size_t)r) {
				r = write(STDOUT_FILENO, stream.buf + ptr, stream.ptr - ptr);
				if (r < 0)
					eprintf("write <stdout>");
			}
		}

		close(stream.fd);
	}

	return 0;
}