使用 libvlc 将 mp3 流式传输到网络

发布于 2024-10-14 18:29:50 字数 115 浏览 2 评论 0原文

如何使用 libvlc 获取 MP3 文件(或实际上任何音频文件)并将其流式传输到网络,以便我可以连接 iTunes 或其他设备并像网络广播一样收听?

尽管任何语言都可以,但 C API 示例是首选。

How can I use libvlc to take an MP3 file (or really any audio file) and stream it to the network so I can connect with iTunes or something and listen like internet radio?

C API example is preferred, though any language is fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的奇迹 2024-10-21 18:29:50

libvlc_vlm_add_broadcast 接受一个 sout 字符串,所以这似乎可以解决问题:

#include <vlc/libvlc.h>
#include <unistd.h>
#include <stdbool.h>
#include <stddef.h>

int main(int argc, char **argv) {
    libvlc_instance_t *vlc;
    const char *url;
    const char *sout = "#transcode{acodec=mp3,ab=128,channels=2," \
                       "samplerate=44100}:http{dst=:8090/go.mp3}";
    const char *media_name = "Foo";

    if (argc != 2) {
        return 1;
    }
    url = argv[1];

    vlc = libvlc_new(0, NULL);
    libvlc_vlm_add_broadcast(vlc, media_name, url, sout, 0, NULL, true, false);
    libvlc_vlm_play_media(vlc, media_name);

    sleep(60); /* Let it play for a minute */

    libvlc_vlm_stop_media(vlc, media_name);
    libvlc_vlm_release(vlc);
    return 0;
}

libvlc_vlm_add_broadcast accepts an sout string, so this seems to do the trick:

#include <vlc/libvlc.h>
#include <unistd.h>
#include <stdbool.h>
#include <stddef.h>

int main(int argc, char **argv) {
    libvlc_instance_t *vlc;
    const char *url;
    const char *sout = "#transcode{acodec=mp3,ab=128,channels=2," \
                       "samplerate=44100}:http{dst=:8090/go.mp3}";
    const char *media_name = "Foo";

    if (argc != 2) {
        return 1;
    }
    url = argv[1];

    vlc = libvlc_new(0, NULL);
    libvlc_vlm_add_broadcast(vlc, media_name, url, sout, 0, NULL, true, false);
    libvlc_vlm_play_media(vlc, media_name);

    sleep(60); /* Let it play for a minute */

    libvlc_vlm_stop_media(vlc, media_name);
    libvlc_vlm_release(vlc);
    return 0;
}
疧_╮線 2024-10-21 18:29:50

文档对此足够清楚,您创建一个媒体(我记得是 vlc_media_new ),将 libvlc 的实例与其关联。然后,您从媒体(vlc_player_from_media 或类似的东西)创建一个播放器,然后开始播放。

我无法帮助您处理流媒体部分,因为我目前也在尝试解决它,但一旦我意识到如何完成工作,我就会帮助您:)

the documentation is clear enough for this, you create a media (vlc_media_new as I recall), associating an instance of the libvlc to it. Then you create a player from media (vlc_player_from_media or something like that) and then you start playing.

I can't help you for the streaming part because I'm currently trying to figure it out too, but I'll give you a hand as soon as I realize how to get the job done :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文