From e74adcb95ac57630e0d6fbdab582dcacf2f52234 Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel <22495855+jkrumbiegel@users.noreply.github.com> Date: Mon, 14 Oct 2024 11:45:41 +0200 Subject: [PATCH] Write colorbuffer directly to io if it fits in format (#4475) * Write colorbuffer directly to io if it fits in format * add changelog --- CHANGELOG.md | 2 ++ src/ffmpeg-util.jl | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07748f71d63..53eb7848b01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +- Improved performance of `record` by avoiding unnecessary copying in common cases [#4475](https://github.com/MakieOrg/Makie.jl/pull/4475). + ## [0.21.14] - 2024-10-11 - Fixed relocatability of GLMakie [#4461](https://github.com/MakieOrg/Makie.jl/pull/4461). diff --git a/src/ffmpeg-util.jl b/src/ffmpeg-util.jl index b7e7b1bb55c..2bb14ffad61 100644 --- a/src/ffmpeg-util.jl +++ b/src/ffmpeg-util.jl @@ -286,8 +286,12 @@ function recordframe!(io::VideoStream) # Make no copy if already Matrix{RGB{N0f8}} # There may be a 1px padding for odd dimensions xdim, ydim = size(glnative) - copy!(view(io.buffer, 1:xdim, 1:ydim), glnative) - write(io.io, io.buffer) + if eltype(glnative) == eltype(io.buffer) && size(glnative) == size(io.buffer) + write(io.io, glnative) + else + copy!(view(io.buffer, 1:xdim, 1:ydim), glnative) + write(io.io, io.buffer) + end next_tick!(io.tick_controller) return end