media: implement importing SRT files
This commit is contained in:
@@ -121,6 +121,10 @@ void Footage::InputValueChangedEvent(const QString &input, int element)
|
||||
AddStream(Track::kAudio, QVariant::fromValue(footage_info.GetAudioStreams().at(i)));
|
||||
}
|
||||
|
||||
for (int i=0; i<footage_info.GetSubtitleStreams().size(); i++) {
|
||||
AddStream(Track::kSubtitle, QVariant::fromValue(footage_info.GetSubtitleStreams().at(i)));
|
||||
}
|
||||
|
||||
SetValid();
|
||||
}
|
||||
|
||||
@@ -146,6 +150,12 @@ rational Footage::VerifyLengthInternal(Track::Type type) const
|
||||
if (first_stream.is_valid()) {
|
||||
return Timecode::timestamp_to_time(first_stream.duration(), first_stream.time_base());
|
||||
}
|
||||
} else if (type == Track::kSubtitle) {
|
||||
SubtitleParams first_stream = GetFirstEnabledSubtitleStream();
|
||||
|
||||
if (first_stream.is_valid()) {
|
||||
return first_stream.duration();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -165,6 +175,7 @@ void Footage::Clear()
|
||||
// Clear all dynamically created inputs
|
||||
InputArrayResize(kVideoParamsInput, 0);
|
||||
InputArrayResize(kAudioParamsInput, 0);
|
||||
InputArrayResize(kSubtitleParamsInput, 0);
|
||||
|
||||
// Clear decoder link
|
||||
decoder_.clear();
|
||||
@@ -205,13 +216,19 @@ void Footage::set_timestamp(const qint64 &t)
|
||||
|
||||
int Footage::GetStreamIndex(Track::Type type, int index) const
|
||||
{
|
||||
if (type == Track::kVideo) {
|
||||
switch (type) {
|
||||
case Track::kVideo:
|
||||
return GetVideoParams(index).stream_index();
|
||||
} else if (type == Track::kAudio) {
|
||||
case Track::kAudio:
|
||||
return GetAudioParams(index).stream_index();
|
||||
} else {
|
||||
return -1;
|
||||
case Track::kSubtitle:
|
||||
return GetSubtitleParams(index).stream_index();
|
||||
case Track::kNone:
|
||||
case Track::kCount:
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Track::Reference Footage::GetReferenceFromRealIndex(int real_index) const
|
||||
@@ -229,6 +246,12 @@ Track::Reference Footage::GetReferenceFromRealIndex(int real_index) const
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<GetSubtitleStreamCount(); i++) {
|
||||
if (GetSubtitleParams(i).stream_index() == real_index) {
|
||||
return Track::Reference(Track::kSubtitle, i);
|
||||
}
|
||||
}
|
||||
|
||||
return Track::Reference();
|
||||
}
|
||||
|
||||
@@ -249,6 +272,8 @@ QIcon Footage::icon() const
|
||||
return icon::Audio;
|
||||
} else if (s.is_valid() && s.video_type() == VideoParams::kVideoTypeStill) {
|
||||
return icon::Image;
|
||||
} else if (HasEnabledSubtitleStreams()) {
|
||||
return icon::TextSmallCaps; // FIXME: Procure icon
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +300,12 @@ QString Footage::DescribeAudioStream(const AudioParams ¶ms)
|
||||
QString::number(params.sample_rate()));
|
||||
}
|
||||
|
||||
QString Footage::DescribeSubtitleStream(const SubtitleParams ¶ms)
|
||||
{
|
||||
return tr("%1: Subtitle")
|
||||
.arg(QString::number(params.stream_index()));
|
||||
}
|
||||
|
||||
void Footage::Hash(QCryptographicHash &hash, const NodeGlobals &globals, const VideoParams &video_params) const
|
||||
{
|
||||
super::Hash(hash, globals, video_params);
|
||||
@@ -475,6 +506,16 @@ void Footage::UpdateTooltip()
|
||||
}
|
||||
}
|
||||
|
||||
int sp_sz = GetSubtitleStreamCount();
|
||||
for (int i=0; i<sp_sz; i++) {
|
||||
SubtitleParams p = GetSubtitleParams(i);
|
||||
|
||||
if (p.enabled()) {
|
||||
tip.append("\n");
|
||||
tip.append(DescribeSubtitleStream(p));
|
||||
}
|
||||
}
|
||||
|
||||
SetToolTip(tip);
|
||||
} else {
|
||||
SetToolTip(tr("Invalid"));
|
||||
|
||||
@@ -173,6 +173,7 @@ public:
|
||||
|
||||
static QString DescribeVideoStream(const VideoParams& params);
|
||||
static QString DescribeAudioStream(const AudioParams& params);
|
||||
static QString DescribeSubtitleStream(const SubtitleParams& params);
|
||||
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ bool FootageDescription::Load(const QString &filename)
|
||||
AudioParams ap;
|
||||
ap.Load(&reader);
|
||||
AddAudioStream(ap);
|
||||
} else if (reader.name() == QStringLiteral("subtitle")) {
|
||||
SubtitleParams sp;
|
||||
sp.Load(&reader);
|
||||
AddSubtitleStream(sp);
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
@@ -124,6 +128,12 @@ bool FootageDescription::Save(const QString &filename) const
|
||||
writer.writeEndElement(); // audio
|
||||
}
|
||||
|
||||
foreach (const SubtitleParams& sp, subtitle_streams_) {
|
||||
writer.writeStartElement(QStringLiteral("subtitle"));
|
||||
sp.Save(&writer);
|
||||
writer.writeEndElement(); // audio
|
||||
}
|
||||
|
||||
writer.writeEndElement(); // streams
|
||||
|
||||
writer.writeEndElement(); // streamcache
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "node/output/track/track.h"
|
||||
#include "render/audioparams.h"
|
||||
#include "render/subtitleparams.h"
|
||||
#include "render/videoparams.h"
|
||||
|
||||
namespace olive {
|
||||
@@ -37,7 +38,7 @@ public:
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return !decoder_.isEmpty() && (!video_streams_.isEmpty() || !audio_streams_.isEmpty());
|
||||
return !decoder_.isEmpty() && (!video_streams_.isEmpty() || !audio_streams_.isEmpty() || !subtitle_streams_.isEmpty());
|
||||
}
|
||||
|
||||
const QString& decoder() const
|
||||
@@ -59,12 +60,21 @@ public:
|
||||
audio_streams_.append(audio_params);
|
||||
}
|
||||
|
||||
void AddSubtitleStream(const SubtitleParams& sub_params)
|
||||
{
|
||||
Q_ASSERT(!HasStreamIndex(sub_params.stream_index()));
|
||||
|
||||
subtitle_streams_.append(sub_params);
|
||||
}
|
||||
|
||||
Track::Type GetTypeOfStream(int index)
|
||||
{
|
||||
if (StreamIsVideo(index)) {
|
||||
return Track::kVideo;
|
||||
} else if (StreamIsAudio(index)) {
|
||||
return Track::kAudio;
|
||||
} else if (StreamIsSubtitle(index)) {
|
||||
return Track::kSubtitle;
|
||||
} else {
|
||||
return Track::kNone;
|
||||
}
|
||||
@@ -92,9 +102,20 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StreamIsSubtitle(int index) const
|
||||
{
|
||||
foreach (const SubtitleParams& sp, subtitle_streams_) {
|
||||
if (sp.stream_index() == index) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HasStreamIndex(int index) const
|
||||
{
|
||||
return StreamIsVideo(index) || StreamIsAudio(index);
|
||||
return StreamIsVideo(index) || StreamIsAudio(index) || StreamIsSubtitle(index);
|
||||
}
|
||||
|
||||
bool Load(const QString& filename);
|
||||
@@ -111,8 +132,13 @@ public:
|
||||
return audio_streams_;
|
||||
}
|
||||
|
||||
const QVector<SubtitleParams>& GetSubtitleStreams() const
|
||||
{
|
||||
return subtitle_streams_;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr unsigned kFootageMetaVersion = 1;
|
||||
static constexpr unsigned kFootageMetaVersion = 2;
|
||||
|
||||
QString decoder_;
|
||||
|
||||
@@ -120,6 +146,8 @@ private:
|
||||
|
||||
QVector<AudioParams> audio_streams_;
|
||||
|
||||
QVector<SubtitleParams> subtitle_streams_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user