makeemptyavi.cc

 1 const char *help = "\
 2 progname: makeemptyavi.cc\n\
 3 code2html: This program makes an empty video with a given color.\n\
 4 version: Torch3 vision2.0, 2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "ffmpegVideoFile.h"
 9 #include "CmdLine.h"
10 
11 using namespace Torch;
12 
13 int main(int argc, char **argv)
14 {
15 	int width;
16 	int height;
17 	int nframes;
18 	int fps;
19 	int bitrate;
20 	char *output_filename;
21 	bool verbose;
22 	char *color_name;
23 
24 	// Construct the command line
25   	CmdLine cmd;
26 	cmd.setBOption("write log", false);
27 	
28   	// Put the help line at the beginning
29   	cmd.info(help);
30 
31   	cmd.addText("\nArguments:");
32   	cmd.addICmdArg("width", &width, "width");
33   	cmd.addICmdArg("height", &height, "height");
34   	cmd.addText("\nOptions:");
35   	cmd.addSCmdOption("-colorname", &color_name, "white", "color name");
36   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
37   	cmd.addICmdOption("-nframes", &nframes, 25, "number of frames");
38   	cmd.addICmdOption("-fps", &fps, 25, "frame rate");
39   	cmd.addICmdOption("-bitrate", &bitrate, 1000000, "bitrate for encoding");
40   	cmd.addSCmdOption("-o", &output_filename, "output.avi", "verbose");
41 
42 	cmd.read(argc, argv);
43 
44 	VideoFile *video = NULL;
45 	video = new ffmpegVideoFile();
46         video->open(output_filename, "w");
47 	video->setIOption("width", width);
48 	video->setIOption("height", height);
49 	video->setROption("framerate", fps);
50 	video->setIOption("bitrate", bitrate);
51 
52 	Color *color = new Color(color_name);
53 	Image *image = new ImageRgb(width, height);
54 		
55 	for(int i = 0 ; i < nframes ; i++)
56 	{   	
57 	   	for(int j = 0 ; j < width * height ; j++)
58 		{
59 			image->pixmap[j*3] = color->data0;
60 			image->pixmap[j*3+1] = color->data1;
61 			image->pixmap[j*3+2] = color->data2;
62 		}
63 		
64 		video->write(image->pixmap);
65 
66 		real percent = 100.0 * (i+1) / nframes;
67 		print("%03d%\r", (int) percent);
68 	}
69 
70 	print("\n");
71 		
72 	video->close();
73 
74 	delete image;
75 	delete color;
76 	delete video;
77 
78 	return(0);
79 }