从无线IP摄像头到Android mobile的实时视频流

从无线IP摄像头到Android mobile的实时视频流,android,rtsp,live-streaming,ip-camera,Android,Rtsp,Live Streaming,Ip Camera,在这里,我必须使用RTSP协议从无线Ip摄像机到android mobile获取实时视频流。摄像机连接到无线路由器,移动设备也有相同的wifi网络。现在我需要从摄像机实现实时视频流 为此,我该怎么办?。这对我来说是一个新概念。如何以编程方式连接android手机和摄像头并获得实时流媒体。如果您有任何帮助,我们将不胜感激。您可以从Ip摄像头访问图像实时源到您的PC,我的是 stringurl=”http://192.168.1.8/image/jpeg.cgi"; 或者其他什么。你应该检查你的设备

在这里,我必须使用RTSP协议从无线Ip摄像机到android mobile获取实时视频流。摄像机连接到无线路由器,移动设备也有相同的wifi网络。现在我需要从摄像机实现实时视频流


为此,我该怎么办?。这对我来说是一个新概念。如何以编程方式连接android手机和摄像头并获得实时流媒体。如果您有任何帮助,我们将不胜感激。

您可以从Ip摄像头访问图像实时源到您的PC,我的是

stringurl=”http://192.168.1.8/image/jpeg.cgi";

或者其他什么。你应该检查你的设备,如果这是包括在内的。然后,您可以下载图像并将其放在imageview上。不是实际的图像文件,只是它的图形细节。您可以为此搜索MJpegInputStream,下面是它的示例代码

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));
}
公共类MjpegInputStream扩展了DataInputStream{ 私有最终字节[]SOI_标记={(字节)0xFF,(字节)0xD8}; 私有最终字节[]EOF_标记={(字节)0xFF,(字节)0xD9}; 私有最终字符串内容\u LENGTH=“CONTENT LENGTH”; 专用最终静态int标头_MAX_LENGTH=100; 私有最终静态整数帧最大长度=40000+标题最大长度; private int mContentLength=-1; 公共静态输入流读取(上下文上下文、字符串url){ HttpResponse; MyHttpClient httpclient=新的MyHttpClient(上下文); 试一试{ res=httpclient.execute(新的HttpGet(URI.create(url)); 返回新的MjpegInputStream(res.getEntity().getContent()); }捕获(客户端协议例外e){ }捕获(IOE){} 返回null; } 公共MjpegInputStream(InputStream in){super(新的BufferedInputStream(in,FRAME_MAX_LENGTH));} private int getendofsequnce(DataInputStream in,字节[]序列)引发IOException{ int-seqIndex=0; 字节c; 对于(int i=0;i
您可以查看更多关于MJPEG输入流和


希望这是有用的、愉快的编码。

按照本手册中的说明完成。