美文网首页
libvlc将rtsp流转为opencv的Mat结构

libvlc将rtsp流转为opencv的Mat结构

作者: zjh3029 | 来源:发表于2017-09-04 11:55 被阅读0次

    1.rtsp流的处理

    #include<opencv2\opencv.hpp>    
    #include<vlc\vlc.h>
    
    using namespace std;
    using namespace cv;
    
    int width = 640;
    int height = 480;
    static char* videobuf;
    
    void *lock(void *data, void**p_pixels)
    {
        *p_pixels = videobuf;
        return NULL;
    }
    
    void display(void*data,void *id)
    {
        IplImage *img = cvCreateImage(CvSize(width, height), IPL_DEPTH_8U, 4);
        img->imageData = videobuf;
        //imshow("test", cvarrToMat(img));
        cvShowImage("test", img);
        waitKey(10);
        cvReleaseImage(&img);
    }
    
    void unlock(void *data, void *id, void *const *p_pixels)
    {
        (void)data;
        assert(id==NULL);
    }
    int main() {
        libvlc_instance_t *instance;
        libvlc_media_t  *media;
        libvlc_media_player_t *media_player;
    
        videobuf = (char*)malloc((width*height) << 2);
    
        memset(videobuf,0,(width*height)<<2);
        
        instance = libvlc_new(0, NULL);
    
        media = libvlc_media_new_location(instance, "rtsp://192.168.68.1:8554/1");
        media_player = libvlc_media_player_new_from_media(media);
        libvlc_media_release(media);
    
        libvlc_video_set_callbacks(media_player, lock, unlock, display, NULL);
        libvlc_video_set_format(media_player, "RV32", width, height, width << 2);
        libvlc_media_player_play(media_player);
    
        while(1){}
        return 0;
    }
    

    2.一个简单的播放器处理流程:

    #include<Windows.h>//windows的api
    #include<vlc\vlc.h>
    #include<iostream>
    using namespace std;
    
    int main()
    {
        libvlc_instance_t *instance_vlc;
        libvlc_media_player_t *mediaplayer_vlc;
        libvlc_media_t *media_vlc;
    
        libvlc_time_t time_play;
        int width, height, waittime = 5000;
        
        instance_vlc=libvlc_new(0, NULL);
        media_vlc = libvlc_media_new_path(instance_vlc, "test.mp4");
        mediaplayer_vlc = libvlc_media_player_new_from_media(media_vlc);
    
        libvlc_media_release(media_vlc);
        libvlc_media_player_play(mediaplayer_vlc);
    
        Sleep(waittime);
    
        time_play = libvlc_media_player_get_length(mediaplayer_vlc);
        cout << "用时:"<<time_play << endl;
    
        width = libvlc_video_get_width(mediaplayer_vlc);
        height = libvlc_video_get_height(mediaplayer_vlc);
        Sleep(time_play - waittime);
    
    
        libvlc_media_player_stop(mediaplayer_vlc);
        libvlc_media_player_release(mediaplayer_vlc);
        libvlc_release(instance_vlc);
        return 0;
    
    }
    

    相关文章

      网友评论

          本文标题:libvlc将rtsp流转为opencv的Mat结构

          本文链接:https://www.haomeiwen.com/subject/kdxejxtx.html