00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00060
00061
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
00068 const ModelOptionDef OPT_OutputMPEGStreamBitRate =
00069 { MODOPT_ARG(int), "OutputMPEGStreamBitRate", &MOC_OUTPUT, OPTEXP_CORE,
00070 "The bit rate for output mpeg streams",
00071
00072
00073 "output-mpeg-bitrate", '\0', "<bits-per-?>", "750000" };
00074
00075
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
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
00118
00119
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
00143
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
00160
00161
00162
00163
00164
00165 #endif // MEDIA_MPEGOUTPUTSTREAM_C_DEFINED