File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
src/AvTranscoder/properties Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,10 @@ Rational StreamProperties::getTimeBase() const
53
53
float StreamProperties::getDuration () const
54
54
{
55
55
const Rational timeBase = getTimeBase ();
56
- return av_q2d (timeBase) * _formatContext->streams [_streamIndex]->duration ;
56
+ const size_t streamDurationInStreamTimeBase = _formatContext->streams [_streamIndex]->duration ;
57
+ if (streamDurationInStreamTimeBase == (size_t )AV_NOPTS_VALUE)
58
+ throw std::runtime_error (" unknown stream duration" );
59
+ return av_q2d (timeBase) * streamDurationInStreamTimeBase;
57
60
}
58
61
59
62
AVMediaType StreamProperties::getStreamType () const
Original file line number Diff line number Diff line change @@ -18,6 +18,13 @@ class AvExport StreamProperties
18
18
size_t getStreamIndex () const { return _streamIndex; }
19
19
size_t getStreamId () const ;
20
20
Rational getTimeBase () const ;
21
+
22
+ /* *
23
+ * @return duration of the stream in seconds
24
+ * @throw runtime_error if the duration is unknown
25
+ * @note If a source file does not specify a duration, but does specify
26
+ * a bitrate, this value will be estimated from bitrate and file size.
27
+ */
21
28
float getDuration () const ; // /< in seconds
22
29
AVMediaType getStreamType () const ;
23
30
You can’t perform that action at this time.
0 commit comments