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

Hey @RodionLV is the idea that you’re uploading an MP4 video to a liveview app and you need to get a preview?

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
6 Likes