diff --git a/src/AvTranscoder/file/FormatContext.hpp b/src/AvTranscoder/file/FormatContext.hpp index 2e885f32..3257ce2a 100644 --- a/src/AvTranscoder/file/FormatContext.hpp +++ b/src/AvTranscoder/file/FormatContext.hpp @@ -78,6 +78,7 @@ class AvExport FormatContext * @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value * @param flag: seeking mode (AVSEEK_FLAG_xxx) * @return seek status + * @warn seeking on a raw bitstreams (without any container) could produce an error (because of a lack of timing information) * @see flushDecoder */ bool seek(const uint64_t position, const int flag); diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index e7ab4fd8..1a250d02 100644 --- a/src/AvTranscoder/properties/FileProperties.cpp +++ b/src/AvTranscoder/properties/FileProperties.cpp @@ -29,12 +29,14 @@ FileProperties::FileProperties(const FormatContext& formatContext) void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyseLevel level) { - clearStreamProperties(); - // if the analysis level wiil decode some streams parts, seek at the beginning - if(level > eAnalyseLevelHeader) + if(level > eAnalyseLevelHeader && ! isRawFormat()) const_cast(_formatContext)->seek(0, AVSEEK_FLAG_BACKWARD); + // clear properties + clearStreamProperties(); + + // reload properties for(size_t streamIndex = 0; streamIndex < _formatContext->getNbStreams(); ++streamIndex) { switch(_formatContext->getAVStream(streamIndex).codec->codec_type) @@ -120,7 +122,7 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse } // if the analysis level has decoded some streams parts, return at the beginning - if(level > eAnalyseLevelHeader) + if(level > eAnalyseLevelHeader && ! isRawFormat()) const_cast(_formatContext)->seek(0, AVSEEK_FLAG_BACKWARD); } @@ -145,6 +147,16 @@ std::string FileProperties::getFormatLongName() const return _avFormatContext->iformat->long_name; } +bool FileProperties::isRawFormat() const +{ + if(getNbStreams() != 1) + return false; + // the format name should be the same as the codec name + if(getFormatName() == getStreamProperties().at(0)->getCodecName()) + return true; + return false; +} + std::string FileProperties::getFormatMimeType() const { #if LIBAVFORMAT_VERSION_MAJOR <= 55 diff --git a/src/AvTranscoder/properties/FileProperties.hpp b/src/AvTranscoder/properties/FileProperties.hpp index f311cb0b..75c1a475 100644 --- a/src/AvTranscoder/properties/FileProperties.hpp +++ b/src/AvTranscoder/properties/FileProperties.hpp @@ -41,6 +41,7 @@ class AvExport FileProperties std::string getFilename() const; std::string getFormatName() const; ///< A comma separated list of short names for the format, or empty if unknown. std::string getFormatLongName() const; ///< Descriptive name for the format, meant to be more human-readable than name, or empty if unknown. + bool isRawFormat() const; ///< Is there a container, or a raw bitstreams without access to timing information. std::string getFormatMimeType() const; ///< Comma-separated list of mime types, or empty if unknown. size_t getProgramsCount() const;