UcbMpegOutputStream.C

Go to the documentation of this file.
00001 /*!@file Media/UcbMpegOutputStream.C Write mpeg video frames using mpeg_encode/ppmtompeg */
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/UcbMpegOutputStream.C $
00035 // $Id: UcbMpegOutputStream.C 8905 2007-10-25 23:21:41Z rjpeters $
00036 //
00037 
00038 #ifndef MEDIA_UCBMPEGOUTPUTSTREAM_C_DEFINED
00039 #define MEDIA_UCBMPEGOUTPUTSTREAM_C_DEFINED
00040 
00041 #include "Media/UcbMpegOutputStream.H"
00042 
00043 #include "Component/ModelOptionDef.H"
00044 #include "Media/UcbMpegEncoder.H"
00045 #include "Raster/GenericFrame.H"
00046 #include "Transport/TransportOpts.H"
00047 #include "Util/Assert.H"
00048 #include "Util/FileUtil.H"
00049 #include "Util/log.H"
00050 #include "rutz/shared_ptr.h"
00051 #include "rutz/trace.h"
00052 
00053 #include <map>
00054 #include <string>
00055 
00056 // Used by: OutputMPEGStream
00057 const ModelOptionDef OPT_UcbMpegFrameRate =
00058   { MODOPT_ARG(SimTime), "UcbMpegFrameRate", &MOC_OUTPUT, OPTEXP_CORE,
00059     "The frame rate, in frames-per-second, for ucb mpeg streams",
00060     "ucbmpeg-framerate", '\0',
00061     "<23.976, 24, 25, 29.97, 30, 50, 59.94, 60>Hz", "29.97Hz" };
00062 
00063 // Used by: OutputMPEGStream
00064 const ModelOptionDef OPT_UcbMpegQuality =
00065   { MODOPT_ARG_STRING, "UcbMpegQuality", &MOC_OUTPUT, OPTEXP_CORE,
00066     "The baseline quality settings for ucb mpeg streams (these "
00067     "settings may be further refined by additional command-line "
00068     "options)",
00069     "ucbmpeg-quality", '\0',
00070     "<basic|hq|superhq>", "basic" };
00071 
00072 // ######################################################################
00073 UcbMpegOutputStream::UcbMpegOutputStream(OptionManager& mgr,
00074                                    const std::string& descrName,
00075                                    const std::string& tagName)
00076   :
00077   LowLevelEncoderMap(mgr, descrName, tagName),
00078   itsFrameRate(&OPT_UcbMpegFrameRate, this),
00079   itsBaselineQuality(&OPT_UcbMpegQuality, this),
00080   itsStem()
00081 {}
00082 
00083 // ######################################################################
00084 void UcbMpegOutputStream::setConfigInfo(const std::string& filestem)
00085 {
00086   // NOTE: if you modify any behavior here, then please update the
00087   // corresponding documentation for the global "--out" option inside
00088   // the OPT_OutputFrameSink definition in Media/MediaOpts.C
00089 
00090   this->setFileStem(filestem);
00091 }
00092 
00093 // ######################################################################
00094 void UcbMpegOutputStream::setFileStem(const std::string& s)
00095 {
00096 GVX_TRACE(__PRETTY_FUNCTION__);
00097   itsStem = s;
00098 }
00099 
00100 // ######################################################################
00101 rutz::shared_ptr<LowLevelEncoder>
00102 UcbMpegOutputStream::makeEncoder(const GenericFrameSpec& spec,
00103                                  const std::string& shortname,
00104                                  const FrameInfo& auxinfo)
00105 {
00106   UcbMpegParams params;
00107 
00108   if (itsBaselineQuality.getVal().compare("basic") == 0)
00109     params = UcbMpegParams::basic();
00110   else if (itsBaselineQuality.getVal().compare("hq") == 0)
00111     params = UcbMpegParams::hq();
00112   else if (itsBaselineQuality.getVal().compare("superhq") == 0)
00113     params = UcbMpegParams::superhq();
00114   else
00115     LFATAL("invalid setting for --ucbmpeg-quality: %s",
00116            itsBaselineQuality.getVal().c_str());
00117 
00118   std::string fname = itsStem + shortname;
00119 
00120   if (!hasExtension(fname, ".mpg") &&
00121       !hasExtension(fname, ".mpeg"))
00122     fname += ".mpg";
00123 
00124 #ifndef MPEGENCODE_PROG
00125   LFATAL("MPEGENCODE_PROG is undefined (the configure script "
00126          "did not find an mpeg_encode or ppmtompeg program)");
00127   /* can't happen */ return rutz::shared_ptr<LowLevelEncoder>();
00128 #else
00129 
00130   // NOTE: for now, we just ignore the FrameInfo auxinfo here; could
00131   // we use it to embed a comment in the mpeg file, though?
00132 
00133   return rutz::shared_ptr<LowLevelEncoder>
00134     (new UcbMpegEncoder(MPEGENCODE_PROG, fname, params,
00135                         itsFrameRate.getVal().hertz()));
00136 #endif
00137 }
00138 
00139 // ######################################################################
00140 /* So things look consistent in everyone's emacs... */
00141 /* Local Variables: */
00142 /* mode: c++ */
00143 /* indent-tabs-mode: nil */
00144 /* End: */
00145 
00146 #endif // MEDIA_UCBMPEGOUTPUTSTREAM_C_DEFINED
Generated on Sun May 8 08:41:01 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3