Search code examples
c++chttpstreamlibvlc

how to view stream sent by me libvlc C/C++


im on Ubuntu 14.04 and I'm trying to write a program that will stream my desktop, using the answer to this: libvlc stream part of screen as an example. However, I don't have another computer readily aviable to see that the stream is going along well, so how can I view that stream on my computer?

libvlc_vlm_add_broadcast(inst, "mybroad", "screen://",
"#transcode{vcodec=h264,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ts,dst=:8080/stream}",
5, params, 1, 0)

My program throws no errors, and writes this

[0x7f0118000e18] x264 encoder: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX

[0x7f0118000e18] x264 encoder: profile High, level 3.0

[0x7f0118000e18] x264 encoder: final ratefactor: 25.54

[0x7f0118000e18] x264 encoder: using SAR=1/1

[0x7f0118000e18] x264 encoder: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX

[0x7f0118000e18] x264 encoder: profile High, level 2.2

So to me, everything seems ok. However, I don't know how to view that stream from my computer- if I open vlc and try to open a network stream, using http:// @:7777 (space on purpose, website does not allow to post such links) I get the invalid host error in its log. This probably is a silly mistake or error on my part, but any help would be greatly appreciated!

if anyone needs it, this is my entire code (I'm using QT 4.8.6):

#include <QCoreApplication>
#include <iostream>
#include <vlc/vlc.h>
#include <X11/Xlib.h>
// #include <QDebug>

using namespace std;

bool ended;

void playerEnded(const libvlc_event_t* event, void *ptr);
libvlc_media_list_t * subitems;
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *media;
libvlc_media_t * stream;

int main(int argc, char *argv[])
{
    XInitThreads();
    QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
    ended = false;




    QCoreApplication a(argc, argv);
  // the array with parameters
            const char* params[] = {"screen-top=0",
                                    "screen-left=0",
                                    "screen-width=640",
                                    "screen-height=480",
                                    "screen-fps=10"};

        // Load the VLC engine */
           inst = libvlc_new (0, NULL);

           if(!inst)
               std::cout << "Can't load video player plugins" << std::endl;

           cout<< "add broacast: " <<
                  libvlc_vlm_add_broadcast(inst, "mybroad",
                       "screen://",
                       "#transcode{vcodec=h264,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ts,dst=:8080/stream}",
                       5, params, // <= 5 == sizeof(params) == count of parameters
                       1, 0)<< '\n';
               cout<< "poczatek broacastu: " <<libvlc_vlm_play_media(inst, "mybroad")<< '\n';
               media = libvlc_media_new_location(inst,http://@:8080/stream");
           // Create a media player playing environment
               mp = libvlc_media_player_new (inst);
               libvlc_media_player_play (mp);
 cout<<"szatan!!!"<<endl;
        int e;
        cin>>e;
        /* Stop playing */
           libvlc_media_player_stop (mp);
        /* Free the media_player */
           libvlc_media_player_release (mp);
           libvlc_release (inst);
       return a.exec();
}

Solution

  • so, i have found the answer- stack overflow wont let me post an answer because I'm new here, so its in the comments! I should have used my IP address when creating media: media = libvlc_media_new_location(inst, "http: //192.168.1.56:8080");(space on purpose so that forum does not hide link) works great! –