无线IP摄像机向安卓手机进行实时视频流传输

11

我需要使用RTSP协议从一台无线IP摄像头向安卓手机进行实时视频流传输。 摄像头连接到无线路由器,手机也连接着同一个wifi网络。现在我需要实现从摄像头获取实时视频流的功能。

为此,我应该怎么做?这对我来说是一个新概念。如何通过编程连接安卓手机和摄像头,并获取实时流。任何帮助都将不胜感激。


1
请按照此链接中的说明进行操作:http://www.androidhive.info/2014/06/android-streaming-live-camera-video-to-web-page/。 - Pravin Raj
1个回答

3
你可以从你的Ip Cam访问图像实时视频流到你的PC,我的是 String URL = "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));
}

您可以在这里这里了解有关MJpegInput流的更多信息。

希望对您有所帮助,编码愉快。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接