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

Test #3697 #3798

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -3,6 +3,7 @@
## [Unreleased]

- Improved thread safety of rendering with CairoMakie (independent `Scene`s only) by locking FreeType handles [#3777](https://github.com/MakieOrg/Makie.jl/pull/3777).
- Added `loop` option support for HTML outputs when recording videos with `record` [#3697](https://github.com/MakieOrg/Makie.jl/pull/3697).

## [0.20.9] - 2024-03-29

Expand Down
5 changes: 1 addition & 4 deletions docs/explanations/animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ nframes = 30
framerate = 30
hue_iterator = range(0, 360, length=nframes)

record(fig, "color_animation.mp4", hue_iterator;
Record(fig, hue_iterator;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it seems like Franklin isn't displaying the output - that should probably be corrected...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makie.jl/docs/utils.jl

Lines 93 to 99 in f51eb52

sz = size(Makie.parent_scene(__result)) # hide
open(joinpath(@OUTPUT, "$(name)_size.txt"), "w") do io # hide
print(io, sz[1], " ", sz[2]) # hide
end # hide
save(joinpath(@OUTPUT, "$pngfile"), __result; px_per_unit = 2, pt_per_unit = 0.75, $rest_kwargs_str) # hide
$(svg ? "save(joinpath(@OUTPUT, \"$svgfile\"), __result; px_per_unit = 2, pt_per_unit = 0.75, $rest_kwargs_str)" : "") # hide
nothing # hide

needs some kind of dispatch on VideoStream objects, to return gifs...

framerate = framerate) do hue
lineplot.color = HSV(hue, 1, 0.75)
end
nothing # hide
```

\video{color_animation}

Passing a function as the first argument is usually done with Julia's `do`-notation, which you might not be familiar with.
Instead of the above, we could also have written:

Expand Down
15 changes: 6 additions & 9 deletions src/ffmpeg-util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
you have issues playing a video, try `profile = "high"` or `profile = "main"`.
- `pixel_format = "yuv420p"`: A ffmpeg compatible pixel format (`-pix_fmt`). Currently only
applies to `mp4`. Defaults to `yuv444p` for `profile = "high444"`.
- `loop = 0`: Number of times the video is repeated, for a `gif`. Defaults to `0`, which
means infinite looping. A value of `-1` turns off looping, and a value of `n > 0` and above
means `n` repetitions (i.e. the video is played `n+1` times).
- `loop = 0`: Number of times the video is repeated, for a `gif` or `html` output. Defaults to `0`, which
means infinite looping. A value of `-1` turns off looping, and a value of `n > 0`
means `n` repetitions (i.e. the video is played `n+1` times) when supported by backend.

!!! warning
`profile` and `pixel_format` are only used when `format` is `"mp4"`; a warning will be issued if `format`
is not `"mp4"` and those two arguments are not `nothing`. Similarly, `compression` is only
valid when `format` is `"mp4"` or `"webm"`, and `loop` is only valid when `format` is `"gif"`.
valid when `format` is `"mp4"` or `"webm"`.
"""
struct VideoStreamOptions
format::String
Expand Down Expand Up @@ -63,15 +63,12 @@ struct VideoStreamOptions
(compression === nothing) && (compression = 20)
end

if format == "gif"
(loop === nothing) && (loop = 0)
end
(loop === nothing) && (loop = 0)

# items are name, value, allowed_formats
allowed_kwargs = [("compression", compression, ("mp4", "webm")),
("profile", profile, ("mp4",)),
("pixel_format", pixel_format, ("mp4",)),
("loop", loop, ("gif",))]
("pixel_format", pixel_format, ("mp4",))]

for (name, value, allowed_formats) in allowed_kwargs
if !(format in allowed_formats) && value !== nothing
Expand Down
4 changes: 3 additions & 1 deletion src/recording.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ end
function Base.show(io::IO, ::MIME"text/html", vs::VideoStream)
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><source src="data:video/x-m4v;base64,""",
"""<video autoplay controls $loopoption><source src="data:video/x-m4v;base64,""",
base64encode(open(read, path)),
"""" type="video/mp4"></video>"""
)
Expand Down
Loading