本文介绍了libvlc流部分屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用vlc库来播放屏幕的一部分。我写了一个小例子:

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.

推荐答案

我找到解决方案。

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

这篇关于libvlc流部分屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:14