Video Processing

So, I took a video and svd decomposition on all the frames and I have got all my frames together. I am to look for a package that can help me put the frames together back in a video.

But i can seem to find any. VideoIO,jl ain’t helping

Any help?

Perhaps explain why? - using this or FFMPEG.jl is the logical solution to this task.

What about record function from Makie?
https://docs.makie.org/stable/documentation/animation/index.html

Well, I wrote a function and it keeps running into an error using VideoIO.jl
I use the VideoWriter method but it doesn’t work
Here is the code

function create_video1(frames, filename="my_video.mp4")
    height, width = size(frames[1])
    
    writer = VideoIO.VideoWriter(filename)

    for frame in frames
        write(writer, frame)
    end
    close(writer)
end

and here is the error

MethodError: no method matching VideoIO.VideoWriter(::String)
Closest candidates are:
  VideoIO.VideoWriter(::Any, ::AbstractMatrix{T}; kwargs...) where T at ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:379
  VideoIO.VideoWriter(::AbstractString, ::Type{T}, ::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 at ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:234
  VideoIO.VideoWriter(::VideoIO.NestedCStruct{VideoIO.libffmpeg.AVFormatContext}, ::VideoIO.NestedCStruct{VideoIO.libffmpeg.AVCodecContext}, ::T, ::VideoIO.NestedCStruct{VideoIO.libffmpeg.AVPacket}, ::Int64, ::Bool, ::Int64) where T<:Union{VideoIO.GrayTransform, VideoIO.NestedCStruct{VideoIO.libffmpeg.AVFrame}, VideoIO.SwsTransform} at ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:4

Stacktrace:
 [1] create_video1(frames::Vector{Any}, filename::String)
   @ Main ./In[49]:4
 [2] create_video1(frames::Vector{Any})
   @ Main ./In[49]:2
 [3] top-level scope
   @ In[50]:1

Does a simple VideoIO.save(filename::String, imgstack::Array) approach work?

1 Like

Where did you get your code from?

The docs have examples to follow

https://juliaio.github.io/VideoIO.jl/stable/writing/#Iterative-Encoding

I had this error

ArgumentError: Encoding arrays with eltype RGB{Float32} not yet supported

Stacktrace:
  [1] VideoIO.VideoWriter(filename::String, ::Type{RGB{Float32}}, sz::Tuple{Int64, Int64}; codec_name::Nothing, framerate::Int64, scanline_major::Bool, container_options::NamedTuple{(), Tuple{}}, container_private_options::NamedTuple{(), Tuple{}}, encoder_options::NamedTuple{(), Tuple{}}, encoder_private_options::NamedTuple{(), Tuple{}}, swscale_options::NamedTuple{(), Tuple{}}, target_pix_fmt::Nothing, pix_fmt_loss_flags::Int64, input_colorspace_details::Nothing, allow_vio_gray_transform::Bool, sws_color_options::NamedTuple{(), Tuple{}}, thread_count::Nothing)
    @ VideoIO ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:265
  [2] VideoWriter
    @ ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:234 [inlined]
  [3] #VideoWriter#46
    @ ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:379 [inlined]
  [4] VideoWriter
    @ ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:379 [inlined]
  [5] #open_video_out#47
    @ ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:473 [inlined]
  [6] open_video_out
    @ ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:473 [inlined]
  [7] open_video_out(f::VideoIO.var"#50#51"{Vector{Any}}, s::String, args::Matrix{RGB{Float32}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ VideoIO ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:476
  [8] open_video_out(f::Function, s::String, args::Matrix{RGB{Float32}})
    @ VideoIO ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:475
  [9] save(filename::String, imgstack::Vector{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ VideoIO ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:501
 [10] save(filename::String, imgstack::Vector{Any})
    @ VideoIO ~/.julia/packages/VideoIO/3Y2nb/src/encoding.jl:500
 [11] top-level scope
    @ In[52]:1

Oh, it doesn’t support some of the RGB types… :frowning:

This works:

using Images
using VideoIO

imgstack = [
        [RGB{N0f8}(rand(), rand(), rand()) 
            for r in 1:10, c in 1:10]
        for i in 1:100
        ]

save("/tmp/movie.mp4", imgstack)


so perhaps you’ll have to tweak the images into an acceptable format. The documentation may have more information…