libvlc流屏幕的一部分

时间:2013-04-24 07:51:06

标签: c++ streaming vlc libvlc

我想使用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);

但这种修改没有改变任何内容。

老实说,我想从一台显示器流式传输(我有两台显示器),但我可以计算显示器的界限。

1 个答案:

答案 0 :(得分:6)

我找到了解决方案。

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