Android: streaming the camera as mjpeg

后端 未结 1 2016
囚心锁ツ
囚心锁ツ 2021-01-31 11:12

After several days of searching SO and google I\'m beginning to give up, so I thought I might as well post here.

I\'m creating an android app which should offer some kin

相关标签:
1条回答
  • 2021-01-31 11:27

    I got it. Seems, like my http-/content-headers were messed up. The proper headers should be:

    stream.write(("HTTP/1.0 200 OK\r\n" +
                              "Server: iRecon\r\n" +
                              "Connection: close\r\n" +
                              "Max-Age: 0\r\n" +
                              "Expires: 0\r\n" +
                              "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" +
                              "Pragma: no-cache\r\n" + 
                              "Content-Type: multipart/x-mixed-replace; " +
                              "boundary=" + boundary + "\r\n" +
                              "\r\n" +
                              "--" + boundary + "\r\n").getBytes());
    

    and

    stream.write(("Content-type: image/jpeg\r\n" +
                          "Content-Length: " + buffer.size() + "\r\n" +
                          "X-Timestamp:" + timestamp + "\r\n" +
                          "\r\n").getBytes());
    
    buffer.writeTo(stream);
    stream.write(("\r\n--" + boundary + "\r\n").getBytes());
    

    Of course, where to put the boundary is your own choice. Also there are probably some fields which are optional (e.g. most in Cache-Control), but this works and till now I was too lazy to strip them down. The important part is to remember the linebreaks (\r\n thingies)...

    0 讨论(0)
提交回复
热议问题