7 #ifndef FF_INPUT_BUFFER_PADDING_SIZE
8 #define FF_INPUT_BUFFER_PADDING_SIZE 16
15 : _formatContext(AV_OPT_FLAG_ENCODING_PARAM)
18 , _previousProcessedStreamDuration(0.0)
49 memcpy(stream.codec->extradata, srcExtradata, srcExtradataSize);
56 av_reduce(&stream.codec->time_base.num, &stream.codec->time_base.den,
60 stream.time_base = stream.codec->time_base;
79 av_reduce(&stream.codec->time_base.num, &stream.codec->time_base.den, audioDesc.
getAVCodecContext().time_base.num,
102 std::stringstream msg;
103 msg <<
"Unable to get the stream ";
105 msg <<
": the OutputFile '";
107 msg <<
"' has only ";
110 throw std::runtime_error(msg.str());
171 LOG_DEBUG(
"Wrap on stream " << streamIndex <<
" (" << data.
getSize() <<
" bytes for frame "
176 av_init_packet(&packet);
177 packet.stream_index = streamIndex;
178 packet.data = (uint8_t*)data.
getData();
187 const AVRational& srcTimeBase = data.
getAVStream()->time_base;
190 packet.duration = av_rescale_q(data.
getAVPacket().duration, srcTimeBase, dstTimeBase);
193 packet.pts = av_rescale_q(data.
getAVPacket().pts, srcTimeBase, dstTimeBase);
195 packet.pts = AV_NOPTS_VALUE;
197 packet.dts = av_rescale_q(data.
getAVPacket().dts, srcTimeBase, dstTimeBase);
200 const int currentStreamPTS =
_outputStreams.at(streamIndex)->getStreamPTS();
201 if(packet.pts != AV_NOPTS_VALUE && packet.pts < currentStreamPTS)
203 packet.pts += currentStreamPTS;
204 packet.dts += currentStreamPTS;
210 const_cast<CodedData&
>(data).getAVPacket().duration = packet.duration;
215 const double currentStreamDuration =
_outputStreams.at(streamIndex)->getStreamDuration();
218 LOG_DEBUG(
"The output stream " << streamIndex <<
" is strictly shorter than the previous duration saved ("
220 <<
"s): wait for more data.")
241 for(PropertyVector::const_iterator it = data.begin(); it != data.end(); ++it)
258 const std::string msg(
"Invalid format profile to setup wrapping.");
260 throw std::runtime_error(msg);
265 LOG_INFO(
"Setup wrapping with:\n" << profile)
271 throw std::runtime_error(
"Invalid format according to the file extension.");
283 for(ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it)
294 catch(std::exception& e)
296 LOG_INFO(
"OutputFile - option " << (*it).first <<
" will be saved to be called when beginWrap")
297 _profile[(*it).first] = (*it).second;
305 for(ProfileLoader::Profile::const_iterator it =
_profile.begin(); it !=
_profile.end(); ++it)
316 catch(std::exception& e)
318 LOG_WARN(
"OutputFile - can't set option " << (*it).first <<
" to " << (*it).second <<
": " << e.what())
double _previousProcessedStreamDuration
To manage process streams order.
FormatContext _formatContext
std::vector< std::pair< std::string, std::string > > PropertyVector
PropertyVector is a vector of pair, because the order of properties matters to us.
void setString(const std::string &value)
void setupWrapping(const ProfileLoader::Profile &profile)
Set the format and the generic options of the output file.
size_t getNbStreams() const
unsigned char * getData()
void closeRessource()
Close the resource accessed by the AVIOContext and free it.
static bool checkFormatProfile(const Profile &profileToCheck)
const std::string avProfileFormat
std::string getFormatName() const
A comma separated list of short names for the format, or empty if unknown.
void setOutputFormat(const std::string &filename, const std::string &shortName="", const std::string &mimeType="")
AVOutputFormat & getAVOutputFormat() const
void addMetaData(const std::string &key, const std::string &value)
std::string getFormatMimeType() const
Comma-separated list of mime types, or empty if unknown.
EWrappingStatus
define wrapping result status
const AVStream * getAVStream() const
std::map< std::string, std::string > Profile
const std::string avProfileIdentificator
std::string getFilename() const
const std::string avProfileIdentificatorHuman
ProfileLoader::Profile _profile
To setup specific wrapping options.
IOutputStream & addAudioStream(const AudioCodec &audioDesc)
Add an audio output stream.
AVStream & addAVStream(const AVCodec &avCodec)
void setupWrappingOptions(const ProfileLoader::Profile &profile)
void writeTrailer()
Write the stream trailer to an output media file.
void writeHeader(AVDictionary **options=NULL)
Write the stream header to an output media file.
Wrapper of AVOption. Get its type to know what the option is about: Int, Double, Ratio, Choice... Parse its array of options to get the potential childs (Choice and Group).
IOutputStream::EWrappingStatus wrap(const CodedData &data, const size_t streamIndex)
Wrap a packet of data in the output ressource.
Option & getOption(const std::string &optionName)
std::string getFormatLongName() const
Descriptive name for the format, meant to be more human-readable than name, or empty if unknown...
std::vector< size_t > _frameCount
Number of wrapped frames.
OutputFile(const OutputFile &outputFile)
bool endWrap()
Close ressource and write trailer.
void writeFrame(AVPacket &packet, bool interleaved=true)
Write a packet to an output media file.
void setupRemainingWrappingOptions()
bool beginWrap()
Open ressource, write header, and setup specific wrapping options given when call setupWrapping...
AVCodecContext & getAVCodecContext()
This class describes coded data.
void addMetadata(const PropertyVector &data)
Add metadata to the output file.
void openRessource(const std::string &url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
#define FF_INPUT_BUFFER_PADDING_SIZE
AVFormatContext & getAVFormatContext() const
IOutputStream & getStream(const size_t streamIndex)
Get the output stream.
std::vector< OutputStream * > _outputStreams
Has ownership.
const std::string avProfileType
IOutputStream & addDataStream(const DataCodec &dataDesc)
Add a data output stream.
AVStream & getAVStream(size_t index) const
IOutputStream & addVideoStream(const VideoCodec &videoDesc)
Add a video output stream.
void setFilename(const std::string &filename)