From 0452b42bfc943bee1b64242db76a214240e1a82d Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 10 Mar 2019 16:31:47 +0100 Subject: [PATCH] Add MediaFileInfo::overallAverageBitrate() --- CMakeLists.txt | 2 +- mediafileinfo.cpp | 20 +++++++++++++++++++- mediafileinfo.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fce4e21..1ac6182 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,7 +170,7 @@ set(META_APP_AUTHOR "Martchus") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_DESCRIPTION "C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags") set(META_VERSION_MAJOR 8) -set(META_VERSION_MINOR 2) +set(META_VERSION_MINOR 3) set(META_VERSION_PATCH 0) set(META_PUBLIC_SHARED_LIB_DEPENDS c++utilities) set(META_PUBLIC_STATIC_LIB_DEPENDS c++utilities_static) diff --git a/mediafileinfo.cpp b/mediafileinfo.cpp index 15bb57c..2057946 100644 --- a/mediafileinfo.cpp +++ b/mediafileinfo.cpp @@ -853,7 +853,7 @@ bool MediaFileInfo::hasTracksOfType(MediaType type) const } /*! - * \brief Returns the overall duration of the file is known; otherwise + * \brief Returns the overall duration of the file if known; otherwise * returns a TimeSpan with zero ticks. * * parseTracks() needs to be called before. Otherwise this @@ -871,6 +871,24 @@ ChronoUtilities::TimeSpan MediaFileInfo::duration() const return TimeSpan(); } +/*! + * \brief Returns the overall average bitrate in kbit/s of the file if known; otherwise + * returns 0.0. + * + * parseTracks() needs to be called before. Otherwise this + * method always returns false. + * + * \sa parseTracks() + */ +double MediaFileInfo::overallAverageBitrate() const +{ + const auto duration = this->duration(); + if (duration.isNull()) { + return 0.0; + } + return 0.0078125 * size() / duration.totalSeconds(); +} + /*! * \brief Determines the available languages for specified media type (by default MediaType::Audio). * diff --git a/mediafileinfo.h b/mediafileinfo.h index 96e2505..4e5d632 100644 --- a/mediafileinfo.h +++ b/mediafileinfo.h @@ -86,6 +86,7 @@ public: std::vector tracks() const; bool hasTracksOfType(TagParser::MediaType type) const; ChronoUtilities::TimeSpan duration() const; + double overallAverageBitrate() const; std::unordered_set availableLanguages(TagParser::MediaType type = TagParser::MediaType::Audio) const; std::string technicalSummary() const; bool areTracksSupported() const;