在 Release 模式下崩溃,在 Debug 模式下遇到错误

Crashing in Release Mode and error encounter in Debug Mode

这是我关于堆栈溢出的第一个问题,所以请回答我。

我正在使用 window 7 的 libvlc 库 2.1.5win64 和 Qt 4.8.5、C++ 和 Cmake 2.8 构建一个项目,以 rtsp 协议从 VLC 服务器捕获流视频。我面临两个非常严重的问题。

1: My program is bulding .exe file in Release mode but it crash when we open(double click) this .exe file, while it is working correctly in debug mode.

2: My program is not working in debug mode also, when I open .exe file it shown a widget but video is not streaming

遇到错误

[0000000001c96b20] main input error: open of 'rtsp"//192.168.1.101:8554/' failed 

[0000000001bcce90] main input error: your input can't be opened
[0000000001bcce90] main input error: VLC is unable to open the MRL 'rtsp://192.168.1.101:8554/'. check the log for details.

请有人回答我的问题......

我也在用 cmakelist 提供我的源代码......

如果可能请编辑我的代码,因为我是 Qt、Cmake、LibVlc 的新手

CmakeList.txt


cmake_minimum_required(VERSION 2.8)
PROJECT(VlcInterfaceWindow_FULL)
FIND_PACKAGE( Qt4 4.8.5 COMPONENTS QtMain QtCore QtGui REQUIRED )
#SET(VlcInterfaceWindow_SOURCES  main.cpp  vlc_on_qt.cpp)
SET(VlcInterfaceWindow_HEAERS vlc_on_qt.h)

INCLUDE(${QT_USE_FILE})
include_directories( "C:/vlc-2.1.5/sdk/include")
QT4_WRAP_CPP(VlcInterfaceWindow_HEAERS_MOC ${VlcInterfaceWindow_HEAERS})


add_library(lib_vlc STATIC IMPORTED)
set_property(TARGET lib_vlc PROPERTY IMPORTED_LOCATION_RELEASE C:/vlc-2.1.5/sdk/lib/libvlc.lib)
set_property(TARGET lib_vlc PROPERTY IMPORTED_LOCATION_DEBUG C:/vlc-2.1.5/sdk/lib/libvlc.lib)

add_library(lib_vlc_core STATIC IMPORTED)
set_property(TARGET lib_vlc_core PROPERTY IMPORTED_LOCATION_RELEASE C:/vlc-    
2.1.5/sdk/lib/libvlccore.lib)
set_property(TARGET lib_vlc_core PROPERTY IMPORTED_DEBUG C:/vlc-2.1.5/sdk/lib/libvlccore.lib)
set(VlcTest_SRCS  main.cpp vlc_on_qt.cpp )

ADD_EXECUTABLE(VlcInterfaceWindow_FULL ${VlcTest_SRCS} ${VlcInterfaceWindow_HEAERS_MOC})
TARGET_LINK_LIBRARIES(VlcInterfaceWindow_FULL ${QT_LIBRARIES} lib_vlc lib_vlc_core)



main.cpp

#include "vlc_on_qt.h"
#include <QtGui/QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Player p;
p.resize(640,480);
//p.playFile("rtsp://38.117.88.90/TenTV/video");
p.playFile("rtsp://192.168.1.101:8554/");
p.show();
return a.exec();
}





vlc_on_qt.h

#ifndef VLC_ON_QT_H
#define VLC_ON_QT_H

#include <vlc/vlc.h>
#include <vlc/libvlc.h>
#include <QWidget>

class 
QVBoxLayout;
class
QTimer;
class 
QFrame;
class
QSlider;

#define POSITION_RESOLUTION 10000

class Player : public QWidget
{
Q_OBJECT

QSlider *_positionSlider;
   
QFrame *_videoWidget;
QTimer *poller;
bool _isPlaying;
libvlc_instance_t *_vlcinstance;
libvlc_media_player_t *_mp;
libvlc_media_t *_m;

public:
Player();

~玩家();

public slots:
void playFile(QString file);
void updateInterface();
void changePosition(int newPosition);
};
#endif



vlc_on_qt.cpp

#include "vlc_on_qt.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QSlider>
#include <QTimer>
#include <QFrame>
#include <iostream>

using namespace std;

Player::Player()
: QWidget()
{

 _videoWidget=new QFrame(this);

_positionSlider=new QSlider(Qt::Horizontal,this); 
_positionSlider->setMaximum(POSITION_RESOLUTION);

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(_videoWidget);
layout->addWidget(_positionSlider);
setLayout(layout);

_isPlaying=false;
poller=new QTimer(this);

connect(poller, SIGNAL(timeout()),this, SLOT(updateInterface()));
connect(_positionSlider, SIGNAL(sliderMoved(int)), this, SLOT(changePosition(int)));

poller->start(100); 
}

Player::~Player() 
{
libvlc_media_player_stop (_mp);
   
libvlc_media_player_release (_mp);

libvlc_release (_vlcinstance);

}

void Player::playFile(QString file)
{
 _vlcinstance=libvlc_new(0, NULL);          

 //Create a new LibVLC media descriptor
_m = libvlc_media_new_location(_vlcinstance, file.toAscii());

_mp=libvlc_media_player_new_from_media (_m);


// Get our media instance to use our window 
 libvlc_media_player_set_hwnd(_mp, _videoWidget->winId());

// Play 
libvlc_media_player_play (_mp);
  
_isPlaying=true;   

}


void Player::changePosition(int newPosition)
{
libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp);
if (curMedia == NULL)
    return;

float pos=(float)(newPosition)/(float)POSITION_RESOLUTION;
libvlc_media_player_set_position (_mp, pos);

}

void Player::updateInterface()
{
if(!_isPlaying)
    return;

libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp);
if (curMedia == NULL)
    return;

float pos=libvlc_media_player_get_position (_mp);
int siderPos=(int)(pos*(float)(POSITION_RESOLUTION));
_positionSlider->setValue(siderPos);

}
来自 vlc 发行版的

libvlc.lib 总是无法用于发布 Visual Studio 版本。要解决此问题,您有 3 个选择:

要找出视频解码有什么问题,您可以将“-vvv”(激活完整调试日志的选项)传递给 libvlc_new