From 8a4e575597f9ad483ffdde68221a57b18d5fa95f Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 13 May 2016 11:45:34 +0200 Subject: [PATCH 1/3] FormatContext: added doc when seek on a raw bitstreams --- src/AvTranscoder/file/FormatContext.hpp | 1 + 1 file changed, 1 insertion(+) 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); From c479c565438a4949fb095a9f7eda8e348a5435d4 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 13 May 2016 13:23:42 +0200 Subject: [PATCH 2/3] FileProperties: added isRawFormat method To check if it's a container, or a raw bitstreams without access to timing information. --- src/AvTranscoder/properties/FileProperties.cpp | 10 ++++++++++ src/AvTranscoder/properties/FileProperties.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index c18083fe..0d489a8b 100644 --- a/src/AvTranscoder/properties/FileProperties.cpp +++ b/src/AvTranscoder/properties/FileProperties.cpp @@ -145,6 +145,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; From edc9345bc762caf4f9af0e96beca1faa558af9bd Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Fri, 13 May 2016 13:26:01 +0200 Subject: [PATCH 3/3] FileProperties: fixed analysis of first GOP on raw format * When extractStreamProperties, seek at the beginning of the file only if analyse gop on none raw format. * Tested with avc (h264 codec) and mp3 files. --- src/AvTranscoder/properties/FileProperties.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index 0d489a8b..ad994f25 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); }