Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML video size annotation #4563

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Expand PlotList plots to expose their child plots to the legend interface, allowing `axislegend`show plots within PlotSpecs as individual entries. [#4546](https://github.com/MakieOrg/Makie.jl/pull/4546)
- Implement S.Colorbar(plotspec) [#4520](https://github.com/MakieOrg/Makie.jl/pull/4520).
- Fixed a hang when `Record` was created inside a closure passed to `IOCapture.capture` [#4562](https://github.com/MakieOrg/Makie.jl/pull/4562).
- Added logical size annotation to `text/html` inline videos so that sizes are appropriate independent of the current `px_per_unit` value [#4563](https://github.com/MakieOrg/Makie.jl/pull/4563).

## [0.21.15] - 2024-10-25

Expand Down
9 changes: 8 additions & 1 deletion CairoMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ end
@testset "VideoStream & screen options" begin
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),))
width = 600
height = 800
f, ax, pl = scatter(points, axis=(type=Axis, aspect=DataAspect(), limits=(0.4, N + 0.6, 0.4, N + 0.6),), figure=(size=(width, height),))

vio = Makie.VideoStream(f; format="mp4", px_per_unit=2.0, backend=CairoMakie)
tmp_path = vio.path
Expand All @@ -132,6 +134,11 @@ end
@test vio.screen.device_scaling_factor == 2.0

Makie.recordframe!(vio)

html = repr(MIME"text/html"(), vio)
@test occursin("width=\"$width\"", html)
@test occursin("height=\"$height\"", html)

save("test.mp4", vio)
save("test_2.mkv", vio)
save("test_3.mp4", vio)
Expand Down
7 changes: 6 additions & 1 deletion src/recording.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,18 @@ function Record(func, figlike, iter; kw_args...)
end

function Base.show(io::IO, ::MIME"text/html", vs::VideoStream)
scene = vs.screen.scene
if !(scene isa Scene)
jkrumbiegel marked this conversation as resolved.
Show resolved Hide resolved
error("Expected Screen to hold a reference to a Scene but got $(repr(scene))")
end
w, h = scene.viewport[].widths
mktempdir() do dir
path = save(joinpath(dir, "video.mp4"), vs)
# <video> only supports infinite looping, so we loop forever even when a finite number is requested
loopoption = vs.options.loop ≥ 0 ? "loop" : ""
print(
io,
"""<video autoplay controls $loopoption><source src="data:video/x-m4v;base64,""",
"""<video autoplay controls $loopoption width="$w" height="$h"><source src="data:video/x-m4v;base64,""",
base64encode(open(read, path)),
"""" type="video/mp4"></video>"""
)
Expand Down
Loading