Skip to content

Commit

Permalink
remove VideoStream underlying file when cleaning the object
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed Jul 16, 2024
1 parent f1bc654 commit 6deae58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 12 additions & 2 deletions CairoMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,25 @@ end
N = 3
points = Observable(Point2f[])
f, ax, pl = scatter(points, axis=(type=Axis, aspect=DataAspect(), limits=(0.4, N + 0.6, 0.4, N + 0.6),), figure=(size=(600, 800),))

vio = Makie.VideoStream(f; format="mp4", px_per_unit=2.0, backend=CairoMakie)
tmp_path = vio.path

@test vio.screen isa CairoMakie.Screen{CairoMakie.IMAGE}
@test size(vio.screen) == size(f.scene) .* 2
@test vio.screen.device_scaling_factor == 2.0

Makie.recordframe!(vio)
save("test.mp4", vio)
@test isfile("test.mp4") # Make sure no error etc
rm("test.mp4")
save("test_2.mkv", vio)
save("test_3.mp4", vio)
# make sure all files are correctly saved:
@test all(isfile, ["test.mp4", "test_2.mkv", "test_3.mp4"])
@test filesize("test.mp4") == filesize("test_3.mp4") > 3000
@test filesize("test.mp4") != filesize("test_2.mkv") > 3000
rm.(["test.mp4", "test_2.mkv", "test_3.mp4"])
finalize(vio); yield()
@test !isfile(tmp_path)
end

@testset "plotlist no ambiguity (#4038)" begin
Expand Down
8 changes: 6 additions & 2 deletions src/ffmpeg-util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function to_ffmpeg_cmd(vso::VideoStreamOptions, xdim::Integer=0, ydim::Integer=0
end


struct VideoStream
mutable struct VideoStream
io::Base.PipeEndpoint
process::Base.Process
screen::MakieScreen
Expand Down Expand Up @@ -229,7 +229,11 @@ function VideoStream(fig::FigureLike;
vso = VideoStreamOptions(format, framerate, compression, profile, pixel_format, loop, loglevel, "pipe:0", true)
cmd = to_ffmpeg_cmd(vso, xdim, ydim)
process = open(`$(FFMPEG_jll.ffmpeg()) $cmd $path`, "w")
return VideoStream(process.in, process, screen, buffer, abspath(path), vso)
result = VideoStream(process.in, process, screen, buffer, abspath(path), vso)
finalizer(result) do x
@async rm(x.path; force=true)

Check warning on line 234 in src/ffmpeg-util.jl

View check run for this annotation

Codecov / codecov/patch

src/ffmpeg-util.jl#L232-L234

Added lines #L232 - L234 were not covered by tests
end
return result

Check warning on line 236 in src/ffmpeg-util.jl

View check run for this annotation

Codecov / codecov/patch

src/ffmpeg-util.jl#L236

Added line #L236 was not covered by tests
end

"""
Expand Down

0 comments on commit 6deae58

Please sign in to comment.