Fixed bitrate detection for av parser
This commit is contained in:
@@ -101,12 +101,14 @@ namespace Av
|
|||||||
return _p;
|
return _p;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::milliseconds AudioFile::getDuration() const
|
ContainerInfo AudioFile::getContainerInfo() const
|
||||||
{
|
{
|
||||||
if (_context->duration == AV_NOPTS_VALUE)
|
ContainerInfo info;
|
||||||
return std::chrono::milliseconds{ 0 }; // TODO estimate
|
info.bitrate = _context->bit_rate;
|
||||||
|
info.duration = std::chrono::milliseconds{ _context->duration == AV_NOPTS_VALUE ? 0 : _context->duration / AV_TIME_BASE * 1000 };
|
||||||
|
info.name = _context->iformat->name;
|
||||||
|
|
||||||
return std::chrono::milliseconds{ _context->duration / AV_TIME_BASE * 1000 };
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioFile::MetadataMap AudioFile::getMetaData() const
|
AudioFile::MetadataMap AudioFile::getMetaData() const
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Av
|
|||||||
~AudioFile();
|
~AudioFile();
|
||||||
|
|
||||||
const std::filesystem::path& getPath() const override;
|
const std::filesystem::path& getPath() const override;
|
||||||
std::chrono::milliseconds getDuration() const override;
|
ContainerInfo getContainerInfo() const override;
|
||||||
MetadataMap getMetaData() const override;
|
MetadataMap getMetaData() const override;
|
||||||
std::vector<StreamInfo> getStreamInfo() const override;
|
std::vector<StreamInfo> getStreamInfo() const override;
|
||||||
std::optional<StreamInfo> getBestStreamInfo() const override;
|
std::optional<StreamInfo> getBestStreamInfo() const override;
|
||||||
|
|||||||
@@ -41,6 +41,13 @@ namespace Av
|
|||||||
std::size_t dataSize{};
|
std::size_t dataSize{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ContainerInfo
|
||||||
|
{
|
||||||
|
std::size_t bitrate{};
|
||||||
|
std::string name{};
|
||||||
|
std::chrono::milliseconds duration{};
|
||||||
|
};
|
||||||
|
|
||||||
struct StreamInfo
|
struct StreamInfo
|
||||||
{
|
{
|
||||||
size_t index{};
|
size_t index{};
|
||||||
@@ -56,7 +63,7 @@ namespace Av
|
|||||||
using MetadataMap = std::unordered_map<std::string, std::string>;
|
using MetadataMap = std::unordered_map<std::string, std::string>;
|
||||||
|
|
||||||
virtual const std::filesystem::path& getPath() const = 0;
|
virtual const std::filesystem::path& getPath() const = 0;
|
||||||
virtual std::chrono::milliseconds getDuration() const = 0;
|
virtual ContainerInfo getContainerInfo() const = 0;
|
||||||
virtual MetadataMap getMetaData() const = 0;
|
virtual MetadataMap getMetaData() const = 0;
|
||||||
virtual std::vector<StreamInfo> getStreamInfo() const = 0;
|
virtual std::vector<StreamInfo> getStreamInfo() const = 0;
|
||||||
virtual std::optional<StreamInfo> getBestStreamInfo() const = 0; // none if failure/unknown
|
virtual std::optional<StreamInfo> getBestStreamInfo() const = 0; // none if failure/unknown
|
||||||
|
|||||||
@@ -186,18 +186,9 @@ AvFormatParser::parse(const std::filesystem::path& p, bool debug)
|
|||||||
{
|
{
|
||||||
const auto mediaFile {Av::parseAudioFile(p)};
|
const auto mediaFile {Av::parseAudioFile(p)};
|
||||||
|
|
||||||
// Stream info
|
Av::ContainerInfo info{ mediaFile->getContainerInfo() };
|
||||||
if (const auto stream{ mediaFile->getBestStreamInfo() })
|
track.duration = info.duration;
|
||||||
{
|
track.bitrate = info.bitrate;
|
||||||
track.bitrate = stream->bitrate;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LMS_LOG(METADATA, INFO) << "File '" << p.string() << "': cannot get best audio stream";
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
track.duration = mediaFile->getDuration();
|
|
||||||
track.hasCover = mediaFile->hasAttachedPictures();
|
track.hasCover = mediaFile->hasAttachedPictures();
|
||||||
|
|
||||||
MetaData::Tags tags;
|
MetaData::Tags tags;
|
||||||
|
|||||||
Reference in New Issue
Block a user