libvlc stream part of screen
Asked Answered
G

1

6

I want to stream a part of screen using vlc library. I wrote a small example:

#include <iostream>
#include <cstdlib>

#include <vlc/vlc.h>


int main(int argc, char**argv)
{
    libvlc_instance_t * inst = libvlc_new(argc, argv);
    libvlc_vlm_add_broadcast(inst, "mybroad",
            "screen://", "#transcode{vcodec=h264, venc=x264,vb=0,scale=0, acodec=mpga,ab=128,channels=2, samplerate=44100}:http{mux=ffmpeg{mux=flv}, dst=:7777/}",
            0, NULL, 1, 0);
    libvlc_vlm_play_media(inst, "mybroad");
    std::cout << "ready" << std::endl;
    // next two lines - it just for waitint
    int i;
    std::cin >> i;
    // omit the code that frees libvlc
    return 0;
}

This code stream all my screen. I can stream a part of screen, if I do it in a console:

vlc -I "dummy" screen:// --screen-left=0 --screen-top=0 \
   --screen-width=640 --screen-height=480 \
   --screen-fps=1 \
   --sout '#transcode{vcodec=h264,vb=800,scale=1,\
     acodec=mpga,ab=128,channels=2,\
     samplerate=44100}:http{mux=ts,dst=:7777/}'

I tryed to do it in code by modifing one line:

libvlc_vlm_add_broadcast(inst, "mybroad",
                "screen:// :screen-fps=24 :screen-top=0 :screen-left=0 :screen-width=320 :screen-height=240", 
               "#transcode{vcodec=h264,venc=x264, vb=0,scale=0,acodec=mpga,ab=128,channels=2, samplerate=44100}:http{mux=ffmpeg{mux=flv},dst=:7777/}",
                0, NULL, 1, 0);

But this modification has changed nothing.

Honestly, I want to stream from one monitor (I have two monitors), but I can calculate the bounds of monitors.

Galina answered 24/4, 2013 at 7:51 Comment(0)
G
8

I found solution.

#include <iostream>
#include <cstdlib>

#include <vlc/vlc.h>


int main(int argc, char**argv)
{
    // the array with parameters
    const char* params[] = {"screen-top=0", 
                            "screen-left=0",
                            "screen-width=640", 
                            "screen-height=480", 
                            "screen-fps=10"}; 
    libvlc_instance_t * inst = libvlc_new(argc, argv);
    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=:7777/}",
            5, params, // <= 5 == sizeof(params) == count of parameters
            1, 0);
    libvlc_vlm_play_media(inst, "mybroad");
    std::cout << "ready" << std::endl;
    int i;
    std::cin >> i;
    return 0;
}
Galina answered 25/4, 2013 at 7:44 Comment(2)
Shouldn't params (in const char* params[] ...) be param?Tibia
Why do i get "main vlm daemon error: invalid media description" when i run this program?Salt

© 2022 - 2024 — McMap. All rights reserved.