Following my (dumb) question and reading this
I managed to connect to my cam, get the flow from it and dump it into an mpeg file. Here is the code for more clarity.
test "request headers from cam" do
options = [basic_auth: {"LOGIN","PASSWORD"}, ibrowse: [{:save_response_to_file, true}]]
{:ok, %HTTPoison.AsyncResponse{id: id}} = HTTPoison.get "http://x.x.x.x/axis-cgi/mjpg/video.cgi?duration=2&resolution=320x240",[], [stream_to: self, recv_timeout: :infinity, hackney: options
]
{:ok, file} = File.open("/tmp/test.mpeg", [:write])
retour = stream_to_file(id,file)
send self,{:retour, retour}
assert_receive {:retour ,:ok}, 10_000
end
defp stream_to_file(id, output) do
receive do
%HTTPoison.AsyncStatus{ id: ^id, code: code} ->
IO.puts " AsyncStatus"
stream_to_file(id,output)
%HTTPoison.AsyncHeaders{ id: ^id} ->
stream_to_file(id,output)
%HTTPoison.AsyncEnd{ id: ^id} ->
IO.puts " AsyncEnd received"
:ok
%HTTPoison.AsyncChunk{id: ^id, chunk: chunk} ->
IO.binwrite(output, chunk)
stream_to_file(id, output)
end
end
Test is running fine, a file is generated as expected but when i try to read it (using a couple of player), i can surreptitiously see one image from the cam and it stops rightafter.
Size (depending on parameters) can be important and when editing the file, i can clearly guess these are successive Jpeg files.
Here is the beginning of the file.
--myboundary Content-Type: image/jpeg Content-Length: 9609
ˇÿˇ‡JFIFˇ˛ W»XW»Xˇ˛ ß2¨ÃéTY"ˇ€C
It tried to play with several parameters without success, it looks like the file is not recognized as a mpeg file.
Any thoughts ? Regards, Pierre