reimplemented export process
This commit is contained in:
+56
-32
@@ -39,7 +39,16 @@ bool ExportTask::Run()
|
||||
{
|
||||
TimeRange range;
|
||||
|
||||
// For safety, if we're overwriting, we save to a temporary filename and then only overwrite it
|
||||
// at the end
|
||||
QString real_filename = params_.filename();
|
||||
if (QFileInfo::exists(params_.filename())) {
|
||||
// Generate a filename that definitely doesn't exist
|
||||
params_.SetFilename(FileFunctions::GetSafeTemporaryFilename(real_filename));
|
||||
}
|
||||
|
||||
encoder_ = Encoder::CreateFromID(params_.encoder(), params_);
|
||||
|
||||
if (!encoder_) {
|
||||
SetError(tr("Failed to create encoder"));
|
||||
return false;
|
||||
@@ -61,17 +70,26 @@ bool ExportTask::Run()
|
||||
|
||||
frame_time_ = Timecode::time_to_timestamp(range.in(), viewer()->video_params().time_base());
|
||||
|
||||
QSize video_force_size;
|
||||
QMatrix4x4 video_force_matrix;
|
||||
|
||||
if (params_.video_enabled()) {
|
||||
|
||||
// If a transformation matrix is applied to this video, create it here
|
||||
if (params_.video_scaling_method() != ExportParams::kStretch) {
|
||||
// FIXME: Re-implement this
|
||||
if (viewer()->video_params().width() != params_.video_params().width()
|
||||
|| params_.video_params().height() != params_.video_params().height()) {
|
||||
video_force_size = QSize(params_.video_params().width(), params_.video_params().height());
|
||||
|
||||
/*QMatrix4x4 mat = ExportParams::GenerateMatrix(params_.video_scaling_method(),
|
||||
viewer()->video_params().width(),
|
||||
viewer()->video_params().height(),
|
||||
params_.video_params().width(),
|
||||
params_.video_params().height());*/
|
||||
if (params_.video_scaling_method() != ExportParams::kStretch) {
|
||||
video_force_matrix = ExportParams::GenerateMatrix(params_.video_scaling_method(),
|
||||
viewer()->video_params().width(),
|
||||
viewer()->video_params().height(),
|
||||
params_.video_params().width(),
|
||||
params_.video_params().height());
|
||||
}
|
||||
} else {
|
||||
// Disables forcing size in the renderer
|
||||
video_force_size = QSize(0, 0);
|
||||
}
|
||||
|
||||
// Create color processor
|
||||
@@ -96,7 +114,9 @@ bool ExportTask::Run()
|
||||
audio_data_.SetLength(range.length());
|
||||
}
|
||||
|
||||
Render(video_range, audio_range, RenderMode::kOnline, false);
|
||||
Render(color_manager_, video_range, audio_range, RenderMode::kOnline, nullptr,
|
||||
video_force_size, video_force_matrix, encoder_->GetDesiredPixelFormat(),
|
||||
color_processor_);
|
||||
|
||||
bool success = true;
|
||||
|
||||
@@ -107,35 +127,28 @@ bool ExportTask::Run()
|
||||
|
||||
encoder_->Close();
|
||||
|
||||
encoder_->deleteLater();
|
||||
delete encoder_;
|
||||
|
||||
// If cancelled, delete the file we made, which is always a file we created since we write to a
|
||||
// temp file during the actual encoding process
|
||||
if (IsCancelled()) {
|
||||
QFile::remove(params_.filename());
|
||||
} else if (params_.filename() != real_filename) {
|
||||
// If we were writing to a temp file, overwrite now
|
||||
if (!FileFunctions::RenameFileAllowOverwrite(params_.filename(), real_filename)) {
|
||||
SetError(tr("Failed to overwrite \"%1\". Export has been saved as \"%2\" instead.")
|
||||
.arg(real_filename, params_.filename()));
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void FrameColorConvert(ColorProcessorPtr processor, FramePtr frame)
|
||||
{
|
||||
// Color conversion must be done with unassociated alpha, and the pipeline is always associated
|
||||
ColorManager::DisassociateAlpha(frame);
|
||||
|
||||
// Convert color space
|
||||
processor->ConvertFrame(frame);
|
||||
|
||||
// Re-associate alpha
|
||||
ColorManager::ReassociateAlpha(frame);
|
||||
}
|
||||
|
||||
QFuture<void> ExportTask::DownloadFrame(FramePtr frame, const QByteArray &hash)
|
||||
{
|
||||
rendered_frame_.insert(hash, frame);
|
||||
|
||||
return QtConcurrent::run(FrameColorConvert, color_processor_, frame);
|
||||
}
|
||||
|
||||
void ExportTask::FrameDownloaded(const QByteArray &hash, const std::list<rational> ×, qint64 job_time)
|
||||
void ExportTask::FrameDownloaded(FramePtr f, const QByteArray &hash, const QVector<rational> ×, qint64 job_time)
|
||||
{
|
||||
Q_UNUSED(job_time)
|
||||
|
||||
FramePtr f = rendered_frame_.value(hash);
|
||||
Q_UNUSED(hash)
|
||||
|
||||
foreach (const rational& t, times) {
|
||||
time_map_.insert(t, f);
|
||||
@@ -154,10 +167,21 @@ void ExportTask::FrameDownloaded(const QByteArray &hash, const std::list<rationa
|
||||
encoder_->WriteFrame(time_map_.take(real_time), real_time);
|
||||
|
||||
frame_time_++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void FrameColorConvert(ColorProcessorPtr processor, FramePtr frame)
|
||||
{
|
||||
// Color conversion must be done with unassociated alpha, and the pipeline is always associated
|
||||
ColorManager::DisassociateAlpha(frame);
|
||||
|
||||
// Convert color space
|
||||
processor->ConvertFrame(frame);
|
||||
|
||||
// Re-associate alpha
|
||||
ColorManager::ReassociateAlpha(frame);
|
||||
}
|
||||
|
||||
void ExportTask::AudioDownloaded(const TimeRange &range, SampleBufferPtr samples, qint64 job_time)
|
||||
{
|
||||
Q_UNUSED(job_time)
|
||||
|
||||
Reference in New Issue
Block a user