Skip to content

VideoProperties: extract min and max bitrate from side data #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2022
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
7 changes: 5 additions & 2 deletions src/AvTranscoder/properties/StreamProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ StreamProperties::StreamProperties(const FileProperties& fileProperties, const s
throw std::runtime_error(ss.str());
}

_codec = avcodec_find_decoder(_formatContext->streams[_streamIndex]->codecpar->codec_id);
AVStream* stream = _formatContext->streams[_streamIndex];
_codec = avcodec_find_decoder(stream->codecpar->codec_id);
_codecContext = avcodec_alloc_context3(_codec);

avcodec_parameters_to_context(_codecContext, _formatContext->streams[_streamIndex]->codecpar);
avcodec_parameters_to_context(_codecContext, stream->codecpar);
_codecContext->time_base = stream->time_base;
_codecContext->coded_side_data = stream->side_data;
}

// find the decoder
Expand Down
16 changes: 16 additions & 0 deletions src/AvTranscoder/properties/VideoProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,29 @@ size_t VideoProperties::getMaxBitRate() const
{
if(!_codecContext)
throw std::runtime_error("unknown codec context");

if (_codecContext->rc_max_rate == 0
&& _codecContext->coded_side_data
&& _codecContext->coded_side_data->type == AV_PKT_DATA_CPB_PROPERTIES) {
const AVCPBProperties* prop = (AVCPBProperties*) _codecContext->coded_side_data->data;
return prop->max_bitrate;
}

return _codecContext->rc_max_rate;
}

size_t VideoProperties::getMinBitRate() const
{
if(!_codecContext)
throw std::runtime_error("unknown codec context");

if (_codecContext->rc_max_rate == 0
&& _codecContext->coded_side_data
&& _codecContext->coded_side_data->type == AV_PKT_DATA_CPB_PROPERTIES) {
const AVCPBProperties* prop = (AVCPBProperties*) _codecContext->coded_side_data->data;
return prop->min_bitrate;
}

return _codecContext->rc_min_rate;
}

Expand Down