Skip to content

Commit a1cc138

Browse files
author
Clement Champetier
committed
VideoDuration: override getDuration method
If it is a raw stream, get the file size to compute the stream duration.
1 parent 3b32e21 commit a1cc138

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <AvTranscoder/data/decoded/Frame.hpp>
44
#include <AvTranscoder/properties/util.hpp>
5+
#include <AvTranscoder/properties/FileProperties.hpp>
56
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
67

78
extern "C" {
@@ -464,6 +465,22 @@ float VideoProperties::getFps() const
464465
return av_q2d(_formatContext->streams[_streamIndex]->avg_frame_rate);
465466
}
466467

468+
float VideoProperties::getDuration() const
469+
{
470+
const float duration = StreamProperties::getDuration();
471+
if(duration == 0)
472+
{
473+
LOG_WARN("The duration of the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown.")
474+
if(_fileProperties->isRawFormat())
475+
{
476+
LOG_INFO("Get the file size to compute the duration.")
477+
return _fileProperties->getFileSize() / getBitRate() * 8;
478+
}
479+
return 0;
480+
}
481+
return duration;
482+
}
483+
467484
bool VideoProperties::hasBFrames() const
468485
{
469486
if(!_codecContext)

src/AvTranscoder/properties/VideoProperties.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class AvExport VideoProperties : public StreamProperties
6161
*/
6262
float getFps() const;
6363

64+
/**
65+
* @brief Override StreamProperties method.
66+
* @return The stream duration in seconds, 0 if not available
67+
*/
68+
float getDuration() const;
69+
6470
bool hasBFrames() const;
6571
// bool isClosedGop() const;
6672

0 commit comments

Comments
 (0)