Skip to content

Commit 5e5e52d

Browse files
author
Clement Champetier
committed
StreamProperties: getDuration returns 0 if the info is not available
1 parent 591b159 commit 5e5e52d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/AvTranscoder/properties/StreamProperties.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ Rational StreamProperties::getTimeBase() const
6666
float StreamProperties::getDuration() const
6767
{
6868
const Rational timeBase = getTimeBase();
69-
return av_q2d(timeBase) * _formatContext->streams[_streamIndex]->duration;
69+
const size_t duration = _formatContext->streams[_streamIndex]->duration;
70+
if(duration == (size_t)AV_NOPTS_VALUE)
71+
return 0;
72+
return av_q2d(timeBase) * duration;
7073
}
7174

7275
AVMediaType StreamProperties::getStreamType() const

src/AvTranscoder/properties/StreamProperties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AvExport StreamProperties
1919
size_t getStreamIndex() const { return _streamIndex; }
2020
size_t getStreamId() const;
2121
Rational getTimeBase() const;
22-
float getDuration() const; ///< in seconds
22+
float getDuration() const; ///< in seconds, 0 if not available
2323
AVMediaType getStreamType() const;
2424

2525
size_t getCodecId() const;

0 commit comments

Comments
 (0)