ParadoxSpiral / libmpv-rs

A libmpv abstraction written in rust that's easy to use and provides the ability to read next to all video and audio codecs.
GNU Lesser General Public License v2.1
100 stars 36 forks source link

Support using from `mpv_open_cplugin`. #25

Closed eNV25 closed 1 year ago

eNV25 commented 2 years ago

It's possible to use Rust to create an MPV plugin.

[package]
name = "test-mpv-cplugin"
version = "0.1.0"
edition = "2021"

[lib]
name = "test_mpv_cplugin"
crate-type = ["cdylib"]

[dependencies]
libmpv-sys = "3.1.0"
use libmpv_sys::*;
use std::ffi::*;

#[no_mangle]
extern "C" fn mpv_open_cplugin(handle: *mut mpv_handle) -> usize {
    let client_name = unsafe { CStr::from_ptr(mpv_client_name(handle)) }
        .to_str()
        .unwrap_or_default();
    println!("Hello from {}", client_name);
    0
}
$ cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
$ mpv --no-config --script=target/debug/libtest_mpv_cplugin.so test.png
Hello from libtest_mpv_cplugin
 (+) Video --vid=1 (png 1118x924 1.000fps)
VO: [gpu] 1118x924 rgba
V: 00:00:00 / 00:00:00 (0%)

Exiting... (End of file)

It would be useful to use the main crate instead of the -sys crate. Should be as simple as adding a constructor from_ptr for struct Mpv.

ryze312 commented 1 year ago

Bump @ParadoxSpiral The only alternative at the moment is this repo