@@ -15,7 +15,10 @@ OutputFile::OutputFile( const std::string& filename )
15
15
, _filename( filename )
16
16
, _previousProcessedStreamDuration( 0.0 )
17
17
, _verbose( false )
18
- {}
18
+ {
19
+ _formatContext.setOutputFormat ( _filename );
20
+ _formatContext.openRessource ( _filename, AVIO_FLAG_WRITE );
21
+ }
19
22
20
23
OutputFile::~OutputFile ()
21
24
{
@@ -25,13 +28,6 @@ OutputFile::~OutputFile()
25
28
}
26
29
}
27
30
28
- bool OutputFile::setup ()
29
- {
30
- _formatContext.setOutputFormat ( _filename );
31
- _formatContext.openRessource ( _filename, AVIO_FLAG_WRITE );
32
- return true ;
33
- }
34
-
35
31
IOutputStream& OutputFile::addVideoStream ( const VideoCodec& videoDesc )
36
32
{
37
33
AVStream& stream = _formatContext.addAVStream ( videoDesc.getAVCodec () );
@@ -157,32 +153,16 @@ void OutputFile::addMetadata( const std::string& key, const std::string& value )
157
153
158
154
void OutputFile::setProfile ( const ProfileLoader::Profile& profile )
159
155
{
156
+ // check if output format indicated is valid with the filename extension
160
157
if ( ! matchFormat ( profile.find ( constants::avProfileFormat )->second , _filename ) )
161
158
{
162
159
throw std::runtime_error ( " Invalid format according to the file extension." );
163
160
}
164
-
161
+
162
+ // set output format
165
163
_formatContext.setOutputFormat ( _filename, profile.find ( constants::avProfileFormat )->second );
166
-
167
- for ( ProfileLoader::Profile::const_iterator it = profile.begin (); it != profile.end (); ++it )
168
- {
169
- if ( (*it).first == constants::avProfileIdentificator ||
170
- (*it).first == constants::avProfileIdentificatorHuman ||
171
- (*it).first == constants::avProfileType ||
172
- (*it).first == constants::avProfileFormat )
173
- continue ;
174
-
175
- try
176
- {
177
- Option& formatOption = _formatContext.getOption ( (*it).first );
178
- formatOption.setString ( (*it).second );
179
- }
180
- catch ( std::exception& e )
181
- {}
182
- }
183
-
184
- setup ();
185
-
164
+
165
+ // set format options
186
166
for ( ProfileLoader::Profile::const_iterator it = profile.begin (); it != profile.end (); ++it )
187
167
{
188
168
if ( (*it).first == constants::avProfileIdentificator ||
@@ -198,8 +178,7 @@ void OutputFile::setProfile( const ProfileLoader::Profile& profile )
198
178
}
199
179
catch ( std::exception& e )
200
180
{
201
- if ( _verbose )
202
- std::cout << " [OutputFile] warning - can't set option " << (*it).first << " to " << (*it).second << " : " << e.what () << std::endl;
181
+ std::cout << " [OutputFile] warning - can't set option " << (*it).first << " to " << (*it).second << " : " << e.what () << std::endl;
203
182
}
204
183
}
205
184
}
0 commit comments