video_recorder.cpp
Go to the documentation of this file.
00001 /* This file is part of the Pangolin Project.
00002  * http://github.com/stevenlovegrove/Pangolin
00003  *
00004  * Copyright (c) 2011 Steven Lovegrove
00005  *
00006  * Permission is hereby granted, free of charge, to any person
00007  * obtaining a copy of this software and associated documentation
00008  * files (the "Software"), to deal in the Software without
00009  * restriction, including without limitation the rights to use,
00010  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following
00013  * conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be
00016  * included in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00020  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00021  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00022  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00023  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  * OTHER DEALINGS IN THE SOFTWARE.
00026  */
00027 
00028 #include "video_recorder.h"
00029 
00030 using namespace std;
00031 
00032 namespace pangolin
00033 {
00034 
00035 VideoRecorder::VideoRecorder(
00036     const std::string& filename,
00037     int stream0_width, int stream0_height, std::string stream0_fmt,
00038     unsigned int buffer_size_bytes
00039 ) : frames(0), buffer(filename, buffer_size_bytes), writer(&buffer)
00040 {
00041     VideoStream strm0;
00042     strm0.name = "main";
00043     strm0.w = stream0_width;
00044     strm0.h = stream0_height;
00045     strm0.fmt = VideoFormatFromString(stream0_fmt);
00046     strm0.frame_size_bytes = (strm0.w * strm0.h * strm0.fmt.bpp) / 8;
00047 
00048     stream_info.push_back(strm0);
00049 }
00050 
00051 VideoRecorder::~VideoRecorder()
00052 {
00053 }
00054 
00055 void VideoRecorder::WriteFileHeader()
00056 {
00057     writer << stream_info[0].fmt.format << "\n";
00058     writer << stream_info[0].w  << "\n";
00059     writer << stream_info[0].h  << "\n";
00060     writer << "30.0\n";
00061 }
00062 
00063 int VideoRecorder::RecordFrame(void* img)
00064 {
00065     if( stream_info.size() != 1 )
00066         throw VideoRecorderException("Incorrect number of frames specified");
00067 
00068     if(frames==0)
00069         WriteFileHeader();
00070 
00071     const VideoStream& strm = stream_info[0];
00072 
00073     writer.write((char*)img,strm.frame_size_bytes);
00074 
00075     return frames++;
00076 }
00077 
00078 }
 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