aviduration.cc

 1 const char *help = "\
 2 progname: aviduration.cc\n\
 3 code2html: This program reads a video file and returns the duration in seconds.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "rgbRawVideoFile.h"
 8 #include "ffmpegVideoFile.h"
 9 #include "CmdLine.h"
10 
11 using namespace Torch;
12 
13 int main(int argc, char **argv)
14 {
15 	char *input_filename;
16 	bool verbose;
17 	bool ffmpeg;
18 
19 	// Construct the command line
20   	CmdLine cmd;
21 	cmd.setBOption("write log", false);
22 	
23   	// Put the help line at the beginning
24   	cmd.info(help);
25 
26   	cmd.addText("\nArguments:");
27   	cmd.addSCmdArg("input filename", &input_filename, "video filename");
28   	cmd.addText("\nOptions:");
29   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
30   	cmd.addBCmdOption("-ffmpeg", &ffmpeg, false, "ffmpeg");
31 
32 	cmd.read(argc, argv);
33 
34 	VideoFile *video = NULL;
35 
36 	if(ffmpeg) video = new ffmpegVideoFile();
37 	else video = new rgbRawVideoFile();
38 
39 	int duration = 0;
40 
41 	if(video->open(input_filename) == true)
42 	{
43 		int width = video->getwidth();
44 		int height = video->getheight();
45 		real fps = video->getframerate();
46 		real brate = video->getbitrate();
47 		int nframes = video->getnframes();
48 		char *codec = video->getcodec();
49 
50 		duration = (int) (nframes / fps);
51 
52 		if(verbose)
53 		{
54 			print("width = %d\n", width);
55 			print("height = %d\n", height);
56 			print("nframes = %d\n", nframes);
57 			print("fps = %g\n", fps);
58 			print("bitrate = %g\n", brate);
59 			print("duration = %d\n", duration);
60 			print("codec = [%s]\n", ((strlen(codec)==0)? "RGB": codec));
61 		}
62 
63 		video->close();
64 	}
65 
66 	delete video;
67 
68 	exit(duration);
69 }