【发布时间】:2016-09-01 16:54:09
【问题描述】:
我设法连接到我的摄像头,从中获取流量并将其转储到 mpeg 文件中。这是更清晰的代码。
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
测试运行良好,按预期生成了一个文件,但是当我尝试读取它(使用几个播放器)时,我可以偷偷地看到来自摄像头的一张图像,然后它就停止了。
大小(取决于参数)可能很重要,在编辑文件时,我可以清楚地猜测这些是连续的 Jpeg 文件。
这是文件的开头。
--myboundary Content-Type: image/jpeg Content-Length: 9609
ˇÿˇ‡JFIFˇ˛ W»XW»Xˇ˛ ß2¨ÃéTY"ˇ€C
它尝试使用几个参数都没有成功,看起来该文件未被识别为 mpeg 文件。
有什么想法吗? 问候, 皮埃尔
【问题讨论】:
-
当用
stream_to_file写入文件时,什么保证了块(字节)的原始顺序? -
感谢您的帮助。我什么都不怕。我唯一可以用 iHex 检查的是里面的所有 jpeg 文件都被 --myboundary 清楚地分隔我确实在 --myboundary 分隔符之间复制了一个随机块,把它放在一个文件中,我有一个正确的图像。
-
MediaInfo 似乎无法从中提取任何信息。我忘了写标题还是什么?