encoder: write audio in segments

I'll be honest, this probably makes no noticeable difference at all. It should be faster and more efficient, but whether that translates into any tangible improvement is yet to be seen.
This commit is contained in:
itsmattkc
2021-05-10 00:44:08 +10:00
parent 27653f10dc
commit 15556c64ae
12 changed files with 295 additions and 152 deletions
+32 -11
View File
@@ -99,10 +99,6 @@ bool ExportTask::Run()
params_.color_transform());
}
if (params_.audio_enabled()) {
audio_data_.SetParameters(audio_params());
}
// Start render process
TimeRangeList video_range, audio_range;
@@ -112,7 +108,6 @@ bool ExportTask::Run()
if (params_.audio_enabled()) {
audio_range = {range};
audio_data_.SetLength(range.length());
}
Render(color_manager_, video_range, audio_range, RenderMode::kOnline, nullptr,
@@ -121,13 +116,13 @@ bool ExportTask::Run()
bool success = true;
if (params_.audio_enabled()) {
// Write audio data now
encoder_->WriteAudio(audio_params(), audio_data_.CreatePlaybackDevice(encoder_));
}
encoder_->Close();
if (!encoder_->GetError().isEmpty()) {
SetError(encoder_->GetError());
success = false;
}
delete encoder_;
// If cancelled, delete the file we made, which is always a file we created since we write to a
@@ -187,7 +182,33 @@ void ExportTask::AudioDownloaded(const TimeRange &range, SampleBufferPtr samples
adjusted_range -= params_.custom_range().in();
}
audio_data_.WritePCM(adjusted_range, samples, QDateTime::currentMSecsSinceEpoch());
if (adjusted_range.in() == audio_time_) {
WriteAudioLoop(adjusted_range, samples);
} else {
audio_map_.insert(adjusted_range, samples);
}
}
void ExportTask::WriteAudioLoop(const TimeRange& time, SampleBufferPtr samples)
{
encoder_->WriteAudio(samples);
audio_time_ = time.out();
for (auto it=audio_map_.begin(); it!=audio_map_.end(); it++) {
TimeRange t = it.key();
SampleBufferPtr s = it.value();
if (t.in() == audio_time_) {
// Erase from audio map since we're just about to write it
audio_map_.erase(it);
// Call recursively to write the next sample buffer
WriteAudioLoop(t, s);
// Break out of loop
break;
}
}
}
}