只有第一帧显示在带有libvlc的RTSP Streaming中

时间:2015-08-02 09:38:41

标签: c++ c vlc libvlc

我想获取IP摄像机的视频,并通过libVLC将其传输到另一个IP。我根据libvlc文档的例子编写这些代码。视频流成功,视频显示目的地没有任何问题。但在我的显示中,只显示了第一帧。经过一些搜索,我猜测这个问题将通过添加RTP over TCP选项来解决。但是在这次改变之后我的问题还没有解决。

我使用的是Microsoft Visual C ++,我的代码是:

#include <stdio.h>
 #include <stdlib.h>
 #include <vlc/vlc.h>
#include <Windows.h>
 int main(int argc, char* argv[])
 {
     libvlc_instance_t * inst;
     libvlc_media_player_t *mp;
     libvlc_media_t *m;


     char *myarg0 = "--sout=#transcode{vcodec=h264,scale=Auto,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=display,dst=rtp{sdp=rtsp://destinationIP:Port}}";
     char *myarg1="--rtsp-tcp"; 
     char *myargs[2] = {myarg1, myarg0};
     /* Load the VLC engine */
     inst = libvlc_new (2, myargs);

     /* Create a new item */
     char *input="http://user:pass@CameraIP//axis-cgi//mjpg//video.cgi";
     m = libvlc_media_new_location (inst,input ); 

     /* Create a media player playing environement */
     mp = libvlc_media_player_new_from_media (m);

     /* No need to keep the media now */
     libvlc_media_release (m);


     /* play the media_player */
     libvlc_media_player_play (mp);

     Sleep (10000000); /* Let it play a bit */

     /* Stop playing */
     libvlc_media_player_stop (mp);

     /* Free the media_player */
     libvlc_media_player_release (mp);

     libvlc_release (inst);

     return 0;
 }

1 个答案:

答案 0 :(得分:1)

这是我如何使用QT和LIBVLC访问RTSP流,这很好用!

libvlc_instance_t *_vlcinstance;
libvlc_media_player_t *_mp;
libvlc_media_t *_m;

const char * const vlc_args[] = {
       //   "--verbose=2", //be much more verbose then normal for debugging purpose
    "--network-caching=100",
};

//create a new libvlc instance
_vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);  //tricky calculation of the char space used
// Create a media player playing environement
_mp = libvlc_media_player_new (_vlcinstance);


/* Create a new LibVLC media descriptor */
_m = libvlc_media_new_location(_vlcinstance, "rtsp://admin:admin@192.168.1.83:554/live0.264");
libvlc_media_player_set_media (_mp, _m);
/* Get our media instance to use our window */
int windid = ui->frame->winId();
libvlc_media_player_set_xwindow (_mp, windid );
/* Play */
libvlc_media_player_play (_mp);

其中&#34; ui-> frame&#34;是目标对象,在我的应用程序中它是一个简单的QFrame(但可以是一切)

为了编译它,你需要#include并在项目设置中LIBS + = -lvlc