Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/AvTranscoder/properties/StreamProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@ StreamProperties::StreamProperties(const FormatContext& formatContext, const siz
_codecContext = _formatContext->streams[_streamIndex]->codec;
}

// find the decoder
if(_formatContext && _codecContext)
{
_codec = avcodec_find_decoder(_codecContext->codec_id);

if(_codec)
{
// load specific options of the codec
if(avcodec_open2(_codecContext, _codec, NULL) == 0)
{
loadOptions(_options, _codecContext);
avcodec_close(_codecContext);
}
}
}
}

StreamProperties::~StreamProperties()
Expand Down Expand Up @@ -98,6 +111,16 @@ std::string StreamProperties::getCodecLongName() const
return std::string(_codec->long_name);
}

std::vector<Option> StreamProperties::getCodecOptions()
{
std::vector<Option> optionsArray;
for(OptionMap::iterator it = _options.begin(); it != _options.end(); ++it)
{
optionsArray.push_back(it->second);
}
return optionsArray;
}

PropertyVector StreamProperties::asVector() const
{
PropertyVector propertyVector;
Expand Down
14 changes: 14 additions & 0 deletions src/AvTranscoder/properties/StreamProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _AV_TRANSCODER_MEDIA_PROPERTY_STREAM_PROPERTIES_HPP

#include <AvTranscoder/common.hpp>
#include <AvTranscoder/Option.hpp>
#include <AvTranscoder/properties/util.hpp>
#include <AvTranscoder/file/FormatContext.hpp>

Expand All @@ -27,6 +28,17 @@ class AvExport StreamProperties

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

/**
* @return The list of private codec options.
* @see getOptionsMap
* @see getOption
*/
OptionArray getCodecOptions();
#ifndef SWIG
OptionMap& getCodecOptionsMap() { return _options; } ///< Get options as map
#endif
Option& getCodecOption(const std::string& optionName) { return _options.at(optionName); }

#ifndef SWIG
const AVFormatContext& getAVFormatContext() const { return *_formatContext; }
#endif
Expand Down Expand Up @@ -59,6 +71,8 @@ class AvExport StreamProperties

size_t _streamIndex;
PropertyVector _metadatas;

OptionMap _options;
};

#ifndef SWIG
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/properties/VideoProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ size_t VideoProperties::getBitRate() const
throw std::runtime_error("cannot compute bit rate: invalid frame size");

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

// discard no frame type when decode
Expand Down Expand Up @@ -509,7 +509,7 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
positionOfLastKeyFrame = count;
}

++count;
_gopSize = ++count;
}
}
av_free_packet(&pkt);
Expand Down