Hi,
I would like to create a video from a set of pregenerated PNGs, but the naive way to copy the example from the docs does not work unfortunately. I’ve already adapted the example slightly to call the right(?) load() function.
What am I missing?
using Luxor
using VideoIO, ProgressMeter
function run_it()
drawing_number = 1
for i in 1:100
Drawing(250, 250, :rec)
background("white")
origin()
radius = 50
pt1 = Point(0, 0)
sethue("blue")
circle(pt1, radius, :stroke)
pt2 = rand(BoundingBox())
if distance(pt1, pt2) < radius
circle(pt2, 5, :fill)
snapshot(fname=string(@__DIR__, "/tmp/", lpad(drawing_number, 10, "0"), ".png"))
drawing_number += 1
@info "we saved a snapshot when i was $(i)"
end
end
finish()
end
run_it()
dir = string(@__DIR__, "/tmp") #path to directory holding images
imgnames = filter(x->occursin(".png",x), readdir(dir)) # Populate list of all .pngs
intstrings = map(x->split(x,".")[1], imgnames) # Extract index from filenames
p = sortperm(parse.(Int, intstrings)) #sort files numerically
imgnames = imgnames[p]
encoder_options = (crf=23, preset="medium")
firstimg = VideoIO.load(joinpath(dir, imgnames[1]))
open_video_out("video.mp4", firstimg, framerate=5, encoder_options=encoder_options) do writer
@showprogress "Encoding video frames.." for i in eachindex(imgnames)
img = VideoIO.load(joinpath(dir, imgnames[i]))
write(writer, img)
end
end
This gives an error:
ERROR: LoadError: MethodError: no method matching VideoIO.VideoWriter(::String, ::Vector{PermutedDimsArray{ColorTypes.RGB{FixedPointNumbers.N0f8}, 2, (2, 1), (2, 1), Matrix{ColorTypes.RGB{FixedPointNumbers.N0f8}}}}; framerate::Int64, encoder_options::@NamedTuple{crf::Int64, preset::String})
Closest candidates are:
VideoIO.VideoWriter(::AbstractString, !Matched::Type{T}, !Matched::Tuple{Integer, Integer}; codec_name, framerate, scanline_major, container_options, container_private_options, encoder_options, encoder_private_options, swscale_options, target_pix_fmt, pix_fmt_loss_flags, input_colorspace_details, allow_vio_gray_transform, sws_color_options, thread_count) where T
@ VideoIO ~/.julia/packages/VideoIO/ZM7RD/src/encoding.jl:234
VideoIO.VideoWriter(::Any, !Matched::AbstractMatrix{T}; kwargs...) where T
@ VideoIO ~/.julia/packages/VideoIO/ZM7RD/src/encoding.jl:379
Stacktrace:
[1] open_video_out(s::String, args::Vector{PermutedDimsArray{ColorTypes.RGB{FixedPointNumbers.N0f8}, 2, (2, 1), (2, 1), Matrix{ColorTypes.RGB{FixedPointNumbers.N0f8}}}}; kwargs::@Kwargs{framerate::Int64, encoder_options::@NamedTuple{crf::Int64, preset::String}})
@ VideoIO ~/.julia/packages/VideoIO/ZM7RD/src/encoding.jl:473
[2] open_video_out(f::var"#5#6", s::String, args::Vector{PermutedDimsArray{ColorTypes.RGB{FixedPointNumbers.N0f8}, 2, (2, 1), (2, 1), Matrix{ColorTypes.RGB{FixedPointNumbers.N0f8}}}}; kwargs::@Kwargs{framerate::Int64, encoder_options::@NamedTuple{crf::Int64, preset::String}})
@ VideoIO ~/.julia/packages/VideoIO/ZM7RD/src/encoding.jl:476
[3] top-level scope
@ ~/Documents/Julia/AdventOfCode/AoC2023/10/anim2.jl:36