MpegOutputStream.C

Go to the documentation of this file.
00001 /*!@file Media/MpegOutputStream.C Write frames to movie files */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Media/MpegOutputStream.C $
00035 // $Id: MpegOutputStream.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #ifndef MEDIA_MPEGOUTPUTSTREAM_C_DEFINED
00039 #define MEDIA_MPEGOUTPUTSTREAM_C_DEFINED
00040 
00041 #include "Media/MpegOutputStream.H"
00042 
00043 #ifdef INVT_HAVE_AVCODEC
00044 
00045 #include "Component/ModelOptionDef.H"
00046 #include "Image/Image.H"
00047 #include "Image/Pixels.H"
00048 #include "Media/FfmpegEncoder.H"
00049 #include "Raster/GenericFrame.H"
00050 #include "Transport/TransportOpts.H"
00051 #include "Util/Assert.H"
00052 #include "Util/log.H"
00053 #include "rutz/shared_ptr.h"
00054 #include "rutz/trace.h"
00055 
00056 #include <map>
00057 #include <string>
00058 
00059 // private command-line option defs
00060 
00061 // Used by: OutputMPEGStream
00062 const ModelOptionDef OPT_OutputMPEGStreamFrameRate =
00063   { MODOPT_ARG(int), "OutputMPEGStreamFrameRate", &MOC_OUTPUT, OPTEXP_CORE,
00064     "The frame rate, in frames-per-second, for output mpeg streams",
00065     "output-mpeg-framerate", '\0', "<frames-per-second>", "25" };
00066 
00067 // Used by: OutputMPEGStream
00068 const ModelOptionDef OPT_OutputMPEGStreamBitRate =
00069   { MODOPT_ARG(int), "OutputMPEGStreamBitRate", &MOC_OUTPUT, OPTEXP_CORE,
00070     "The bit rate for output mpeg streams",
00071     // FIXME it's not clear from the ffmpeg docs whether the bitrate
00072     // is bits-per-second or bits-per-frame
00073     "output-mpeg-bitrate", '\0', "<bits-per-?>", "750000" };
00074 
00075 // Used by: OutputMPEGStream
00076 const ModelOptionDef OPT_OutputMPEGStreamBufSize =
00077   { MODOPT_ARG(ByteCount), "OutputMPEGStreamBufSize", &MOC_OUTPUT, OPTEXP_CORE,
00078     "The size, in bytes, of the per-frame output buffer for output "
00079     "mpeg streams (you can try increasing the buffer size if you "
00080     "are seeing warnings like 'encoded frame too large')",
00081     "output-mpeg-bufsize", '\0', "<bytes>", "2MiB" };
00082 
00083 // Used by: OutputMPEGStream
00084 static const ModelOptionDef OPT_OutputMPEGStreamCodec =
00085   { MODOPT_ARG_STRING, "OutputMPEGStreamCodec", &MOC_OUTPUT, OPTEXP_CORE,
00086     "Type of video output codec to use (use value 'List' to see list of "
00087     "available codecs on your system)",
00088     "output-codec", '\0', "<List|name>", "mpeg1video" };
00089 
00090 static const ModelOptionDef OPT_OutputMPEGUseFormatContext =
00091   { MODOPT_ARG(bool), "OutputMPEGUseFormatContext", &MOC_OUTPUT, OPTEXP_CORE,
00092                 "Whether to use the ffmpeg FormatContext when outputing stream data "
00093                 "to the file. If this option is false, then the raw data from the codec "
00094                 "is written directly to the file. Otherwise, the data goes through the "
00095                 "ffmpeg calls to write the data. This is used when one needs header and "
00096                 "frame information especially for codecs like flv)",
00097     "output-useFormatContext", '\0', "<true|false>", "false" };
00098 
00099 // ######################################################################
00100 OutputMPEGStream::OutputMPEGStream(OptionManager& mgr,
00101                                    const std::string& descrName,
00102                                    const std::string& tagName)
00103   :
00104   LowLevelEncoderMap(mgr, descrName, tagName),
00105   itsFrameRate(&OPT_OutputMPEGStreamFrameRate, this),
00106   itsFrameRateBase(tagName+"FrameRateBase", this, 1),
00107   itsBitRate(&OPT_OutputMPEGStreamBitRate, this),
00108   itsBufSize(&OPT_OutputMPEGStreamBufSize, this),
00109   itsCodecName(&OPT_OutputMPEGStreamCodec, this),
00110   itsUseFormatContext(&OPT_OutputMPEGUseFormatContext, this),
00111   itsStem()
00112 {}
00113 
00114 // ######################################################################
00115 void OutputMPEGStream::setConfigInfo(const std::string& filestem)
00116 {
00117   // NOTE: if you modify any behavior here, then please update the
00118   // corresponding documentation for the global "--out" option inside
00119   // the OPT_OutputFrameSink definition in Media/MediaOpts.C
00120 
00121   this->setFileStem(filestem);
00122 }
00123 
00124 // ######################################################################
00125 void OutputMPEGStream::setFileStem(const std::string& s)
00126 {
00127 GVX_TRACE(__PRETTY_FUNCTION__);
00128   itsStem = s;
00129 }
00130 
00131 
00132 #include "Media/MediaOpts.H"
00133 #include "Media/FrameRange.H"
00134 #include "Component/ModelManager.H"
00135 
00136 // ######################################################################
00137 rutz::shared_ptr<LowLevelEncoder>
00138 OutputMPEGStream::makeEncoder(const GenericFrameSpec& spec,
00139                               const std::string& shortname,
00140                               const FrameInfo& auxinfo)
00141 {
00142   // NOTE: for now, we just ignore the FrameInfo auxinfo here; could
00143   // we use it to embed a comment in the mpeg file, though?
00144 
00145   return rutz::shared_ptr<FfmpegEncoder>
00146     (new FfmpegEncoder(itsStem+shortname,
00147                        itsCodecName.getVal(),
00148                        itsBitRate.getVal(),
00149                        itsFrameRate.getVal(),
00150                        itsFrameRateBase.getVal(),
00151                        spec.dims,
00152                        itsBufSize.getVal().bytes(),
00153                                                                                          itsUseFormatContext.getVal()));
00154 }
00155 
00156 #endif // HAVE_FFMPEG_AVCODEC_H
00157 
00158 // ######################################################################
00159 /* So things look consistent in everyone's emacs... */
00160 /* Local Variables: */
00161 /* mode: c++ */
00162 /* indent-tabs-mode: nil */
00163 /* End: */
00164 
00165 #endif // MEDIA_MPEGOUTPUTSTREAM_C_DEFINED
Generated on Sun May 8 08:05:20 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3