2015-10-26 25 views
9

我在cpp中有一个opencv应用程序。OpenCV IP摄像机应用程序崩溃[h264 @ 0xxxxx]在访问单元中缺少图片

它捕获视频流并将其保存到视频文件中,并使用opencv的简单结构。

它适用于我的摄像头。

但是,它可能会在大约十秒后崩溃,而我运行它来捕获来自IP Camara的流。

我的编译命令是:

g++ -O3 IP_Camera_linux.cpp -o IP_Camera `pkg-config --cflags --libs opencv` 

从IP cam。我流像这样访问:

const string Stream = "rtsp://admin:[email protected]/"; 

它完美运行,显示视频并保存它,直到显示的视频冻结和应用程序崩溃。而在终端上的错误信息是:

[h264 @ 0x15e6f60] error while decoding MB 59 31, bytestream (-20) 
[h264 @ 0x15e8200] error while decoding MB 61 27, bytestream (-3) 
[h264 @ 0x109c880] missing picture in access unit 
[h264 @ 0x109c000] no frame! 

据我了解,拳头两条线在上面的错误消息可能有一些做的,但实际上并没有崩溃的应用程序。最后两行可能是原因或原因?

任何帮助?

+0

看看下面的[RTSP UPD vs TCP](http://answers.opencv.org/question/34012/ip-camera-h264-error-while-decoding/) – Pim

+0

那么可能会解决实际上是什么不是主要问题,好!顺便说一句,没有接受的答案,似乎还没有辩论。 – tod

+0

我们可以看到你的cpp文件吗?或者关于如何访问摄像机流的一些代码片段? – Manny

回答

3

在大量的命中和试用后得到了解决方案。只是改变了流地址,它有效。

来源:

const string Stream = "rtsp://admin:[email protected]/"; 

要:

const string Stream = "rtsp://admin:[email protected]/ch1-s1?tcp"; 

不知道,它做什么样的变化?

但它工作完美!

即使是形式的普遍警告:

[h264 @ 0x15e6f60] error while decoding MB 59 31, bytestream (-20) 
[h264 @ 0x15e8200] error while decoding MB 61 27, bytestream (-3) 

都没有了。

无论如何,如果有人能够解释它背后的逻辑原因,将不胜感激。

CREDIT

-1

作为引用到the original answer,加入?TCP到最后迫使RTSP连接使用TCP协议UDP协议,如果你不主动检查任何这是有用的运行,而不是连接问题,因此你不能承受任何数据包丢失。

对于稳健的运行,你可以在你循环检查NULL形象,如果你得到一个NULL图像,可以重置相机连接:

IplImage *img = cvQueryFrame(camera); 
     if (img == NULL) { 
      printf("img == null "); 
      fflush(stdout); 
      camera = cvCreateFileCapture("rtsp://admin:[email protected]/ch1-s1?tcp"); 
     } 
+0

重新启动连接会使流很糟糕。 – tod

0

距离的ffmpeg错误。可能你的ffmpeg是旧版本,你可能想更新它。它完美地解决了这个问题对我的情况下,通过重新安装最新的OpenCV和ffmpeg的如下:

  • 安装最新的ffmpeg

    git clone git://source.ffmpeg.org/ffmpeg.git 
    cd ffmpeg 
    ./configure --enable-shared --disable-static 
    make 
    sudo make install 
    
  • 安装最新的OpenCV

    git clone [email protected]:opencv/opencv.git 
    cd opencv 
    mkdir build 
    cd build 
    cmake ../ -DCMAKE_BUILD_TYPE=Release 
    make 
    sudo make install