JuliaIO / VideoIO.jl

Reading and writing of video files in Julia via ffmpeg
https://juliaio.github.io/VideoIO.jl/stable
Other
125 stars 53 forks source link

encoding Gray images from Images #336

Open drdozer opened 2 years ago

drdozer commented 2 years ago

I've made a stack of images using the Gray pixel type from Images. When I tried to render this stack as a movie with save I got this stack-trace. It seems Gray is not supported. I've no idea how to kludge this, other than by me converting the gray to some other format prior to saving it.

save("cgvideo.mp4", worlds, framerate=framerate)
ArgumentError: Encoding arrays with eltype ColorTypes.Gray not yet supported

Stacktrace:

[1] VideoIO.VideoWriter(filename::String, ::Type{ColorTypes.Gray}, 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/w6BET/src/encoding.jl:253

[2] #VideoWriter#30

@ ~/.julia/packages/VideoIO/w6BET/src/encoding.jl:369 [inlined]

[3] #open_video_out#31

@ ~/.julia/packages/VideoIO/w6BET/src/encoding.jl:463 [inlined]

[4] open_video_out(f::VideoIO.var"#34#35"{Vector{Matrix{ColorTypes.Gray}}}, s::String, args::Matrix{ColorTypes.Gray}; kwargs::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}})

@ VideoIO ~/.julia/packages/VideoIO/w6BET/src/encoding.jl:467

[5] #save#33

@ ~/.julia/packages/VideoIO/w6BET/src/encoding.jl:492 [inlined]

[6] #fileio_save#39

@ ~/.julia/packages/VideoIO/w6BET/src/VideoIO.jl:113 [inlined]

[7] invokelatest(::Any, ::Any, ::Vararg{Any, N} where N; kwargs::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}})

@ Base ./essentials.jl:710

[8] action(call::Symbol, libraries::Vector{Union{Base.PkgId, Module}}, file::FileIO.Formatted, args::Vector{Matrix{ColorTypes.Gray}}; options::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}})

@ FileIO ~/.julia/packages/FileIO/DNKwN/src/loadsave.jl:219

[9] action(call::Symbol, libraries::Vector{Union{Base.PkgId, Module}}, sym::Symbol, file::String, args::Vector{Matrix{ColorTypes.Gray}}; options::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}})

@ FileIO ~/.julia/packages/FileIO/DNKwN/src/loadsave.jl:185

[10] save(file::String, args::Vector{Matrix{ColorTypes.Gray}}; options::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}})

@ FileIO ~/.julia/packages/FileIO/DNKwN/src/loadsave.jl:129

[11] ##function_wrapped_cell#545

@ ~/.julia/pluto_notebooks/Surprising report.jl#==#8fdb5398-66b2-4cc7-86c0-990eb5554150:1 [inlined]

[12] var"##function_wrapped_cell#545"(save::Function, framerate::Int64, worlds::Vector{Matrix{ColorTypes.Gray}})

@ Main ./none:0

[13] invokelatest(::Any, ::Any, ::Vararg{Any, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})

@ Base ./essentials.jl:708

[14] invokelatest(::Any, ::Any, ::Vararg{Any, N} where N)

@ Base ./essentials.jl:706

[15] compute(m::Module, computer::Main.PlutoRunner.Computer)

@ Main.PlutoRunner ~/.julia/packages/Pluto/nkHsc/src/runner/PlutoRunner.jl:252

[16] (::Main.PlutoRunner.var"#7#8"{Module})()

@ Main.PlutoRunner ~/.julia/packages/Pluto/nkHsc/src/runner/PlutoRunner.jl:366

[17] run_inside_trycatch(m::Module, f::Main.PlutoRunner.var"#7#8"{Module}, return_proof::Main.PlutoRunner.ReturnProof)

@ Main.PlutoRunner ~/.julia/packages/Pluto/nkHsc/src/runner/PlutoRunner.jl:301

[18] run_expression(m::Module, expr::Expr, cell_id::Base.UUID, function_wrapped_info::Tuple{Set{Symbol}, Set{Symbol}}, contains_user_defined_macrocalls::Bool)

@ Main.PlutoRunner ~/.julia/packages/Pluto/nkHsc/src/runner/PlutoRunner.jl:366

[19] top-level scope

@ none:1

handle_error(::ArgumentError, ::Base.PkgId, ::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}})@error_handling.jl:61
handle_exceptions(::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector{T} where T}}, ::String)@error_handling.jl:56
var"#action#33"(::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}}, ::typeof(FileIO.action), ::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted, ::Vector{Matrix{ColorTypes.Gray}})@loadsave.jl:228
var"#action#32"(::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}}, ::typeof(FileIO.action), ::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::Symbol, ::String, ::Vector{Matrix{ColorTypes.Gray}})@loadsave.jl:185
var"#save#20"(::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}}, ::typeof(FileIO.save), ::String, ::Vector{Matrix{ColorTypes.Gray}})@loadsave.jl:129
top-level scope@Local: 1[inlined]
timholy commented 2 years ago

A workaround might be to lazy-convert so you don't have to allocate memory:

using MappedArrays
worldsrgb = to_eltype(RGB, worlds)
save(...)

But ideally what would be done automatically here, care to try making a pull request?