首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从无线IP摄像头到Android手机的视频直播

从无线IP摄像头到Android手机的视频直播
EN

Stack Overflow用户
提问于 2014-07-23 17:04:56
回答 1查看 12.1K关注 0票数 10

在这里,我必须获得实时视频流从一个无线Ip摄像头到安卓手机使用protocol.Camera连接到无线路由器和手机也有相同的wifi network.Now,我需要实现从摄像头的实时视频流。

为了达到这个目的,我该怎么办?这是me.How的新概念,通过编程连接安卓手机和摄像头,并获得实时streaming.Any帮助将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-11 13:25:26

你可以从你的Ip Cam到你的PC上访问实时图像源,我的是

String URL = "http://192.168.1.8/image/jpeg.cgi";

或者类似的东西。你应该检查你的设备,如果它包括在内。然后,您可以下载该图像并将其放到图像视图中。不是实际的图像文件,而是它的图形细节。您可以在MJpegInputStream中搜索它,以下是它的示例代码

代码语言:javascript
复制
public class MjpegInputStream extends DataInputStream {
private final byte[] SOI_MARKER = { (byte) 0xFF, (byte) 0xD8 };
private final byte[] EOF_MARKER = { (byte) 0xFF, (byte) 0xD9 };
private final String CONTENT_LENGTH = "Content-Length";
private final static int HEADER_MAX_LENGTH = 100;
private final static int FRAME_MAX_LENGTH = 40000 + HEADER_MAX_LENGTH;
private int mContentLength = -1;

public static MjpegInputStream read(Context context,String url) {
    HttpResponse res;
    MyHttpClient httpclient = new MyHttpClient( context );     
    try {
        res = httpclient.execute(new HttpGet(URI.create(url)));
        return new MjpegInputStream(res.getEntity().getContent());              
    } catch (ClientProtocolException e) {
    } catch (IOException e) {}
    return null;
}

public MjpegInputStream(InputStream in) { super(new BufferedInputStream(in, FRAME_MAX_LENGTH)); }

private int getEndOfSeqeunce(DataInputStream in, byte[] sequence) throws IOException {
    int seqIndex = 0;
    byte c;
    for(int i=0; i < FRAME_MAX_LENGTH; i++) {
        c = (byte) in.readUnsignedByte();
        if(c == sequence[seqIndex]) {
            seqIndex++;
            if(seqIndex == sequence.length) return i + 1;
        } else seqIndex = 0;
    }
    return -1;
}

private int getStartOfSequence(DataInputStream in, byte[] sequence) throws IOException {
    int end = getEndOfSeqeunce(in, sequence);
    return (end < 0) ? (-1) : (end - sequence.length);
}

private int parseContentLength(byte[] headerBytes) throws IOException, NumberFormatException {
    ByteArrayInputStream headerIn = new ByteArrayInputStream(headerBytes);
    Properties props = new Properties();
    props.load(headerIn);
    return Integer.parseInt(props.getProperty(CONTENT_LENGTH));
}   

public Bitmap readMjpegFrame() throws IOException {
    mark(FRAME_MAX_LENGTH);
    int headerLen = getStartOfSequence(this, SOI_MARKER);
    reset();
    byte[] header = new byte[headerLen];
    readFully(header);
    try {
        mContentLength = parseContentLength(header);
    } catch (NumberFormatException nfe) { 
        mContentLength = getEndOfSeqeunce(this, EOF_MARKER); 
    }
    reset();
    byte[] frameData = new byte[mContentLength];
    skipBytes(headerLen);
    readFully(frameData);
    return BitmapFactory.decodeStream(new ByteArrayInputStream(frameData));
}

您可以查看有关MJpegInput流、herehere的更多信息

希望它是有帮助的,愉快的编码。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24906274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档