【问题标题】:libvlc stream part of screenlibvlc 流屏幕的一部分
【发布时间】:2013-04-24 07:51:06
【问题描述】:

我想使用 vlc 库流式传输屏幕的一部分。我写了一个小例子:

#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;
}

这个代码流所有我的屏幕。 如果我在控制台中进行,我可以流式传输屏幕的一部分:

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/}'

我尝试通过修改一行在代码中做到这一点:

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);

但是这次修改并没有改变什么。

老实说,我想从一台监视器进行流式传输(我有两台监视器),但我可以计算监视器的范围。

【问题讨论】:

    标签: c++ streaming vlc libvlc


    【解决方案1】:

    我找到了解决办法。

    #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;
    }
    

    【讨论】:

    • 不应该params(在const char* params[] ...)是param吗?
    • 为什么我在运行这个程序时得到“main vlm daemon error: invalid media description”?
    猜你喜欢
    • 2019-08-11
    • 2019-02-14
    • 2015-03-14
    • 2012-06-10
    • 2013-08-30
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多