JuliaIO / VideoIO.jl

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

Help! Read Video Data as a collection of frames?! #211

Closed abadredd closed 3 years ago

abadredd commented 4 years ago

Hey Guys,

Im relativity new to Julia and Im attempting to read a .mp4 video as a collection of frames. So far I have come across two methods to read the .mp4 data but having trouble reshaping them into the format I want.

img=read(open("PeopleWalking.mp4"))
img = Float64.(img)
@show size(img);
@show typeof(img);

The problem with this is the data read is in the form of

7606633-element Array{UInt8,1}

..... and I cant really make sense of it in terms of what portions of the data correspond to what frame,

f = VideoIO.openvideo("PeopleWalking.mp4")
img=read(f)
size(img)

The problem here the data is in this format 1080×1920 PermutedDimsArray(::Array{RGB{N0f8},2}, (2, 1)) with eltype RGB{FixedPointNumbers.Normed{UInt8,8}}:

Also when I try to play the video here I get

julia> VideoIO.playvideo(f)
ERROR: MethodError: no method matching VideoIO.VideoReader(::VideoIO.VideoReader{true})

My GOAL: Find a way to convert the video data to a 3 dimensional matrix cube where the third dimension corresponds to the number of frames of the video and the colums and rows of each frame are of type Float64, to eventually utilize SVDS on the data and perform back substitution svds(reshape(movie_cube, :, size(movie_cube, 3)), nsv=k)[1]

yakir12 commented 4 years ago

This should work:

using VideoIO
io = VideoIO.testvideo("annie_oakley")
f = VideoIO.openvideo(io)
img = read(f)
frames = Vector{typeof(copy(img))}(undef, 0)
push!(frames, copy(img))
while !eof(f)
    read!(f, img)
    push!(frames, copy(img))
end
close(f)
a = cat(frames..., dims = 3)

Note however that this is more of a help request than an actual issue with VideoIO.jl. Next time use Julia Discourse or the julia#video channel on slack for such cases.

IanButterworth commented 3 years ago

There are some simpler ways to do this now in v0.9