00001 /*!@file Media/UcbMpegEncoder.H Thin c++ wrapper around 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/UcbMpegEncoder.H $ 00035 // $Id: UcbMpegEncoder.H 8903 2007-10-25 22:56:57Z rjpeters $ 00036 // 00037 00038 #ifndef MEDIA_UCBMPEGENCODER_H_DEFINED 00039 #define MEDIA_UCBMPEGENCODER_H_DEFINED 00040 00041 #include "Image/Dims.H" 00042 #include "Transport/LowLevelEncoder.H" 00043 #include "Video/VideoFormat.H" 00044 00045 #include <string> 00046 00047 class VideoFrame; 00048 00049 namespace rutz { class bidir_pipe; } 00050 00051 struct UcbMpegParams 00052 { 00053 /// Get standard default encoding params 00054 static UcbMpegParams basic(); 00055 00056 /// Get high-quality encoding params 00057 static UcbMpegParams hq(); 00058 00059 /// Get super-high-quality encoding params 00060 static UcbMpegParams superhq(); 00061 00062 const char* PATTERN; //!< e.g. "IBBPBBPBBPBBPBB" 00063 int GOP_SIZE; //!< e.g. 30; group-of-pictures; multiple of PATTERN length 00064 int SLICES_PER_FRAME; //!< e.g. 1; must divide evenly into SIZE.h() 00065 const char* PIXEL; //!< either "HALF" or "FULL" 00066 int RANGE; //!< e.g. 10; search radius 00067 const char* PSEARCH_ALG; //!< ["LOGARITHMIC"], "EXHAUSTIVE", "TWOLEVEL", "SUBSAMPLE" 00068 const char* BSEARCH_ALG; //!< ["CROSS2"], "SIMPLE", "EXHAUSTIVE" 00069 int IQSCALE; //!< quality scale for I-frames; best quality == 1 00070 int PQSCALE; //!< quality scale for P-frames; best quality == 1 00071 int BQSCALE; //!< quality scale for B-frames; best quality == 1 00072 const char* REFERENCE_FRAME; //!< ["DECODED"], "ORIGINAL" 00073 }; 00074 00075 /// Thin c++ wrapper around mpeg_encode/ppmtompeg 00076 /** The implementation opens a pipe to an mpeg_encode or ppmtompeg 00077 subprocess, using the "INPUT_DIR stdin" configuration option, and 00078 sends frames over the pipe to be encoded into the resulting mpeg 00079 file. 00080 00081 Ucb stands for "University of California-Berkeley", where 00082 mpeg_encode was originally written. 00083 */ 00084 class UcbMpegEncoder : public LowLevelEncoder 00085 { 00086 public: 00087 /// Construct an encoder 00088 /** @param exename full path to the mpeg_encode or ppmtompeg 00089 executable */ 00090 UcbMpegEncoder(const std::string& exename, 00091 const std::string& outname, 00092 const UcbMpegParams& params, 00093 const double framerate = 29.97 /* Hz */); 00094 00095 ~UcbMpegEncoder(); 00096 00097 virtual int close(); 00098 00099 void writeVideoFrame(const VideoFrame& f); 00100 00101 virtual void writeFrame(const GenericFrame& f); 00102 00103 private: 00104 UcbMpegEncoder(const UcbMpegEncoder&); // not implemented 00105 UcbMpegEncoder& operator=(const UcbMpegEncoder&); // not implemented 00106 00107 void makeParmsFile(const VideoFrame& f); 00108 00109 std::string itsExeName; 00110 std::string itsOutFname; 00111 UcbMpegParams itsParams; 00112 std::string itsParamFname; 00113 double itsFrameRate; //!< 23.976, 24, 25, 29.97, 30, 50, 59.94, 60 Hz 00114 VideoFormat itsVideoFormat; 00115 rutz::bidir_pipe* itsSubprocess; 00116 Dims itsDims; 00117 }; 00118 00119 // ###################################################################### 00120 /* So things look consistent in everyone's emacs... */ 00121 /* Local Variables: */ 00122 /* mode: c++ */ 00123 /* indent-tabs-mode: nil */ 00124 /* End: */ 00125 00126 #endif // MEDIA_UCBMPEGENCODER_H_DEFINED