ppm2avi.cc

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