blind

suckless command-line video editing utility
git clone git://git.suckless.org/blind
Log | Files | Refs | README | LICENSE

blind-interleave.c (1041B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "common.h"
      3 
      4 USAGE("(file frames) ...")
      5 
      6 int
      7 main(int argc, char *argv[])
      8 {
      9 	struct stream *streams;
     10 	size_t parts, length = 0, *frames, i;
     11 
     12 	UNOFLAGS(argc % 2 || !argc);
     13 
     14 	parts   = (size_t)argc / 2;
     15 	streams = emalloc2(parts, sizeof(*streams));
     16 	frames  = alloca(parts * sizeof(*frames));
     17 
     18 	for (i = 0; i < parts; i++) {
     19 		eopen_stream(streams + i, argv[i * 2]);
     20 		frames[i] = etozu_arg("frames", argv[i * 2 + 1], 1, SIZE_MAX);
     21 		if (i)
     22 		    echeck_compat(streams, streams + i);
     23 	}
     24 	for (i = 0; i < parts; i++) {
     25 		if (!streams[i].frames || streams[i].frames > SIZE_MAX - length) {
     26 			length = 0;
     27 			break;
     28 		}
     29 		length += streams[i].frames;
     30 	}
     31 
     32 	streams->frames = length;
     33 	fprint_stream_head(stdout, streams);
     34 	efflush(stdout, "<stdout>");
     35 
     36 	for (i = 0; i < parts; i++, i = i == parts ? 0 : i)
     37 		if (esend_frames(streams + i, STDOUT_FILENO, frames[i], "<stdout>") != frames[i])
     38 			break;
     39 	for (i = 0; i < parts; i++)
     40 		close(streams[i].fd);
     41 
     42 	free(streams);
     43 	return 0;
     44 }