Skip to content

Commit e396836

Browse files
author
Clement Champetier
committed
VideoProperties: getNbFrames returns 0 if the info is not available
1 parent 76740bb commit e396836

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,17 @@ size_t VideoProperties::getNbFrames() const
396396
throw std::runtime_error("unknown format context");
397397
size_t nbFrames = _formatContext->streams[_streamIndex]->nb_frames;
398398
if(nbFrames == 0)
399-
nbFrames = getFps() * getDuration();
399+
{
400+
LOG_WARN("The number of frames in the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown.")
401+
const float duration = getDuration();
402+
if(duration != 0)
403+
{
404+
LOG_INFO("Try to compute the number of frames from the fps and the duration.")
405+
nbFrames = getFps() * duration;
406+
}
407+
else
408+
return 0;
409+
}
400410
return nbFrames;
401411
}
402412

src/AvTranscoder/properties/VideoProperties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AvExport VideoProperties : public StreamProperties
4343
size_t getBitRate() const; ///< in bits/s
4444
size_t getMaxBitRate() const;
4545
size_t getMinBitRate() const;
46-
size_t getNbFrames() const;
46+
size_t getNbFrames() const; ///< 0 if unknown
4747
size_t getTicksPerFrame() const;
4848
size_t getWidth() const;
4949
size_t getHeight() const;

0 commit comments

Comments
 (0)