using GLMakie: FileIO using Base64 gif_html(blob) = "" mp4_html(blob) = """""" function table_html(cells::AbstractMatrix) rows_html = map(eachrow(cells)) do row "" * join(map(cell -> "$cell", row)) * "" end return "" * join(rows_html) * "
" end struct VideoDisplay videostream::Makie.VideoStream end Base.show(io::IO, ::MIME"juliavscode/html", vd::VideoDisplay) = show(io, MIME"text/html"(), vd) function Base.show(io::IO, ::MIME"text/html", vd::VideoDisplay) # Save to file if not already saved format = vd.videostream.options.format dir = mktempdir() path = joinpath(dir, "$(gensym(:video)).$(format)") FileIO.save(path, vd.videostream) # Display vdation as HTML tag, depending on format if format == "gif" # Display GIFs as image tags blob = base64encode(read(path)) print(io, gif_html(blob)) elseif format == "mp4" # Display MP4 videos as video tags blob = base64encode(read(path)) print(io, mp4_html(blob)) else # Convert other video types to MP4 mktempdir() do dir path = joinpath(dir, "video.mp4") FileIO.save(path, vd.videostream) blob = base64encode(read(path)) print(io, mp4_html(blob)) end end end struct MultiVideoDisplay videostreams::Vector{Makie.VideoStream} shape::Tuple{Int, Int} end MultiVideoDisplay(videostreams) = MultiVideoDisplay(videostreams, (length(videostreams), 1)) Base.show(io::IO, ::MIME"juliavscode/html", vd::MultiVideoDisplay) = show(io, MIME"text/html"(), vd) function Base.show(io::IO, ::MIME"text/html", vd::MultiVideoDisplay) cells = map(vd.videostreams) do videostream # Save to file if not already saved format = videostream.options.format dir = mktempdir() path = joinpath(dir, "$(gensym(:video)).$(format)") FileIO.save(path, videostream) # Display vdation as HTML tag, depending on format if format == "gif" # Display GIFs as image tags blob = base64encode(read(path)) return gif_html(blob) elseif format == "mp4" # Display MP4 videos as video tags blob = base64encode(read(path)) return mp4_html(blob) else # Convert other video types to MP4 mktempdir() do dir path = joinpath(dir, "video.mp4") FileIO.save(path, vd.videostream) blob = base64encode(read(path)) return mp4_html(blob) end end end cells = reshape(cells, vd.shape) print(io, table_html(cells)) end function activate_figure!(figure; config...) backend = Makie.current_backend() scene = Makie.get_scene(figure) config = Dict{Symbol,Any}(config) screen = Makie.getscreen(backend, scene, config) Makie.push_screen!(scene, screen) return figure end