Skip to content

Commit 31a3f01

Browse files
committed
Merge pull request #250 from cchampet/dev_propertiesGetCodecPrivateOptions
StreamProperties: added list of private codec options
2 parents 7ed9558 + 34859e3 commit 31a3f01

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/AvTranscoder/properties/StreamProperties.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,21 @@ StreamProperties::StreamProperties(const FormatContext& formatContext, const siz
2828
_codecContext = _formatContext->streams[_streamIndex]->codec;
2929
}
3030

31+
// find the decoder
3132
if(_formatContext && _codecContext)
33+
{
3234
_codec = avcodec_find_decoder(_codecContext->codec_id);
35+
36+
if(_codec)
37+
{
38+
// load specific options of the codec
39+
if(avcodec_open2(_codecContext, _codec, NULL) == 0)
40+
{
41+
loadOptions(_options, _codecContext);
42+
avcodec_close(_codecContext);
43+
}
44+
}
45+
}
3346
}
3447

3548
StreamProperties::~StreamProperties()
@@ -98,6 +111,16 @@ std::string StreamProperties::getCodecLongName() const
98111
return std::string(_codec->long_name);
99112
}
100113

114+
std::vector<Option> StreamProperties::getCodecOptions()
115+
{
116+
std::vector<Option> optionsArray;
117+
for(OptionMap::iterator it = _options.begin(); it != _options.end(); ++it)
118+
{
119+
optionsArray.push_back(it->second);
120+
}
121+
return optionsArray;
122+
}
123+
101124
PropertyVector StreamProperties::asVector() const
102125
{
103126
PropertyVector propertyVector;

src/AvTranscoder/properties/StreamProperties.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _AV_TRANSCODER_MEDIA_PROPERTY_STREAM_PROPERTIES_HPP
33

44
#include <AvTranscoder/common.hpp>
5+
#include <AvTranscoder/Option.hpp>
56
#include <AvTranscoder/properties/util.hpp>
67
#include <AvTranscoder/file/FormatContext.hpp>
78

@@ -27,6 +28,17 @@ class AvExport StreamProperties
2728

2829
const PropertyVector& getMetadatas() const { return _metadatas; }
2930

31+
/**
32+
* @return The list of private codec options.
33+
* @see getOptionsMap
34+
* @see getOption
35+
*/
36+
OptionArray getCodecOptions();
37+
#ifndef SWIG
38+
OptionMap& getCodecOptionsMap() { return _options; } ///< Get options as map
39+
#endif
40+
Option& getCodecOption(const std::string& optionName) { return _options.at(optionName); }
41+
3042
#ifndef SWIG
3143
const AVFormatContext& getAVFormatContext() const { return *_formatContext; }
3244
#endif
@@ -59,6 +71,8 @@ class AvExport StreamProperties
5971

6072
size_t _streamIndex;
6173
PropertyVector _metadatas;
74+
75+
OptionMap _options;
6276
};
6377

6478
#ifndef SWIG

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ size_t VideoProperties::getBitRate() const
334334
throw std::runtime_error("cannot compute bit rate: invalid frame size");
335335

336336
// Needed to get the gop size
337-
if(_levelAnalysis < eAnalyseLevelFirstGop)
337+
if(getGopSize() == 0)
338338
throw std::runtime_error("cannot compute bit rate: need to get info from the first gop (see eAnalyseLevelFirstGop)");
339339

340340
// discard no frame type when decode
@@ -509,7 +509,7 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
509509
positionOfLastKeyFrame = count;
510510
}
511511

512-
++count;
512+
_gopSize = ++count;
513513
}
514514
}
515515
av_free_packet(&pkt);

0 commit comments

Comments
 (0)