Use libvlc to stream mp3 to network

南楼画角 提交于 2020-01-13 19:24:09

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/4845588/use-libvlc-to-stream-mp3-to-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!