简体   繁体   English

使用 libvlc 在 RTSP Streaming 中仅显示第一帧

[英]Only first frame showed in RTSP Streaming with libvlc

I want to get video of an IP camera and stream it to another IP by libVLC.我想通过 libVLC 获取 IP 摄像机的视频并将其流式传输到另一个 IP。 I write these codes based on examples of libvlc docs.我根据 libvlc 文档示例编写了这些代码。 The video streamed successfully and video showed without any problem in destination.But in my display, only first frame was shown.视频流成功,视频在目的地显示没有任何问题。但在我的显示器中,只显示了第一帧。 After some search I guessed this problem will be solve by adding RTP over TCP option.经过一番搜索,我猜想通过添加RTP over TCP选项可以解决这个问题。 But after this change my problem didn't solve yet.但是在这个改变之后,我的问题还没有解决。

I use Microsoft visual C++ and my codes are:我使用 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;
 }

here is how i acces a RTSP stream with QT and LIBVLC, this is working well !这是我如何使用 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);

where "ui->frame" is the destination object, in my app it's a simple QFrame (but can be everything)其中“ui->frame”是目标对象,在我的应用程序中它是一个简单的 QFrame(但可以是一切)

For compile it you need #include and in the projects settings LIBS += -lvlc要编译它,您需要 #include 并在项目设置中 LIBS += -lvlc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM