如何使用Elixir / HTTPoison或Hackney获得视频流? [英] How to get a video flow with Elixir/HTTPoison or Hackney?

查看:102
本文介绍了如何使用Elixir / HTTPoison或Hackney获得视频流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Elixir / HTTPoison从凸轮获取流并将其转储到文件中。
网址为 xxxx / axis-cgi / mjpg / video.cgi?duration = 1& resolution = 320x240

I'm trying to get a stream from a cam using Elixir / HTTPoison and dump it into a file. Url is x.x.x.x/axis-cgi/mjpg/video.cgi?duration=1&resolution=320x240

使用网址在DHC(Chrome插件)中,我可以具有以下内容:

Using the url in DHC (Chrome addon), i can have the following:


响应200 OK

Response 200 OK

HEADERS缓存控制:无缓存语法:no-cache过期:12月01日,星期四
1994 16:00:00 GMT连接:close内容类型:
multipart / x-mixed-更换; boundary = myboundary X时间偏移:
62044.312573 pretty完成请求标头接受: / 接受编码:gzip,deflate,sdch
接受语言:fr-FR,fr ; q = 0.8,en-US; q = 0.6,en; q = 0.4
内容类型:application / xml用户代理:Mozilla / 5.0(Windows NT
6.1; WOW64)AppleWebKit / 537.36 (KHTML,例如Gecko)Chrome / 52.0.2743.116 Safari / 537.36注意:XHR自动添加
标头,例如Accept,Accept-Language,Cookie,User-Agent等。

HEADERS Cache-Control: no-cache Pragma: no-cache Expires: Thu, 01 Dec 1994 16:00:00 GMT Connection: close Content-Type: multipart/x-mixed-replace; boundary=myboundary X-Time-Offset: 62044.312573 pretty COMPLETE REQUEST HEADERS Accept: / Accept-Encoding: gzip, deflate, sdch Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4 Content-Type: application/xml User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Note: XHR automatically adds headers like Accept, Accept-Language, Cookie, User-Agent, etc.

原始的格式显示了很多二进制jpeg图像,并用-myboundary 东西隔开了。

Raw formatting the body is showing me a lot of binary jpeg image separated by a --myboundary thing.


-myboundary

--myboundary

Content-Type:image / jpeg

Content-Type: image/jpeg

Content-Length:11848

Content-Length: 11848

?JFIF ? W u]7W u]7 ? 2 ̎TY C

����JFIF�� W�u]7W�u]7�� �2�̎TY"��C

现在,我要

  test "request headers from cam" do
    options = [hackney: [basic_auth: {"login","password"}]]
    {:ok, %HTTPoison.AsyncResponse{id: id}} = HTTPoison.get "http://x.x.x.x/axis-cgi/mjpg/video.cgi?duration=1&resolution=320x240",[], [stream_to: self, recv_timeout: :infinity, hackney: options]
    assert_receive %HTTPoison.AsyncStatus{id: ^id, code: 200}, 1_000
  end

我确实有以下答复,

  1) test request headers from cam (NewsequenceTest)
     test/newsequence_test.exs:9
     No message matching %HTTPoison.AsyncStatus{id: ^id, code: 200} after 1000ms.
     The following variables were pinned:
       id = #Reference<0.0.3.125>
     Process mailbox:
       %HTTPoison.AsyncStatus{code: 401, id: #Reference<0.0.3.125>}
       %HTTPoison.AsyncHeaders{headers: [{"Date", "Wed, 31 Aug 2016 06:47:00 GMT"}, {"Accept-Ranges", "bytes"}, {"Connection", "close"}, {"WWW-Authenticate", "Digest realm=\"AXIS_ACCC8E545922\", nonce=\"0000fa64Y50235919055a42f91d3dea744b10d2dab9653\", stale=FALSE, qop=\"auth\""}, {"WWW-Authenticate", "Basic realm=\"AXIS_ACCC8E545922\""}, {"Content-Length", "189"}, {"Content-Type", "text/html; charset=ISO-8859-1"}], id: #Reference<0.0.3.125>}
       %HTTPoison.AsyncChunk{chunk: "<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>\n<BODY><H1>401 Unauthorized</H1>\nYour client does not have permission to get URL /axis-cgi/mjpg/video.cgi from this server.\n</BODY></HTML>\n", id: #Reference<0.0.3.125>}
       %HTTPoison.AsyncEnd{id: #Reference<0.0.3.125>}
     stacktrace:
       test/newsequence_test.exs:12: (test)

我确实尝试了基本身份验证具有相同的结果。

I did try without basic auth with the same result.

我还不知道此身份验证错误是怎么回事。
当然,我误解了一些东西,有人可以启发我吗?

I don't understand yet what it's happening with this auth error. Sure i misunderstod something, can someone please enlighten me on this subject ?

亲切的问候,

Pierre

推荐答案

所以这里的问题是代码正在调用:

So the problem here was that the code was calling:

HTTPoison.get(..., [], [..., hackney: [hackney: [basic_auth: {"login","password"}]]])

代替:

HTTPoison.get(..., [], [..., hackney: [basic_auth: {"login","password"}]])

这会导致 hackney 忽略它们,因为它试图获取 opts [:hackney] [:basic_auth] 等c>。

which was causing hackney to ignore them as it was trying to fetch opts[:hackney][:basic_auth] etc which were all nil.

解决方法是替换:

options = [hackney: [basic_auth: {"login","password"}]]

with

options = [basic_auth: {"login","password"}]

这篇关于如何使用Elixir / HTTPoison或Hackney获得视频流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆