Skip to content

Commit

Permalink
Remove Requires-based GLMakie video player functions (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Mar 17, 2024
1 parent e5bb24f commit 6f965b6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 174 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
VideoIO v1.1.0 Release Notes
======================
## Removal

- The GLMakie-based video player that was accessed through Requires by loading GLMakie separately has been removed
after being deprecated in v1.0.8.


VideoIO v0.9 Release Notes
======================
## New features
Expand Down
7 changes: 1 addition & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "VideoIO"
uuid = "d6d074c3-1acf-5d4c-9a43-ef38773959a2"
version = "1.0.9"
version = "1.1.0"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand All @@ -11,10 +11,7 @@ FFMPEG_jll = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"

[compat]
Expand All @@ -26,7 +23,5 @@ FileIO = "1.6"
Glob = "1.2"
ImageCore = "0.8, 0.9, 0.10"
PrecompileTools = "1"
ProgressMeter = "1.2"
Requires = "1.0"
Scratch = "1"
julia = "1.6"
76 changes: 1 addition & 75 deletions docs/src/reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,49 +103,6 @@ while !eof(f)
end
close(f)
```

## Video Playback

A trivial video player interface exists (no audio) through `GLMakie.jl`.
Note: `GLMakie` must be imported first to enable playback functionality.

```julia
using GLMakie
using VideoIO

f = VideoIO.testvideo("annie_oakley") # downloaded if not available
VideoIO.playvideo(f) # no sound
```

Customization of playback can be achieved by looking at the basic expanded version of this function:

```julia
import GLMakie
import VideoIO

#io = VideoIO.open(video_file)
io = VideoIO.testvideo("annie_oakley") # for testing purposes
f = VideoIO.openvideo(io)

img = read(f)
obs_img = GLMakie.Observable(GLMakie.rotr90(img))
scene = GLMakie.Scene(camera=GLMakie.campixel!, resolution=reverse(size(img)))
GLMakie.image!(scene, obs_img)

display(scene)

fps = VideoIO.framerate(f)
while !eof(f) && GLMakie.isopen(scene)
img = read(f)
obs_img[] = GLMakie.rotr90(img)
sleep(1 / fps)
end

```
This code is essentially the code in `playvideo`, and will read and
(without the `sleep`) play a movie file as fast as possible.


## Reading Camera Output
Frames can be read iteratively
```julia
Expand Down Expand Up @@ -174,7 +131,7 @@ julia> opts["video_size"] = "640x480"
julia> opencamera(VideoIO.DEFAULT_CAMERA_DEVICE[], VideoIO.DEFAULT_CAMERA_FORMAT[], opts)
VideoReader(...)
```

Or more simply, change the default. For example:
```julia
julia> VideoIO.DEFAULT_CAMERA_OPTIONS["video_size"] = "640x480"
Expand All @@ -184,37 +141,6 @@ julia> VideoIO.DEFAULT_CAMERA_OPTIONS["framerate"] = 30
julia> julia> opencamera()
VideoReader(...)
```
### Webcam playback
The default system webcam can be viewed directly
```julia
using GLMakie
using VideoIO
VideoIO.viewcam()
```

An expanded version of this approach:
```julia
import GLMakie, VideoIO

cam = VideoIO.opencamera()
try
img = read(cam)
obs_img = GLMakie.Observable(GLMakie.rotr90(img))
scene = GLMakie.Scene(camera=GLMakie.campixel!, resolution=reverse(size(img)))
GLMakie.image!(scene, obs_img)

display(scene)

fps = VideoIO.framerate(cam)
while GLMakie.isopen(scene)
img = read(cam)
obs_img[] = GLMakie.rotr90(img)
sleep(1 / fps)
end
finally
close(cam)
end
```

## Video Properties & Metadata
```@docs
Expand Down
95 changes: 2 additions & 93 deletions src/VideoIO.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module VideoIO

using Libdl
using Requires, Dates, ProgressMeter
using ImageCore: channelview, rawview
using ColorTypes: RGB, Gray, N0f8, N6f10, YCbCr, Normed, red, green, blue
using Dates
using FileIO: File
using ImageCore: channelview, rawview
using PrecompileTools

using Base: fieldindex, RefValue, cconvert
Expand Down Expand Up @@ -98,106 +97,16 @@ elseif Sys.isbsd()
end
end

#Helper functions to explain about GLMakie load order requirement
function play(f; flipx = false, flipy = false)
return error(
"GLMakie must be loaded before VideoIO to provide video playback functionality. Try a new session with `using GLMakie, VideoIO`",
)
end
function playvideo(video; flipx = false, flipy = false)
return error(
"GLMakie must be loaded before VideoIO to provide video playback functionality. Try a new session with `using GLMakie, VideoIO`",
)
end
function viewcam(device = DEFAULT_CAMERA_DEVICE, format = DEFAULT_CAMERA_FORMAT)
return error(
"GLMakie must be loaded before VideoIO to provide camera playback functionality. Try a new session with `using GLMakie, VideoIO`",
)
end

## FileIO interface
fileio_load(f::File; kwargs...) = load(f.filename; kwargs...)
fileio_save(f::File, video; kwargs...) = save(f.filename, video; kwargs...)

function __init__()
# Always check your dependencies from `deps.jl`
# TODO remove uncessary ENV["LD_LIBRARY_PATH"] from check_deps, so that
# it doesn't mess with LD_LIBRARY_PATH, which was causing CI download issues due to issues with julia's curl
# since check_deps is optional, I hope this is ok for now

#check_deps()

loglevel!(libffmpeg.AV_LOG_FATAL)
# @info "VideoIO: Low-level FFMPEG reporting set to minimal (AV_LOG_FATAL). See `? VideoIO.loglevel!` for options"

read_packet[] = @cfunction(_read_packet, Cint, (Ptr{AVInput}, Ptr{UInt8}, Cint))

av_register_all()

libffmpeg.avdevice_register_all()

@require GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" begin
# Define read and retrieve for Images
function play(f; flipx = false, flipy = false, pixelaspectratio = nothing)
@warn "This GLMakie-based `play` function is deprecated and will be removed in a future release." maxlog = 1
eof(f) && error("VideoReader at end of file. Use `seekstart(f)` to rewind")
# if user did not specify the aspect ratio we'll try to use the one stored in the video file
if pixelaspectratio === nothing
pixelaspectratio = aspect_ratio(f)
end
h = height(f)
w = round(typeof(h), width(f) * pixelaspectratio) # has to be an integer
flips_to_dims = Dict(
(true, true) => (1, 2),
(true, false) => 1,
(false, true) => 2,
(false, false) => nothing,
)
flipping_dims = flips_to_dims[(flipx, flipy)]
flipping = i -> i
if flipping_dims !== nothing
flipping = i -> reverse(i, dims = flipping_dims)
end
flip_and_rotate = i -> begin
rotated = GLMakie.rotr90(i)
flipping(rotated)
end
img = read(f)
obs_img = GLMakie.Observable(flip_and_rotate(img))
scene =
GLMakie.Scene(camera = GLMakie.campixel!, resolution = reverse(size(img)))

GLMakie.image!(scene, obs_img)
display(scene)
# issue 343: camera can't run at full speed on MacOS
fps = Sys.isapple() ? min(framerate(f), 24) : framerate(f)
while isopen(scene) && !eof(f)
read!(f, img)
obs_img[] = flip_and_rotate(img)
sleep(1 / fps)
end
end

function playvideo(video; flipx = false, flipy = false, pixelaspectratio = nothing)
@warn "This GLMakie-based `playvideo` function is deprecated and will be removed in a future release." maxlog = 1
f = VideoIO.openvideo(video)
try
play(f, flipx=flipx, flipy=flipy, pixelaspectratio=pixelaspectratio)
finally
close(f)
end
end

function viewcam(device=nothing, format=nothing, options=nothing, pixelaspectratio=nothing)
@warn "This GLMakie-based `viewcam` function is deprecated and will be removed in a future release." maxlog = 1
camera = opencamera(device, format, options)
try
play(camera; flipx=true, pixelaspectratio)
finally
close(camera)
end
end
end
end

@setup_workload begin
Expand Down

2 comments on commit 6f965b6

@IanButterworth
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

  • The experimental deprecated Requires-based GLMakie video player has been removed

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/103029

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.0 -m "<description of version>" 6f965b620b1c2760a6756ee44faa96a5ccbc3d43
git push origin v1.1.0

Please sign in to comment.