correct duration/rate in project explorer

This commit is contained in:
itsmattkc
2019-09-26 16:00:21 +10:00
parent 0e46ff02d7
commit ce20dc159e
10 changed files with 106 additions and 6 deletions
+1 -2
View File
@@ -363,8 +363,6 @@ bool FFmpegDecoder::Probe(Footage *f)
// Retrieve metadata about the media
av_dump_format(fmt_ctx_, 0, filename, 0);
qDebug() << "Format duration:" << fmt_ctx_->duration;
// Dump it into the Footage object
for (unsigned int i=0;i<fmt_ctx_->nb_streams;i++) {
@@ -379,6 +377,7 @@ bool FFmpegDecoder::Probe(Footage *f)
video_stream->set_width(avstream_->codecpar->width);
video_stream->set_height(avstream_->codecpar->height);
video_stream->set_frame_rate(av_guess_frame_rate(fmt_ctx_, avstream_, nullptr));
str = video_stream;
+55
View File
@@ -22,6 +22,7 @@
#include <QCoreApplication>
#include "common/timecodefunctions.h"
#include "ui/icons/icons.h"
Footage::Footage()
@@ -146,6 +147,60 @@ QIcon Footage::icon()
return QIcon();
}
#include <QDebug>
QString Footage::duration()
{
if (streams_.isEmpty()) {
return QString();
}
if (streams_.first()->type() == Stream::kVideo) {
VideoStreamPtr video_stream = std::static_pointer_cast<VideoStream>(streams_.first());
int64_t duration = video_stream->duration();
rational frame_rate_timebase = video_stream->frame_rate().flipped();
if (video_stream->timebase() != frame_rate_timebase) {
// Convert from timebase to frame rate
rational duration_time = olive::timestamp_to_time(duration, video_stream->timebase());
duration = olive::time_to_timestamp(duration_time, frame_rate_timebase);
}
return olive::timestamp_to_timecode(duration,
frame_rate_timebase,
olive::CurrentTimecodeDisplay());
} else if (streams_.first()->type() == Stream::kAudio) {
AudioStreamPtr audio_stream = std::static_pointer_cast<AudioStream>(streams_.first());
return olive::timestamp_to_timecode(streams_.first()->duration(),
streams_.first()->timebase(),
olive::CurrentTimecodeDisplay());
}
return QString();
}
QString Footage::rate()
{
if (streams_.isEmpty()) {
return QString();
}
if (streams_.first()->type() == Stream::kVideo) {
// Return the timebase as a frame rate
VideoStreamPtr video_stream = std::static_pointer_cast<VideoStream>(streams_.first());
return QCoreApplication::translate("Footage", "%1 FPS").arg(video_stream->frame_rate().toDouble());
} else if (streams_.first()->type() == Stream::kAudio) {
// Return the sample rate
AudioStreamPtr audio_stream = std::static_pointer_cast<AudioStream>(streams_.first());
return QCoreApplication::translate("Footage", "%1 Hz").arg(audio_stream->sample_rate());
}
return olive::timestamp_to_timecode(streams_.first()->duration(), streams_.first()->timebase(), olive::CurrentTimecodeDisplay());
}
void Footage::ClearStreams()
{
if (streams_.empty()) {
+4
View File
@@ -207,6 +207,10 @@ public:
virtual QIcon icon() override;
virtual QString duration() override;
virtual QString rate() override;
private:
/**
* @brief Internal function to delete all Stream children and empty the array
+10
View File
@@ -31,3 +31,13 @@ QString VideoStream::description()
QString::number(width()),
QString::number(height()));
}
const rational &VideoStream::frame_rate()
{
return frame_rate_;
}
void VideoStream::set_frame_rate(const rational &frame_rate)
{
frame_rate_ = frame_rate;
}
+11
View File
@@ -29,6 +29,17 @@ public:
VideoStream();
virtual QString description() override;
/**
* @brief Get this video stream's frame rate
*
* Used purely for metadata, rendering uses the timebase instead.
*/
const rational& frame_rate();
void set_frame_rate(const rational& frame_rate);
private:
rational frame_rate_;
};
using VideoStreamPtr = std::shared_ptr<VideoStream>;
+10
View File
@@ -101,6 +101,16 @@ void Item::set_tooltip(const QString &t)
tooltip_ = t;
}
QString Item::duration()
{
return QString();
}
QString Item::rate()
{
return QString();
}
Item *Item::parent() const
{
return parent_;
+4
View File
@@ -94,6 +94,10 @@ public:
virtual QIcon icon() = 0;
virtual QString duration();
virtual QString rate();
Item *parent() const;
const Item* root() const;
+7
View File
@@ -20,6 +20,8 @@
#include "sequence.h"
#include <QCoreApplication>
#include "common/channellayout.h"
#include "ui/icons/icons.h"
@@ -37,6 +39,11 @@ QIcon Sequence::icon()
return olive::icon::Sequence;
}
QString Sequence::rate()
{
return QCoreApplication::translate("Sequence", "%1 FPS").arg(video_time_base_.flipped().toDouble());
}
const int &Sequence::video_width()
{
return video_width_;
+2
View File
@@ -40,6 +40,8 @@ public:
virtual QIcon icon() override;
virtual QString rate() override;
/* VIDEO GETTER/SETTER FUNCTIONS */
const int& video_width();
+2 -4
View File
@@ -131,11 +131,9 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
case kName:
return internal_item->name();
case kDuration:
// FIXME Return actual information
return "00:00:00;00";
return internal_item->duration();
case kRate:
// FIXME Return actual information
return "29.97 FPS";
return internal_item->rate();
}
}
break;