2013-04-24 114 views
4

我想使用vlc庫流化屏幕的一部分。我寫了一個小例子:屏幕的libvlc流部分

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

我tryed做的代碼通過對矯正一行:

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

但這種修改已經什麼也沒有改變。老實說,我想從一個顯示器(我有兩個顯示器)流,但我可以計算顯示器的界限。

回答

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; 
} 
+0

不應該'params'(在'const char * params [] ...')是'param'嗎? – 2013-09-07 01:09:18

+0

是的,這是事實。 – KoVadim 2013-09-08 12:43:29

+0

當我運行這個程序時,爲什麼會出現「main vlm daemon error:invalid media description」? – Vigo 2013-10-15 12:34:40