Rich_Morin

Rich_Morin

Extracting selected images from downloaded video files?

I want to extract selected images from downloaded video files. I’d like to know whether Membrane is a reasonable tool for this job, whether anyone else has done similar tasks with it, etc. I’m also unsure about how its “pipeline” approach would fit a “random access” use case.

For purposes of discussion, assume that I’ll be using VLC media player to download videos from web sites such as YouTube, storing them as MP4 files. Because I’ll be processing the images, I’d like to get them into Nx tensor format.

Can someone give me some advice, clues, and/or suggestions?

Most Liked

kip

kip

ex_cldr Core Team

As of image version 0.21.0 which I just published you can leverage the Evision.VideoCapture module to extract images from a video.

You can therefore use either the more idiomatic API in Image.Video or simply leverage the code that is there to use Evision directly.

Depending on the codec support of the OpenCV installation on your system I suspect you may not need to use the FFMEG CLI approach any more.

Example using Image

# Extract using a frame offset
iex> {:ok, video} = Image.Video.open("./test/support/video/video_sample.mp4")
iex> {:ok, _image} = Image.Video.image_from_video(video, frame: 0)

# Extract using a millisecond offset
iex> {:ok, _image} = Image.Video.image_from_video(video, millisecond: 0)

# Capturing images from a camera (note that seeking is not supported
# on image streams. On MacOS you will receive a prompt to permit the
# app to access the camera. You may need to restart the BEAM and/or
# your system if capturing fails immediately after granting permission.
iex> {:ok, video} = Image.Video.open(:default_camera)
iex> {:ok, _image} = Image.Video.image_from_video(video)

Example using Evision directly

# Extract by frame offset
video = Evision.VideoCapture.videoCapture(video_filename)
true = Evision.VideoCapture.set(video, Evision.cv_CAP_PROP_POS_FRAMES(), frame_offset),
cv_image = Evision.VideoCapture.read(video)

Using images in Nx

Both Image and Evision support zero-copy “export” of images to Nx. Just call Image.to_nx/1 or Evision.Mat.to_nx/1 as appropriate.

kwando

kwando

I would use ffmpeg to extract images from the video files. Could probably skip VLC and use ffmpeg directly as well.

Then loading the extracted images from disk and do whatever I have to do in nx :slight_smile:

Probably not gonna be the most efficient way of doing it, but might be good enough :slight_smile:

No idea on how membrane works.

kokolegorille

kokolegorille

I am also using ffmpeg to extract images from video, there is a ffmpex wrapper, but I wrote a simple one.

Membrane is good if You want to receive or stream rtmp, or webrtc…

But for YT, I would check this python package, and maybe use erlport to interface python script.

https://github.com/pytube/pytube

There are tools to transform images from/to nx…

by @kip

and

by @cocoa

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement