Giter VIP home page Giter VIP logo

mpv-rs's Introduction

DEPRECATED USE LIBMPV-RS INSTEAD

https://crates.io/crates/libmpv

mpv-rs

safe libmpv bindings for Rust.

mpv is a media player based on MPlayer and mplayer2. It supports a wide variety of video file formats, audio and video codecs, and subtitle types.

The crate is a safe libmpv API binding in Rust. For more info about mpv, see here.

Documentation

Installing

[dependencies]
mpv = "0.2"

the mpv package is needed for this to run.

Linux

On linux, you can ask your package manager to install it for you.

Arch

# pacman -S mpv

Debian-based systems

# apt-get install libmpv1

Windows

libmpv can be found here for windows. You need to copy the library into your rust binaries folder for it to be linked properly.

Running

2 examples are available from the get go in this crate.

simple.rs will alow you to display a standard mpv player in a new window. Controls will be available.

$ cargo run --example simple

sdl2.rs will embed mpv in an sdl2 window. Controls will not be available and cannot be. If you want an interface on top of this player, you must draw your own with OpenGL calls or SDL2 calls.

$ cargo run --example sdl2

Contributing

Any contribution is welcome, as well as any code review !

What is left to implement

If you want to contribute, there are quite a few less-used functions and structs of mpv that can be added to mpv-rs

Events :

Formats :

MpvHandler impls :

  • (easy) load_config_file
  • (easy) detach_destroy (if only I knew what this was for ?)
  • (easy) client_name
  • (advanced) set_wakeup_callback
  • (advanced) get_wakeup_pipe
  • (easy) request_log_messages
  • (easy) request_event

MpvHandlerWithGl impls :

  • (easy) raw_opengl_ctx() : return the raw opengl context
  • (easy, but hard testing) report_flip
  • (very hard, probably requires a third-party library such as futures-rs) set_update_callback (partially implemented via update_available)

Refactor

(easy, long) This crate was done on my early rust days, and as such the current code is very poorly organized. Without changing how this crate works, refactoring everything in coherent files would be a huge plus.

Submitting an issue

Any question concerning the mpv-rs API is welcome in the issues.

If your mpv crashes, please make sure it's coming from this Rust binding and not from libmpv itself.

License

mpv is globally licensed under GPLv2+ (see here), but this crate is licensed under the MIT/Apache-2.0 (at your option).

mpv-rs's People

Contributors

cobrand avatar zekesonxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mpv-rs's Issues

Code Assumes 64bit

In this line, an uint64_t is defined as an unsigned long. This is not the case on Linux in 32bit.

Symptom:

Thread 1 hit Breakpoint 2, mpv_wait_event (ctx=0x73c822a0, timeout=1000) at ../player/client.c:849
849         return event;
1: *event = {event_id = MPV_EVENT_END_FILE, error = 0, reply_userdata = 0, data = 0x7320c048}
(gdb) n
850     }
(gdb)
mpv::mpv_handler::MpvHandler::wait_event::h37d3a3d836c63369 (self=0x7efff0c4, timeout=1000)
    at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/mpv-0.2.3/src/mpv_handler.rs:350
350                 if ptr.is_null() {
(gdb) print *ptr
$1 = mpv::mpv_gen::Struct_mpv_event {event_id: mpv::mpv_gen::MPV_EVENT_END_FILE, error: 0, reply_userdata: 0, data: 0x0}
(gdb) x/5x ptr
0x73c48ef8:     0x00000007      0x00000000      0x00000000      0x00000000
0x73c48f08:     0x7320c048

Note how in C data is 0x7320c048, but Rust thinks that data is NULL. When you look at the memory dump, the correct pointer is still there, but Rust is out of alignment with the structure:

typedef struct mpv_event {
    mpv_event_id event_id;
    int error;
    uint64_t reply_userdata;
    void *data;
} mpv_event;

This is the structure in mpv_gen.rs:

#[repr(C)]
#[derive(Copy)]
pub struct Struct_mpv_event {
    pub event_id: mpv_event_id,
    pub error: ::std::os::raw::c_int,
    pub reply_userdata: uint64_t,
    pub data: *mut ::std::os::raw::c_void,
}

which looks ok, but since uint64_t is actually only four bytes long, it's not.

This took ages to find.

Bottom pixel row is black in SDL2 example

The bottom row of pixels is black in the SDL2 example. Maybe the whole video is shifted up by 1 px for some reason?

In the simple example it looks correct. [Link to test video]

Btw, the simple example uses 14% CPU while SDL2 example only uses 0.87% CPU, why?

Is it also possible to render video with glutin/glium with as low CPU usage as SDL2?

mpv.get_property_async::<&str>("non-existent") segfaults

Specifically, the segfault happens when the reply is received. Somewhere, (I guess as result) a null pointer is returned from libmpv, which mpv-rs tries to turn into a CStr. This happens here.

A simple change like this prevents the segfault:

Format::Str(if char_ptr != 0 as *mut _ { 
    unsafe {                             
        CStr::from_ptr(char_ptr)         
            .to_str()                    
            .unwrap()                    
    }                                    
}                                        
else {                                   
    ""                                   
})                                       

But I can't say if this is a proper solution. Also, the same probably happens for OsdStr but I don't even know what OsdStr is used for.

The issue can easily be reproduced by adding the following line to examples/simple.rs:

mpv.get_property_async::<&str>("nonexistent", 1).unwrap();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.