libvlc-go

adrgMIT活跃维护

用 Go 语言手写的 libVLC 绑定,提供高层媒体播放器接口,方便在 Go 程序里播放音视频、抓屏和录屏。

Handcrafted Go bindings for libVLC and high-level media player interface

v3.1.6发布于 2024-09-13 19:51 UTC510star58fork同步于 2026-11-07 07:33 UTC

怎么上手

由 README 提炼,执行前请确认
go get github.com/adrg/libvlc-go/v3
硬件要求按 README 说明

README 未说明显存或 GPU 要求;需先安装 libVLC 开发文件(VLC SDK),Linux、Windows、macOS 安装方式见项目 wiki

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 Go 封装 libVLC 的绑定库,为应用快速加上音视频播放能力

用 Go 语言手写的 libVLC 绑定,提供高层媒体播放器接口,方便在 Go 程序里播放音视频、抓屏和录屏。

核心能力

  • 手写绑定 libVLC C API,提供高层播放器接口
  • 按 libVLC 主版本分 Go module,v3 对应 libVLC 3.X
  • 支持从本地路径或 URL 加载媒体播放
  • 通过 EventManager 注册播放结束等事件回调
  • 附带播放列表、均衡器、投屏 Chromecast 等示例

容易踩的坑

必须先安装 libVLC 开发文件,否则无法编译;v2 版本针对 libVLC < v2.2.0 需加 -tags legacy 构建;使用前需在代码中调用 vlc.Init 并在结束时 vlc.Release

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v3.1.6
  1. v3.1.6最新正式版2024-09-13 · 2024-09-13 19:51 UTC

    Changelog

    New bindings
    • Added Marquee type
    • Added Logo type
    • Added more player bindings:
      • Player.Contrast and Player.SetContrast
      • Player.Brightness and Player.SetBrightness
      • Player.Hue and Player.SetHue
      • Player.Saturation and Player.SetSaturation
      • Player.Gamma and Player.SetGamma
      • Player.VideoAdjustmentsEnabled and Player.EnableVideoAdjustments
      • Player.SetDeinterlaceMode
      • Player.Logo
      • Player.Marquee
    Bug fixes
    • Fixed event manager related C compiler warnings.
    Internal
    • Improved error reporting
    • Improved documentation
    • Improved GitHub Actions workflows
  2. v2.1.52024-09-13 · 2024-09-13 19:50 UTC
    查看更新说明

    Changelog

    New bindings
    • Added Marquee type
    • Added Logo type
    • Added more player bindings:
      • Player.Contrast and Player.SetContrast
      • Player.Brightness and Player.SetBrightness
      • Player.Hue and Player.SetHue
      • Player.Saturation and Player.SetSaturation
      • Player.Gamma and Player.SetGamma
      • Player.VideoAdjustmentsEnabled and Player.EnableVideoAdjustments
      • Player.SetDeinterlaceMode
      • Player.Logo
      • Player.Marquee
    Bug fixes
    • Fixed event manager related C compiler warnings.
    Internal
    • Improved error reporting
    • Improved documentation
    • Improved GitHub Actions workflows
  3. v3.1.52021-09-24 · 2021-09-24 12:02 UTC
    查看更新说明

    Changelog

    New bindings
    • Added Player.TakeSnapshot method
    • Added Player.TitleIndex and Player.TitleCount methods
    • Added Player.Titles and Player.SetTitle methods
    • Added Player.ChapterIndex, Player.ChapterCount and Player.SetChapter methods
    • Added Player.TitleChapters and Player.TitleChapterCount methods
    • Added Player.NextChapter and Player.PreviousChapter methods
    • Added Player.Navigate method
    • Added Player.SetTitleDisplayMode method
    Internal
    • Improved documentation
    • Improved Github actions
    • Added dependabot.yml
  4. v2.1.42021-09-24 · 2021-09-24 12:01 UTC
    查看更新说明

    Changelog

    New bindings
    • Added Player.TakeSnapshot method
    • Added Player.TitleIndex, Player.TitleCount and Player.SetTitle methods
    • Added Player.ChapterIndex and Player.ChapterCount methods
    • Added Player.TitleChapterCount and Player.SetChapter methods
    • Added Player.NextChapter and Player.PreviousChapter methods
    • Added Player.Navigate method
    • Added Player.SetTitleDisplayMode method
    Internal
    • Improved documentation
    • Improved Github actions
    • Added dependabot.yml
  5. v3.1.42021-03-31 · 2021-03-31 12:04 UTC
    查看更新说明

    Changelog

    New bindings
    • Added vlc.ListAudioOutputDevices method
    • Added Player.AudioOutputDevices method
    • Added Player.AudioOutputDevice and Player.SetAudioOutputDevice methods
    • Added Player.Role and Player.GetRole methods
    • Added Player.UpdateVideoViewpoint method
    • Added Player.VideoDimensions method
    • Added Player.CursorPosition method
    New examples
    Misc
    • Fixed relevant golangci-lint notices
    • Improved documentation

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    The package can be useful for adding multimedia capabilities to applications through the provided player interfaces. It relies on Go modules in order to mirror each supported major version of libVLC.

    Documentation for v3, which implements bindings for libVLC 3.X, can be found on pkg.go.dev.
    Documentation for v2, which implements bindings for libVLC 2.X, can be found on pkg.go.dev.

    Example applications:

    Prerequisites

    The libVLC development files are required. Instructions for installing the VLC SDK on multiple operating systems can be found on the wiki pages of this project.

    Installation

    In order to support multiple versions of libVLC, the package contains a Go module for each major version of the API. Choose an installation option depending on the version of libVLC you want to use.

    libVLC v3.X

    go get github.com/adrg/libvlc-go/v3
    

    libVLC v2.X

    go get github.com/adrg/libvlc-go/v2
    
    # Build for libVLC < v2.2.0
    go build -tags legacy
    

    All versions above also work for projects which are not using Go modules. However, consider switching to modules.

    Examples

    Examples for all supported API versions can be found at https://github.com/adrg/libvlc-go-examples.

    Usage

    package main
    
    import (
        "log"
    
        vlc "github.com/adrg/libvlc-go/v3"
    )
    
    func main() {
        // Initialize libVLC. Additional command line arguments can be passed in
        // to libVLC by specifying them in the Init function.
        if err := vlc.Init("--no-video", "--quiet"); err != nil {
            log.Fatal(err)
        }
        defer vlc.Release()
    
        // Create a new player.
        player, err := vlc.NewPlayer()
        if err != nil {
            log.Fatal(err)
        }
        defer func() {
            player.Stop()
            player.Release()
        }()
    
        // Add a media file from path or from URL.
        // Set player media from path:
        // media, err := player.LoadMediaFromPath("localpath/test.mp4")
        // Set player media from URL:
        media, err := player.LoadMediaFromURL("http://stream-uk1.radioparadise.com/mp3-32")
        if err != nil {
            log.Fatal(err)
        }
        defer media.Release()
    
        // Retrieve player event manager.
        manager, err := player.EventManager()
        if err != nil {
            log.Fatal(err)
        }
    
        // Register the media end reached event with the event manager.
        quit := make(chan struct{})
        eventCallback := func(event vlc.Event, userData interface{}) {
            close(quit)
        }
    
        eventID, err := manager.Attach(vlc.MediaPlayerEndReached, eventCallback, nil)
        if err != nil {
            log.Fatal(err)
        }
        defer manager.Detach(eventID)
    
        // Start playing the media.
        err = player.Play()
        if err != nil {
            log.Fatal(err)
        }
    
        <-quit
    }
    

    In action

    A list of projects using libvlc-go, in alphabetical order. If you want to showcase your project in this section, please create a pull request with it.

    • Alio - Command-line music player with Emacs style key bindings.
    • Tripbot - An ongoing 24/7 slow-TV art project.

    Stargazers over time

    Stargazers over time

    Contributing

    Contributions in the form of pull requests, issues or just general feedback, are always welcome.
    See CONTRIBUTING.MD.

    Contributors: adrg, fenimore, tarrsalah, danielpellon, patknight, sndnvaps, karlpip.

    Discord server

    libvlc-go is part of the libVLC Discord Community server. Feel free to come say hello!

    References

    For more information see the libVLC documentation.

    License

    Copyright (c) 2018 Adrian-George Bostan.

    This project is licensed under the MIT license. See LICENSE for more details.