Skip to content

Commit

Permalink
support the loop option in html video output (#3697)
Browse files Browse the repository at this point in the history
* support the loop option in html video output

* add to changelog

* try adding html animation to docs

* Update animation.md

* revert doc animation changes

* fix warning test

---------

Co-authored-by: Anshul Singhvi <asinghvi17@simons-rock.edu>
  • Loading branch information
aplavin and asinghvi17 authored May 16, 2024
1 parent d8ae9e0 commit 50e2085
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- Provided an interface to convert markers in CairoMakie separately (`cairo_scatter_marker`) so external packages can overload it. [#3811](https://github.com/MakieOrg/Makie.jl/pull/3811)
- Updated to DelaunayTriangulation v1.0 [#3787](https://github.com/MakieOrg/Makie.jl/pull/3787).
- Added methods `hidedecorations!`, `hiderdecorations!`, `hidethetadecorations!` and `hidespines!` for `PolarAxis` axes [#3823](https://github.com/MakieOrg/Makie.jl/pull/3823).
- 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
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
1 change: 0 additions & 1 deletion test/record.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ mktempdir() do tempdir
warn_fmts=["mkv", "webm", "gif"],
no_warn_fmts=["mp4"],
),
(:loop, 0, ["mkv", "webm", "mp4"], ["gif"]),
]

for (kwarg, value, warn_fmts, no_warn_fmts) in warn_tests
Expand Down

0 comments on commit 50e2085

Please sign in to comment.