Skip to content

Commit 4574951

Browse files
committed
Merge pull request #248 from cchampet/fix_gopAnalysisOfRawStream
Fix gop analysis of raw stream
2 parents f3b6f44 + 94b6a4d commit 4574951

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/AvTranscoder/file/FormatContext.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class AvExport FormatContext
7878
* @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value
7979
* @param flag: seeking mode (AVSEEK_FLAG_xxx)
8080
* @return seek status
81+
* @warn seeking on a raw bitstreams (without any container) could produce an error (because of a lack of timing information)
8182
* @see flushDecoder
8283
*/
8384
bool seek(const uint64_t position, const int flag);

src/AvTranscoder/properties/FileProperties.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ FileProperties::FileProperties(const FormatContext& formatContext)
2929

3030
void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyseLevel level)
3131
{
32-
clearStreamProperties();
33-
3432
// if the analysis level wiil decode some streams parts, seek at the beginning
35-
if(level > eAnalyseLevelHeader)
33+
if(level > eAnalyseLevelHeader && ! isRawFormat())
3634
const_cast<FormatContext*>(_formatContext)->seek(0, AVSEEK_FLAG_BACKWARD);
3735

36+
// clear properties
37+
clearStreamProperties();
38+
39+
// reload properties
3840
for(size_t streamIndex = 0; streamIndex < _formatContext->getNbStreams(); ++streamIndex)
3941
{
4042
switch(_formatContext->getAVStream(streamIndex).codec->codec_type)
@@ -120,7 +122,7 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse
120122
}
121123

122124
// if the analysis level has decoded some streams parts, return at the beginning
123-
if(level > eAnalyseLevelHeader)
125+
if(level > eAnalyseLevelHeader && ! isRawFormat())
124126
const_cast<FormatContext*>(_formatContext)->seek(0, AVSEEK_FLAG_BACKWARD);
125127
}
126128

@@ -145,6 +147,16 @@ std::string FileProperties::getFormatLongName() const
145147
return _avFormatContext->iformat->long_name;
146148
}
147149

150+
bool FileProperties::isRawFormat() const
151+
{
152+
if(getNbStreams() != 1)
153+
return false;
154+
// the format name should be the same as the codec name
155+
if(getFormatName() == getStreamProperties().at(0)->getCodecName())
156+
return true;
157+
return false;
158+
}
159+
148160
std::string FileProperties::getFormatMimeType() const
149161
{
150162
#if LIBAVFORMAT_VERSION_MAJOR <= 55

src/AvTranscoder/properties/FileProperties.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class AvExport FileProperties
4141
std::string getFilename() const;
4242
std::string getFormatName() const; ///< A comma separated list of short names for the format, or empty if unknown.
4343
std::string getFormatLongName() const; ///< Descriptive name for the format, meant to be more human-readable than name, or empty if unknown.
44+
bool isRawFormat() const; ///< Is there a container, or a raw bitstreams without access to timing information.
4445
std::string getFormatMimeType() const; ///< Comma-separated list of mime types, or empty if unknown.
4546

4647
size_t getProgramsCount() const;

0 commit comments

Comments
 (0)