Skip to content

Commit 591b159

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

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/AvTranscoder/properties/FileProperties.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ float FileProperties::getDuration() const
186186
{
187187
if(!_avFormatContext)
188188
throw std::runtime_error("unknown format context");
189+
const size_t duration = _avFormatContext->duration;
190+
if(duration == (size_t)AV_NOPTS_VALUE)
191+
return 0;
189192
return 1.0 * _avFormatContext->duration / AV_TIME_BASE;
190193
}
191194

src/AvTranscoder/properties/FileProperties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AvExport FileProperties
4646

4747
size_t getProgramsCount() const;
4848
double getStartTime() const;
49-
float getDuration() const; ///< in seconds
49+
float getDuration() const; ///< in seconds, 0 if not available
5050
size_t getBitRate() const; ///< total stream bitrate in bit/s, 0 if not available (result of a computation by ffmpeg)
5151
size_t getPacketSize() const;
5252

0 commit comments

Comments
 (0)