export: allow exporting subtitles to sidecar files
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
|
||||
#include "common/digit.h"
|
||||
#include "common/qtutils.h"
|
||||
#include "core.h"
|
||||
#include "dialog/task/task.h"
|
||||
#include "node/project/project.h"
|
||||
#include "node/project/sequence/sequence.h"
|
||||
@@ -250,6 +249,12 @@ ExportDialog::ExportDialog(ViewerOutput *viewer_node, QWidget *parent) :
|
||||
preview_viewer_->ConnectViewerNode(viewer_node_);
|
||||
preview_viewer_->SetColorMenuEnabled(false);
|
||||
preview_viewer_->SetColorTransform(video_tab_->CurrentOCIOColorSpace());
|
||||
|
||||
// We don't check if the codec supports subtitles because we can always export to a sidecar file
|
||||
bool has_subtitle_codecs = SequenceHasSubtitles();
|
||||
connect(subtitles_enabled_, &QCheckBox::toggled, subtitle_tab_, &QWidget::setEnabled);
|
||||
subtitles_enabled_->setChecked(has_subtitle_codecs);
|
||||
subtitles_enabled_->setEnabled(has_subtitle_codecs);
|
||||
}
|
||||
|
||||
rational ExportDialog::GetSelectedTimebase() const
|
||||
@@ -445,9 +450,9 @@ void ExportDialog::FormatChanged(ExportFormat::Format current_format)
|
||||
audio_enabled_->setChecked(has_audio_codecs);
|
||||
audio_enabled_->setEnabled(has_audio_codecs);
|
||||
|
||||
bool has_subtitle_codecs = subtitle_tab_->SetFormat(current_format);
|
||||
subtitles_enabled_->setChecked(has_subtitle_codecs);
|
||||
subtitles_enabled_->setEnabled(has_subtitle_codecs);
|
||||
if (subtitles_enabled_->isEnabled()) {
|
||||
subtitle_tab_->SetFormat(current_format);
|
||||
}
|
||||
}
|
||||
|
||||
void ExportDialog::ResolutionChanged()
|
||||
@@ -503,6 +508,20 @@ void ExportDialog::SetDefaultFilename()
|
||||
filename_edit_->setText(file_location);
|
||||
}
|
||||
|
||||
bool ExportDialog::SequenceHasSubtitles() const
|
||||
{
|
||||
if (Sequence *s = dynamic_cast<Sequence*>(viewer_node_)) {
|
||||
TrackList *tl = s->track_list(Track::kSubtitle);
|
||||
for (Track *t : tl->GetTracks()) {
|
||||
if (!t->IsMuted() && !t->Blocks().empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ExportParams ExportDialog::GenerateParams() const
|
||||
{
|
||||
VideoParams video_render_params(static_cast<int>(video_tab_->width_slider()->GetValue()),
|
||||
@@ -519,7 +538,7 @@ ExportParams ExportDialog::GenerateParams() const
|
||||
audio_tab_->sample_format_combobox()->GetSampleFormat());
|
||||
|
||||
ExportParams params;
|
||||
params.set_encoder(Encoder::GetTypeFromFormat(format_combobox_->GetFormat()));
|
||||
params.set_format(format_combobox_->GetFormat());
|
||||
params.SetFilename(filename_edit_->text().trimmed());
|
||||
params.SetExportLength(viewer_node_->GetLength());
|
||||
|
||||
@@ -561,8 +580,15 @@ ExportParams ExportDialog::GenerateParams() const
|
||||
params.set_audio_bit_rate(audio_tab_->bit_rate_slider()->GetValue() * 1000);
|
||||
}
|
||||
|
||||
if (subtitles_enabled_->isChecked()) {
|
||||
params.EnableSubtitles(subtitle_tab_->GetSubtitleCodec());
|
||||
if (subtitles_enabled_->isEnabled()
|
||||
&& subtitles_enabled_->isChecked()) {
|
||||
if (!subtitle_tab_->GetSidecarEnabled()) {
|
||||
// Export subtitles embedded in container
|
||||
params.EnableSubtitles(subtitle_tab_->GetSubtitleCodec());
|
||||
} else {
|
||||
// Export subtitles to a sidecar file
|
||||
params.EnableSidecarSubtitles(subtitle_tab_->GetSidecarFormat(), subtitle_tab_->GetSubtitleCodec());
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
|
||||
@@ -63,6 +63,8 @@ private:
|
||||
void LoadPresets();
|
||||
void SetDefaultFilename();
|
||||
|
||||
bool SequenceHasSubtitles() const;
|
||||
|
||||
ExportParams GenerateParams() const;
|
||||
|
||||
ViewerOutput* viewer_node_;
|
||||
|
||||
@@ -46,6 +46,13 @@ ExportFormatComboBox::ExportFormatComboBox(Mode mode, QWidget *parent) :
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case kShowSubtitlesOnly:
|
||||
if (!ExportFormat::GetVideoCodecs(f).isEmpty()
|
||||
|| ExportFormat::GetSubtitleCodecs(f).isEmpty()
|
||||
|| !ExportFormat::GetAudioCodecs(f).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
QString format_name = ExportFormat::GetName(f);
|
||||
|
||||
@@ -34,7 +34,8 @@ public:
|
||||
enum Mode {
|
||||
kShowAllFormats,
|
||||
kShowAudioOnly,
|
||||
kShowVideoOnly
|
||||
kShowVideoOnly,
|
||||
kShowSubtitlesOnly
|
||||
};
|
||||
|
||||
ExportFormatComboBox(Mode mode, QWidget *parent = nullptr);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "exportsubtitlestab.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
|
||||
namespace olive {
|
||||
|
||||
@@ -15,22 +14,46 @@ ExportSubtitlesTab::ExportSubtitlesTab(QWidget *parent) :
|
||||
|
||||
int row = 0;
|
||||
|
||||
sidecar_checkbox_ = new QCheckBox(tr("Export to sidecar file"));
|
||||
layout->addWidget(sidecar_checkbox_, row, 0, 1, 2);
|
||||
|
||||
row++;
|
||||
|
||||
sidecar_format_label_ = new QLabel(tr("Sidecar Format:"));
|
||||
sidecar_format_label_->setVisible(false);
|
||||
layout->addWidget(sidecar_format_label_, row, 0);
|
||||
|
||||
sidecar_format_combobox_ = new ExportFormatComboBox(ExportFormatComboBox::kShowSubtitlesOnly);
|
||||
sidecar_format_combobox_->setVisible(false);
|
||||
layout->addWidget(sidecar_format_combobox_, row, 1);
|
||||
|
||||
row++;
|
||||
|
||||
layout->addWidget(new QLabel(tr("Codec:")), row, 0);
|
||||
|
||||
codec_combobox_ = new QComboBox();
|
||||
layout->addWidget(codec_combobox_, row, 1);
|
||||
|
||||
outer_layout->addStretch();
|
||||
|
||||
connect(sidecar_checkbox_, &QCheckBox::toggled, sidecar_format_label_, &QWidget::setVisible);
|
||||
connect(sidecar_checkbox_, &QCheckBox::toggled, sidecar_format_combobox_, &QWidget::setVisible);
|
||||
}
|
||||
|
||||
int ExportSubtitlesTab::SetFormat(ExportFormat::Format format)
|
||||
{
|
||||
auto scodecs = ExportFormat::GetSubtitleCodecs(format);
|
||||
setEnabled(!scodecs.isEmpty());
|
||||
|
||||
sidecar_checkbox_->setChecked(scodecs.empty());
|
||||
sidecar_checkbox_->setEnabled(!scodecs.empty());
|
||||
|
||||
scodecs = ExportFormat::GetSubtitleCodecs(sidecar_format_combobox_->GetFormat());
|
||||
|
||||
codec_combobox_->clear();
|
||||
foreach (ExportCodec::Codec scodec, scodecs) {
|
||||
codec_combobox_->addItem(ExportCodec::GetCodecName(scodec), scodec);
|
||||
}
|
||||
|
||||
return scodecs.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,12 @@
|
||||
#ifndef EXPORTSUBTITLESTAB_H
|
||||
#define EXPORTSUBTITLESTAB_H
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
|
||||
#include "codec/exportformat.h"
|
||||
#include "render/subtitleparams.h"
|
||||
#include "dialog/export/exportformatcombobox.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
@@ -34,6 +36,12 @@ class ExportSubtitlesTab : public QWidget
|
||||
public:
|
||||
ExportSubtitlesTab(QWidget *parent = nullptr);
|
||||
|
||||
bool GetSidecarEnabled() const { return sidecar_checkbox_->isChecked(); }
|
||||
void SetSidecarEnabled(bool e) { sidecar_checkbox_->setEnabled(e); }
|
||||
|
||||
ExportFormat::Format GetSidecarFormat() const { return sidecar_format_combobox_->GetFormat(); }
|
||||
void SetSidecarFormat(ExportFormat::Format f) { sidecar_format_combobox_->SetFormat(f); }
|
||||
|
||||
int SetFormat(ExportFormat::Format format);
|
||||
|
||||
ExportCodec::Codec GetSubtitleCodec()
|
||||
@@ -42,6 +50,11 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
QCheckBox *sidecar_checkbox_;
|
||||
|
||||
QLabel *sidecar_format_label_;
|
||||
ExportFormatComboBox *sidecar_format_combobox_;
|
||||
|
||||
QComboBox *codec_combobox_;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user