VLC RTSP推流
阿新 • • 發佈:2019-01-30
目的:把桌面或視訊推送出去(伺服器),用VLC可接收播發(客戶端);
-
搭建VLC環境
-
用程式碼推流;
vlc是通過字串的方式設定引數,這些引數可以在VLC客戶端推流向導過程中檢視;
int main(int argc, char **argv) { //轉碼引數:#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none} //網路引數:rtp{sdp=rtsp://:8554/} //此處隱藏了本機的IP地址,只設置了埠號; const char *sout = "#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:rtp{sdp=rtsp://:8554/}"; const char *MRL; //推桌面; //MRL= "screen://"; //推視訊; MRL= "test.mkv"; //選項引數,可設定推流的大小,幀率,快取時間... const char* options[]= { "screen-top=0", "screen-left=0", "screen-width=1000", "screen_height=800", "screen-fps=30" }; const char *media_name = "test"; //開始推流; libvlc_instance_t *vlc= libvlc_new(0, NULL); libvlc_vlm_add_broadcast(vlc, media_name, MRL, sout, 5, options, true, false); //5為optoins個數; libvlc_vlm_play_media(vlc, media_name); //play 30s _sleep(30000); //結束推流; libvlc_vlm_stop_media(vlc, media_name); libvlc_vlm_release(vlc); return 0; }
-
用VLC客戶端推流;
-
VLC接收播放;
輸入推流端的IP地址及推流設定的埠號;
同步連線需要一定的時間,幾秒到幾十秒視網路及傳輸的畫面大小而定;