Transcode, limit output birate to the media bitrate (no need to upscale)
This commit is contained in:
+50
-16
@@ -1,3 +1,6 @@
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "av/InputFormatContext.hpp"
|
||||
|
||||
#include "Parameters.hpp"
|
||||
@@ -13,30 +16,61 @@ getMimeType(Format format)
|
||||
}
|
||||
|
||||
Parameters::Parameters(const InputMediaFile& inputMediaFile,
|
||||
const Format& outputFormat,
|
||||
std::size_t audioBitrate)
|
||||
const Format& outputFormat)
|
||||
:
|
||||
_mediaFile(inputMediaFile),
|
||||
_outputFormat(outputFormat),
|
||||
_outputAudioBitrate(audioBitrate),
|
||||
_outputVideoBitrate(0)
|
||||
_outputFormat(outputFormat)
|
||||
{
|
||||
// By default, select the best stream indexes
|
||||
_inputStreams = _mediaFile.getBestStreams();
|
||||
|
||||
// setBitrate(Stream::Audio, 0);
|
||||
// setBitrate(Stream::Video, 0);
|
||||
}
|
||||
|
||||
Parameters::Parameters(const InputMediaFile& inputMediaFile,
|
||||
const Format& outputFormat,
|
||||
std::size_t audioBitrate,
|
||||
std::size_t videoBitrate)
|
||||
:
|
||||
_mediaFile(inputMediaFile),
|
||||
_outputFormat(outputFormat),
|
||||
_outputAudioBitrate(audioBitrate),
|
||||
_outputVideoBitrate(videoBitrate)
|
||||
std::size_t
|
||||
Parameters::setBitrate(Stream::Type type, std::size_t bitrate)
|
||||
{
|
||||
// By default, select the best stream indexes
|
||||
_inputStreams = _mediaFile.getBestStreams();
|
||||
// Limit the output bitrate to the input bitrate
|
||||
if (_inputStreams.find(type) != _inputStreams.end())
|
||||
{
|
||||
const Transcode::Stream& stream = _mediaFile.getStream( _inputStreams[type] );
|
||||
|
||||
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Stream bitrate = " << stream.getBitrate();
|
||||
|
||||
if (!bitrate || bitrate > stream.getBitrate())
|
||||
{
|
||||
LMS_LOG(MOD_TRANSCODE, SEV_INFO) << "Setting bitrate for stream idx " << _inputStreams[type] << " to input bitrate (" << stream.getBitrate() << ")";
|
||||
_outputBitrate[type] = stream.getBitrate();
|
||||
}
|
||||
else
|
||||
{
|
||||
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Setting bitrate for stream idx " << _inputStreams[type] << " to " << bitrate;
|
||||
_outputBitrate[type] = bitrate;
|
||||
}
|
||||
return _outputBitrate[type];
|
||||
}
|
||||
else
|
||||
{
|
||||
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Cannot find stream type " << type;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t
|
||||
Parameters::getOutputBitrate(Stream::Type type) const
|
||||
{
|
||||
std::map<Stream::Type, std::size_t>::const_iterator it = _outputBitrate.find(type);
|
||||
|
||||
if (it != _inputStreams.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "output bitrate not set for type " << type;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Transcode
|
||||
|
||||
Reference in New Issue
Block a user