# Video creation example does not work to naive way

**URL:** https://discourse.julialang.org/t/video-creation-example-does-not-work-to-naive-way/111888
**Category:** New to Julia
**Tags:** videoio
**Created:** [March 20, 2024, 4:13pm UTC](https://discourse.julialang.org/t/video-creation-example-does-not-work-to-naive-way/111888 "2024-03-20T16:13:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Julia2001](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@Julia2001](https://discourse.julialang.org/u/Julia2001)
#### Post date: [March 20, 2024, 4:13pm UTC](https://discourse.julialang.org/t/video-creation-example-does-not-work-to-naive-way/111888/1 "2024-03-20T16:13:32Z")

</div>

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](https://juliaio.github.io/VideoIO.jl/stable/writing/#Iterative-Encoding) does not work unfortunately. I’ve already adapted the example slightly to call the right(?) load() function.  
What am I missing?

```julia
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:

```julia
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

```

---

<div class="post-metadata">

### Author: ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)
#### Post date: [March 20, 2024, 4:37pm UTC](https://discourse.julialang.org/t/video-creation-example-does-not-work-to-naive-way/111888/2 "2024-03-20T16:37:23Z")

</div>

You’re using `VideoIO.load` to load the images. You should be using an Image loading package for that. i.e. ImageIO via FileIO

---

<div class="post-metadata">

### Author: ![Julia2001](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@Julia2001](https://discourse.julialang.org/u/Julia2001)
#### Post date: [March 20, 2024, 7:02pm UTC](https://discourse.julialang.org/t/video-creation-example-does-not-work-to-naive-way/111888/3 "2024-03-20T19:02:48Z")

</div>

I’ve added “using FileIO”. Now it works.  
Thanks!
