main.cpp
Go to the documentation of this file.
00001 
00007 #include <pangolin/pangolin.h>
00008 #include <pangolin/video.h>
00009 #include <pangolin/video_recorder.h>
00010 
00011 using namespace pangolin;
00012 using namespace std;
00013 
00014 void RecordSample(const std::string uri, const std::string filename)
00015 {
00016     // Setup Video Source
00017     VideoInput video(uri);
00018     VideoPixelFormat vid_fmt = VideoFormatFromString(video.PixFormat());
00019     const unsigned w = video.Width();
00020     const unsigned h = video.Height();
00021 
00022     // Setup async video recorder with 50 frame memory buffer
00023     VideoRecorder recorder(filename, w, h, vid_fmt.format, video.SizeBytes()*50 );
00024 
00025     // Create Glut window
00026     pangolin::CreateGlutWindowAndBind("Main",w,h);
00027 
00028     // Create viewport for video with fixed aspect
00029     View& vVideo = Display("Video").SetAspect((float)w/h);
00030 
00031     // OpenGl Texture for video frame
00032     GlTexture texVideo(w,h,GL_RGBA8);
00033 
00034     unsigned char* img = new unsigned char[video.SizeBytes()];
00035 
00036     while( !pangolin::ShouldQuit() )
00037     {
00038         glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
00039 
00040         if( video.GrabNext(img,true) )
00041         {
00042             // Upload to GPU as texture for display
00043             texVideo.Upload(img, vid_fmt.channels==1 ? GL_LUMINANCE:GL_RGB, GL_UNSIGNED_BYTE);
00044 
00045             // Record video frame
00046             recorder.RecordFrame(img);
00047         }
00048 
00049         // Activate video viewport and render texture
00050         vVideo.Activate();
00051         texVideo.RenderToViewportFlipY();
00052 
00053         // Swap back buffer with front and process window events via GLUT
00054         pangolin::FinishGlutFrame();
00055     }
00056 
00057     delete[] img;
00058 }
00059 
00060 int main( int argc, char* argv[] )
00061 {
00062     std::string uris[] = {
00063         "dc1394:[fps=30,dma=10,size=640x480,iso=400]//0",
00064         "convert:[fmt=RGB24]//v4l:///dev/video0",
00065         "convert:[fmt=RGB24]//v4l:///dev/video1",
00066         ""
00067     };
00068 
00069     std::string filename = "video.pvn";
00070 
00071     if( argc >= 2 ) {
00072         const string uri = std::string(argv[1]);
00073         if( argc == 3 ) {
00074             filename = std::string(argv[2]);
00075         }
00076         RecordSample(uri, filename);
00077     }else{
00078         cout << "Usage  : SimpleRecord [video-uri] [output-filename]" << endl << endl;
00079         cout << "Where video-uri describes a stream or file resource, e.g." << endl;
00080         cout << "\tfile:[realtime=1]///home/user/video/movie.pvn" << endl;
00081         cout << "\tfile:///home/user/video/movie.avi" << endl;
00082         cout << "\tfiles:///home/user/seqiemce/foo%03d.jpeg" << endl;
00083         cout << "\tdc1394:[fmt=RGB24,size=640x480,fps=30,iso=400,dma=10]//0" << endl;
00084         cout << "\tdc1394:[fmt=FORMAT7_1,size=640x480,pos=2+2,iso=400,dma=10]//0" << endl;
00085         cout << "\tv4l:///dev/video0" << endl;
00086         cout << "\tconvert:[fmt=RGB24]//v4l:///dev/video0" << endl;
00087         cout << "\tmjpeg://http://127.0.0.1/?action=stream" << endl;
00088         cout << endl;
00089 
00090         // Try to open some video device
00091         for(int i=0; !uris[i].empty(); ++i )
00092         {
00093             try{
00094                 cout << "Trying: " << uris[i] << endl;
00095                 RecordSample(uris[i], filename);
00096                 return 0;
00097             }catch(VideoException) {}
00098         }
00099     }
00100 
00101     return 0;
00102 
00103 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


pangolin_wrapper
Author(s): Todor Stoyanov
autogenerated on Wed Feb 13 2013 14:03:25