x2avi.cc

 1 const char *help = "\
 2 progname: x2avi.cc\n\
 3 code2html: This program makes a video from any supported images.\n\
 4 version: Torch3 vision2.0, 2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "xtprobeImageDiskXFile.h"
 9 #include "ffmpegVideoFile.h"
10 #include "DiskXFile.h"
11 #include "FileListCmdOption.h"
12 #include "CmdLine.h"
13 
14 using namespace Torch;
15 
16 int main(int argc, char **argv)
17 {
18 	int width;
19 	int height;
20 	int fps;
21 	int bitrate;
22 	char *output_filename;
23 	bool verbose;
24 
25   	FileListCmdOption input_file_list("filename", "the list of inputs files or one data file");
26   	input_file_list.isArgument(true);
27 
28 	// Construct the command line
29   	CmdLine cmd;
30 	cmd.setBOption("write log", false);
31 	
32   	// Put the help line at the beginning
33   	cmd.info(help);
34 
35   	cmd.addText("\nArguments:");
36 	cmd.addCmdOption(&input_file_list);
37   	cmd.addICmdArg("width", &width, "width");
38   	cmd.addICmdArg("height", &height, "height");
39   	cmd.addText("\nOptions:");
40   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
41   	cmd.addICmdOption("-fps", &fps, 25, "verbose");
42   	cmd.addSCmdOption("-o", &output_filename, "output.avi", "verbose");
43   	cmd.addICmdOption("-bitrate", &bitrate, 1000000, "bitrate for encoding");
44 
45 	cmd.read(argc, argv);
46 
47 	VideoFile *video = NULL;
48 	video = new ffmpegVideoFile();
49         video->open(output_filename, "w");
50 	video->setIOption("width", width);
51 	video->setIOption("height", height);
52 	video->setROption("framerate", fps);
53 	video->setIOption("bitrate", bitrate);
54 
55 	Image *image = new ImageRgb(width, height);
56 	ImageDiskXFile *image_file = NULL;
57 		
58 	int nframes = input_file_list.n_files;
59 
60 	for(int i = 0 ; i < nframes ; i++)
61 	{   	
62 		image_file = new xtprobeImageDiskXFile(input_file_list.file_names[i], "r");
63 		image->loadImageXFile(image_file);
64 		delete image_file;
65 		
66 		if((image->width != width) || (image->height != height))
67 		{
68 			warning("error incorrect image size.");
69 			
70 			delete image;
71 			video->close();
72 			delete video;
73 
74 			return 1;
75 		}
76 		 
77 		if(verbose) print("r");
78 			
79 		video->write(image->pixmap);
80 		if(verbose) print("w");
81 
82 		real percent = 100.0 * (i+1) / nframes;
83 		print("%03d%\r", (int) percent);
84 	}
85 
86 	print("\n");
87 		
88 	video->close();
89 
90 	delete image;
91 	delete video;
92 
93 	return(0);
94 }