save timelapse stream to file

This commit is contained in:
2019-11-02 18:05:24 +01:00
parent 7db1739df6
commit 83ba717d5b
9 changed files with 150 additions and 23 deletions

View File

@@ -1644,6 +1644,9 @@ bool Canvas::create(int width, int height)
m_merge_rtt.create(width, height);
m_merge_tex.create(width, height);
m_unsaved = true;
timelapse_reset_encoder();
return true;
}
@@ -2213,7 +2216,27 @@ bool Canvas::project_save_thread(std::string file_path, bool show_progress)
}
}
}
if (ppi_header.doc_version.minor >= 4)
{
BinaryStreamWriter sw;
sw.init(BinaryStream::ByteOrder::LittleEndian);
Serializer::Descriptor info;
info.class_id = "ppi_info";
info.name = L"info header";
info.props["has_encoder"] = std::make_shared<Serializer::Boolean>(m_encoder != nullptr);
sw << info;
if (m_encoder != nullptr)
sw << *m_encoder;
int bytes = sw.m_data.size();
fwrite(&bytes, sizeof(int), 1, fp);
fwrite((char*)sw.m_data.data(), sw.m_data.size(), 1, fp);
}
fclose(fp);
bool success = false;
if (use_tmp)
{
@@ -2415,6 +2438,33 @@ bool Canvas::project_open_thread(std::string file_path)
std::swap(tmp_layers, m_layers);
if (ppi_header.doc_version.minor >= 4)
{
int bytes = 0;
fread(&bytes, sizeof(int), 1, fp);
std::vector<uint8_t> data(bytes);
fread(data.data(), bytes, 1, fp);
BinaryStreamReader sr;
sr.init(data.data(), data.size(), BinaryStream::ByteOrder::LittleEndian);
Serializer::Descriptor info;
sr >> info;
if (info.value<Serializer::Boolean>("has_encoder"))
{
m_encoder = std::make_unique<MP4Encoder>();
sr >> *m_encoder;
m_encoder->init();
}
else
{
timelapse_reset_encoder();
}
}
else
{
timelapse_reset_encoder();
}
fclose(fp);
LOG("project restore from %s", file_path.c_str());
@@ -2829,3 +2879,10 @@ void Canvas::set_camera(const CameraData& c)
m_proj = c.m_proj;
m_vp = c.m_vp;
}
void Canvas::timelapse_reset_encoder() noexcept
{
m_encoder = std::make_unique<MP4Encoder>();
int res = glm::min<int>(m_width / 2, 1024);
m_encoder->init(res * 4, res * 2, 30, 2000 << 10);
}