#define _LARGEFILE64_SOURCE #define _LARGEFILE_SOURCE #include #include #include #include #include #include #include #define RATE 48000 #define XSIZE 256 #define YSIZE 240 //#define XSIZE 240 //#define YSIZE 160 #define CHANNELS 1 #define PICS_PER_LINE 2 #define PIXBYTES 3 #define FRAMESKIP 1 #define LASTFRAME 0x7FFFFFFF //#define LASTFRAME 120 static FILE* Nfopen(const char* fn, const char* mode) { unsigned BufSize = 1024*1024*2; int mask = O_RDONLY; int fd; FILE* fp; char* Buf = (char*)malloc(BufSize); if(*mode == 'r') mask = O_RDONLY; if(*mode == 'w') mask = O_WRONLY | O_TRUNC | O_CREAT; fd = open(fn, mask | O_LARGEFILE, 0644); fp = fdopen(fd, mode); setbuffer(fp, Buf, BufSize); return fp; } typedef struct { char Buf[XSIZE*YSIZE*PIXBYTES]; } frame; int main(int argc, char **argv) { --argc; if(argc != 5) { fprintf(stderr, "Usage: sidebyside NUMBER video%%d.raw audio%%d.raw VIDEO_OUT AUDIO_OUT\n" "Where %%d will be automatically substituted by stream number (1-N)\n"); return -1; } unsigned N = atoi(argv[1]); std::string Vpat = argv[2]; std::string Apat = argv[3]; std::string Vout = argv[4]; std::string Aout = argv[5]; std::vector vin(N); std::vector ain(N); /* sidebyside 2 video%.raw audio%.raw video.raw audio.raw */ const unsigned Lines = (N + PICS_PER_LINE-1) / PICS_PER_LINE; FILE* aout = Nfopen(Aout.c_str(), "wb"); for(unsigned a=0; a Bufs(N); static const unsigned char zerobuf[XSIZE*PIXBYTES] = {0}; bool non_eof = false; for(unsigned a=0; a= LASTFRAME) break; #endif /**/}/**/ FrameDone: if(FRAMESKIP) line_counter = (line_counter+1)%FRAMESKIP; } for(unsigned a=0; a Bufs(N*CHANNELS); bool non_eof = false; for(unsigned a=0; a 0.0 && leftness < 0.3) leftness = 0.3; if(leftness <= 0.0 && leftness > -0.3) leftness = -0.3; if(rightness > 0.0 && rightness < 0.3) rightness = 0.3; if(rightness <= 0.0 && rightness > -0.3) rightness = -0.3; //lefts left += Bufs[a*2+0] * std::max(-0.5, leftness); right += Bufs[a*2+0] * std::max(-0.5, rightness * 0.3); //rights left += Bufs[a*2+1] * std::max(-0.5, leftness * 0.3); right += Bufs[a*2+1] * std::max(-0.5, rightness); } #else for(unsigned a=0; a 0.0 && leftness < 0.3) leftness = 0.3; if(leftness <= 0.0 && leftness > -0.3) leftness = -0.3; if(rightness > 0.0 && rightness < 0.3) rightness = 0.3; if(rightness <= 0.0 && rightness > -0.3) rightness = -0.3; left += Bufs[a] * std::max(-0.5, leftness); right += Bufs[a] * std::max(-0.5, rightness); } #endif fwrite(&left, 2, 1, aout); fwrite(&right, 2, 1, aout); ++audioframeno; #ifdef LASTFRAME if(audioframeno/(RATE/60) >= LASTFRAME) break; #endif } for(unsigned a=0; a