Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
add video recording example (#152)
Browse files Browse the repository at this point in the history
* don't create folder if not needed

* add example for recording a video

* remove old comment

* add more comments

* remove GL

* try our own tmpdir

* use GLWindow
  • Loading branch information
SimonDanisch committed Mar 15, 2017
1 parent 3de3140 commit 1f9f071
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
47 changes: 47 additions & 0 deletions examples/introduction/video_recording.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Colors, GLVisualize, GLAbstraction, GLWindow

if !isdefined(:runtests)
window = glscreen()
end
description = """
Example of how to record a video from GLVisualize
"""
kitty = visualize(loadasset("cat.obj"))
_view(kitty, window)

# save video to report dir, or in some tmp dir we'll delete later
path = if haskey(ENV, "CI_REPORT_DIR")
ENV["CI_REPORT_DIR"] * "/videorecord.mkv"
else
homedir()
end
name = ""
while true # for some reason, folder retured by mktempdir isn't usable -.-
name = path * "/$(randstring()).mkv"
isfile(name) || break
end

# create a stream to which we can add frames
io, buffer = GLVisualize.create_video_stream(name, window)
for i=1:10 # record 10 frames
# do something
GLAbstraction.set_arg!(kitty, :color, RGBA{Float32}(1, 0, 1-(i/10), i/10))
#render current frame
# if you call @async renderloop(window) you can replace this part with yield
GLWindow.render_frame(window)
GLWindow.swapbuffers(window)
GLWindow.poll_reactive()

# add the frame from the current window
GLVisualize.add_frame!(io, window, buffer)
end
# closing the stream will trigger writing the video!
close(io)

if !isdefined(:runtests)
renderloop(window)
end
# clean up, only when we're not recording this!
if !haskey(ENV, "CI_REPORT_DIR")
rm(name)
end
8 changes: 5 additions & 3 deletions test/test_static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ config = ExampleRunner.RunnerConfig(
)
window = config.window

imgpath = joinpath(full_folder, "images")
isdir(imgpath) || mkdir(imgpath)
if recording
imgpath = joinpath(full_folder, "images")
isdir(imgpath) || mkdir(imgpath)
end

for path in config.files
isopen(config.rootscreen) || break
Expand Down Expand Up @@ -117,7 +119,7 @@ end
if recording
open(joinpath(full_folder, "report.md"), "w") do io
println(io, "### Test Images:")
create_mosaic(io, full_folder)
create_mosaic(io, imgpath)
if !isempty(failures)
println(io, "### Failures:")
for (k, dict) in failures
Expand Down

0 comments on commit 1f9f071

Please sign in to comment.