RodionLV

RodionLV

How to get a frame from a video for example in jpeg format using ffmpeg?

I need to get the first frame from an mp4 video for my task in order to use it as a preview

Marked As Solved

kip

kip

ex_cldr Core Team

You can get image frames from video with image. For example:

iex> {:ok, video} = Image.Video.open("./test/support/video/video_sample.mp4")
iex> {:ok, image} = Image.Video.image_from_video(video, millisecond: 0)

# Save the image as a jpeg. Or process it further.
iex> Image,write(image, "/some/path/to/image.jpg")

The implementation uses the fabulous eVision which is a required dependency if you do this in image.

Of course you can use evision directly:

# Open the video file
iex> {:ok, video} = VideoCapture.videoCapture(filename, apiPreference: backend)

# Seek to either the frame or milliseconds
iex> {:ok, video} = VideoCapture.set(video, Constant.cv_CAP_PROP_POS_FRAMES(), frame)
iex> {:ok, video} = VideoCapture.set(video, Constant.cv_CAP_PROP_POS_MSEC(), millis)

# Capture the frame as an evision matrix
iex> evision_matrix = VideoCapture.read(video)

# Then save as a jpeg or process further

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
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
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New

We're in Beta

About us Mission Statement