From 2cc1324cf6d6076cd8b0c3dad8c691fc2defe97e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Garramu=C3=B1o?= Date: Mon, 26 Feb 2024 02:47:11 -0300 Subject: [PATCH] Fixed saving large movies into annoations viewport. --- mrv2/docs/HISTORY.md | 5 ++- mrv2/lib/mrvFl/mrvSaveMovie.cpp | 79 ++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/mrv2/docs/HISTORY.md b/mrv2/docs/HISTORY.md index f702fa864..3a58fcd9f 100644 --- a/mrv2/docs/HISTORY.md +++ b/mrv2/docs/HISTORY.md @@ -31,7 +31,10 @@ v1.0.7 as I was using an NTFS drive which sets umask 0022 by default. - Made reading session more robust to handle missing files or wrong settings. - Made checking for readable files faster. - +- Fixed saving large images/movies with annotations on work properly. +- Improved memory consumption of saving movies, particularly large ones like + 4K. + v1.0.6 ====== diff --git a/mrv2/lib/mrvFl/mrvSaveMovie.cpp b/mrv2/lib/mrvFl/mrvSaveMovie.cpp index 8110f4b41..d7b50307b 100644 --- a/mrv2/lib/mrvFl/mrvSaveMovie.cpp +++ b/mrv2/lib/mrvFl/mrvSaveMovie.cpp @@ -61,6 +61,16 @@ namespace mrv auto mute = player->isMuted(); player->setMute(true); + + auto context = ui->app->getContext(); + + // Get I/O cache and store its size. + auto ioSystem = context->getSystem(); + auto cache = ioSystem->getCache(); + + size_t oldCacheSize = cache->getMax(); + + try { @@ -117,8 +127,12 @@ namespace mrv ioOptions["OpenEXR/DWACompressionLevel"] = s.str(); } #endif + - auto context = ui->app->getContext(); + // Make I/O cache be 1Gb to deal with long movies fine. + size_t bytes = memory::gigabyte; + cache->setMax(bytes); + auto timeline = player->timeline(); auto startTimeOpt = timeline->getTimeline()->global_start_time(); @@ -241,8 +255,7 @@ namespace mrv offscreenBufferOptions.colorType = image::PixelType::RGBA_F32; // Create the writer. - auto writerPlugin = - context->getSystem()->getPlugin(path); + auto writerPlugin = ioSystem->getPlugin(path); if (!writerPlugin) { @@ -267,34 +280,7 @@ namespace mrv .arg(outputInfo.size) .arg(outputInfo.pixelType); LOG_INFO(msg); - - outputInfo = writerPlugin->getWriteInfo(outputInfo); - if (image::PixelType::None == outputInfo.pixelType) - { - outputInfo.pixelType = image::PixelType::RGB_U8; - offscreenBufferOptions.colorType = image::PixelType::RGB_U8; -#ifdef TLRENDER_EXR - if (saveEXR) - { - offscreenBufferOptions.colorType = - image::PixelType::RGB_F32; - } -#endif - } - -#ifdef TLRENDER_EXR - if (saveEXR) - { - outputInfo.pixelType = options.exrPixelType; - } -#endif - if (saveHDR) - { - outputInfo.pixelType = image::PixelType::RGB_F32; - offscreenBufferOptions.colorType = - image::PixelType::RGB_F32; - } - + if (annotations) { view->setActionMode(ActionMode::kScrub); @@ -323,6 +309,7 @@ namespace mrv view->frameView(); renderSize.w = viewportSize.w; renderSize.h = viewportSize.h; + outputInfo.size = renderSize; LOG_WARNING(_("Image too big. " "Will save the viewport size.")); } @@ -341,6 +328,34 @@ namespace mrv LOG_INFO(msg); } + outputInfo = writerPlugin->getWriteInfo(outputInfo); + if (image::PixelType::None == outputInfo.pixelType) + { + outputInfo.pixelType = image::PixelType::RGB_U8; + offscreenBufferOptions.colorType = image::PixelType::RGB_U8; +#ifdef TLRENDER_EXR + if (saveEXR) + { + offscreenBufferOptions.colorType = + image::PixelType::RGB_F32; + } +#endif + } + +#ifdef TLRENDER_EXR + if (saveEXR) + { + outputInfo.pixelType = options.exrPixelType; + } +#endif + if (saveHDR) + { + outputInfo.pixelType = image::PixelType::RGB_F32; + offscreenBufferOptions.colorType = + image::PixelType::RGB_F32; + } + + msg = tl::string::Format(_("Output info: {0} {1}")) .arg(outputInfo.size) .arg(outputInfo.pixelType); @@ -657,6 +672,8 @@ namespace mrv settings->addRecentFile(file); ui->uiMain->fill_menu(ui->uiMenuBar); } + + cache->setMax(oldCacheSize); } } // namespace mrv