Skip to content

Instantly share code, notes, and snippets.

@Wigny
Created June 11, 2023 07:29
Show Gist options
  • Save Wigny/3800dfce66b64b2dee1480f33378203d to your computer and use it in GitHub Desktop.
Save Wigny/3800dfce66b64b2dee1480f33378203d to your computer and use it in GitHub Desktop.
Mix.install([evision: "~> 0.1"],
system_env: [
EVISION_PREFER_PRECOMPILED: "false",
CMAKE_OPENCV_OPTIONS: "-D WITH_FFMPEG=ON"
]
)
alias Evision.VideoCapture
url = "rtsp://172.28.6.108:8554/mystream"
Stream.resource(
fn -> VideoCapture.videoCapture(url, apiPreference: Evision.Constant.cv_CAP_FFMPEG()) end,
fn
%{isOpened: true} = video ->
frame = if VideoCapture.grab(video), do: VideoCapture.retrieve(video)
{[frame], video}
%{isOpened: false} = video ->
{:halt, video}
end,
fn video -> VideoCapture.release(video) end
)
|> Stream.each(&IO.inspect/1)
|> Stream.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment