Skip to content

Commit 141139f

Browse files
author
Clement Champetier
committed
FormatContext: load options specific to the format when muxing
* This need to be done after call of avformat_write_header. * Add attribute _flags. * Fix #92
1 parent 6f7f62d commit 141139f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace avtranscoder
88

99
FormatContext::FormatContext( const std::string& filename, int req_flags, AVDictionary** options )
1010
: _avFormatContext( NULL )
11+
, _flags( req_flags )
1112
, _options()
1213
, _isOpen( false )
1314
{
@@ -29,6 +30,7 @@ FormatContext::FormatContext( const std::string& filename, int req_flags, AVDict
2930

3031
FormatContext::FormatContext( int req_flags )
3132
: _avFormatContext( NULL )
33+
, _flags( req_flags )
3234
, _options()
3335
, _isOpen( false )
3436
{
@@ -88,6 +90,8 @@ void FormatContext::writeHeader( AVDictionary** options )
8890
{
8991
throw std::runtime_error( "could not write header: " + getDescriptionFromErrorCode( ret ) );
9092
}
93+
// when muxing, priv_data of AVFormatContext is set by avformat_write_header()
94+
loadOptions( _options, _avFormatContext->priv_data, _flags );
9195
}
9296

9397
void FormatContext::writeFrame( AVPacket& packet, bool interleaved )

src/AvTranscoder/file/FormatContext.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ class AvExport FormatContext
5151
*/
5252
void closeRessource();
5353

54-
void writeHeader( AVDictionary** options = NULL ); ///< Write the stream header to an output media file
54+
/**
55+
* @brief Write the stream header to an output media file
56+
* @note Also load options specific to the output format
57+
*/
58+
void writeHeader( AVDictionary** options = NULL );
5559

5660
/**
5761
* @brief Write a packet to an output media file
@@ -106,6 +110,7 @@ class AvExport FormatContext
106110

107111
private:
108112
AVFormatContext* _avFormatContext; ///< Has ownership
113+
const int _flags; ///< Flags with which the options are loaded (see AV_OPT_FLAG_xxx)
109114
OptionMap _options;
110115
bool _isOpen; ///< Is the AVFormatContext open (in constructor with a filename)
111116
};

0 commit comments

Comments
 (0)