GithubHelp home page GithubHelp logo

mplayercontrol's Introduction

This is a net6.0 wrapper library for MPlayer, libmpv, mencoder, and as of 1.8+ ffmpeg, and ffprobe support has been added.

There is a sample net6.0 winforms project included and it can play both audio and video files.

The sample player currently supports play, pause, stop. seek and some other basic functionality. I only add new features as I require them or people send in patches.

See examples on the wiki pages https://github.com/majorsilence/MPlayerControl/wiki.

This is a personal project that as of 2022 is just for me to play around with things. If you are a dotnet developer looking for a way to interact with video and audio I suggest one of these projects instead.

MediaPlayer screeenshot

Downloads

Version 1.8+, net6.0

It has been tested on Windows 11 and Ubuntu Linux 22.04. Use libmpv, ffmpeg, and ffprobe.

Mainly namespace changes, removal of old code, and the addition of ffmpeg and ffprobe. For example

  • using LibMPlayerCommon;
    • changes to:
    • using Majorsilence.Media.Videos;

TODO:

Version 1.6 or less, net48

It has been tested on Windows XP/7/8 and Ubuntu Linux 10.10/11.04/12.04/13.04/14.04/16.04 and OpenSuse Linux 10.3.

Download using nuget https://www.nuget.org/packages?q=mplayercontrol.

  • PM> Install-Package MPlayerControl
  • PM> Install-Package MPlayerControl-Gtk
  • PM> Install-Package MPlayerControl-Winform

Development

Written in c#.

MPlayerControl is developed with the following work flow:

  • Nothing happens for months/years
  • Someone needs it to do something it doesn't already do
  • That person implements that something and submits a pull request
  • Repeat if it doesn't have a feature that you want it to have, add it
    • If it has a bug you need fixed, fix it

Linux and Mac

Use Rider.

Windows

Use Visual Studio 2019 or newer.

MPlayer

Majorsilence.Media.Videos requires "mplayer.exe" to exist in the same directory as the exe or the path must be specified. On linux mplayer may be in the path and work without specifying a path or having mplayer in the same directory. Download mplayer for windows from http://oss.netfarm.it/mplayer-win32.php. It may require some tweaks to getting working on some systems.

MPV Support

Initial mpv support has been added. Majorsilence.Media.Videos needs the libmpv path set and he following environment variable set.

The LC_NUMERIC environment variable must be set to "C" before running an that uses LibMPlayerCommon and libmpv.

LC_NUMERIC=C

Example

LC_NUMERIC=C mono MediaPlayer.exe

In mono develop right click the executable Project -> Options -> Run -> General add the environment varilabe here.

LC_NUMERIC=C

Web and Worker Projects

Majorsilence.Media.Web is a webapi project that can be used to upload videos to a server. Majorsilence.Media.WorkerService is a dotnet worker service that detects the uploaded videos and converts them to various formats.

The two project communicate through a simple txt file. Each upload video is assigned a guid. The text format for communication is as follows:

  • filename: {guid}.startrequest
  • filename: {guid}.txt
  • Line 1: {guid}
    • Added by the web upload project.
  • Line 2: {original video file extension}
    • Added by the web upload project.
  • Line 3: {MM/dd/yyyy HH:mm:ss}
    • optional timestamp of video converstation start date.
    • Added by the worker service.

Example upload file

f95a2020-c31c-4d8d-bb86-82b6edf2b529.txt

f95a2020-c31c-4d8d-bb86-82b6edf2b529
.mkv

Example after the worker service started processing the video.

f95a2020-c31c-4d8d-bb86-82b6edf2b529.txt

f95a2020-c31c-4d8d-bb86-82b6edf2b529
.mkv
10/29/2022 20:46:23

Converted folder

  • converted
    • YYYY
      • MM
        • dd
          • {id}
            • {id}.done
            • {id}.{filetypes....}
sequenceDiagram
    participant Client
    participant WebAPI
    participant FileSystem
    participant WorkerService

    Client->>WebAPI: GET request for token and ID
    WebAPI->>FileSystem: Write {id}.startrequest with token
    FileSystem-->>WebAPI: Confirm write
    WebAPI-->>Client: Return bearer token and ID

    Client->>WebAPI: POST video with token and ID
    WebAPI->>FileSystem: Write video to {id}.txt
    FileSystem-->>WebAPI: Confirm video saved
    WebAPI-->>Client: Confirm upload success

    WorkerService->>FileSystem: Detect {id}.txt
    WorkerService->>FileSystem: Process video
    FileSystem->>WorkerService: Delete original video file
    FileSystem->>WorkerService: Delete {id}.startrequest
    FileSystem->>WorkerService: Delete {id}.txt
    WorkerService->>FileSystem: Create {id}.done with video info
Loading

Web and Worker Service Docker Compose Example

version: "3.8"
services:
  workerservice:
    image: "majorsilence/media_workerservice:1.0.0-main"
    environment:
        ApiSettings__UploadFolder: "PLACEHOLDER/web/uploads"
        ApiSettings__ConvertedFolder: "PLACEHOLDER/web/output"
        ApiSettings__MEncoderPath: "/usr/bin/mencoder"
        ApiSettings__FfmpegPath: "/usr/bin/ffmpeg"
    command: sysctl -w fs.inotify.max_user_instances=1024
  workerservice:
    image: "majorsilence/media_web:1.0.0-main"
    ports:
        - "30001:80"
    environment:
        ApiSettings__UploadFolder: "PLACEHOLDER/web/uploads"
        ASPNETCORE_URLS: "https://+:443;http://+:80"
        #ASPNETCORE_Kestrel__Certificates__Default__Password: "PLACEHOLDER"
        #ASPNETCORE_Kestrel__Certificates__Default__Path: "/PLACEHOLDER/certs/PLACEHOLDER.pfx"
    command: sysctl -w fs.inotify.max_user_instances=1024

Ubuntu Setup

Core requirements

sudo apt-get install mplayer mencoder libmpv1 ffmpeg

Release build

cd Release-Builds
./build-release.ps1

Upload nuget packages to nuget.org.

bump version number.

./prepare-files-for-release.sh

Commit and push new version number for future developments

mplayercontrol's People

Contributors

dependabot[bot] avatar emanuellopes avatar hadeutscher avatar majorsilence avatar medo64 avatar sonicmouse avatar volikag 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  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  avatar  avatar  avatar  avatar

mplayercontrol's Issues

Audio

Listing audio tracks and audio track selection

Does not play video

I've opened video file but it is not played. I've clicked play button but nothing changed.
Also I see in output:

mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
The gl2 video output driver has been renamed to -vo gl_tiled, but you really should be using -vo gl instead.
X11 error: BadValue (integer parameter out of range for operation)
[gl] Could not create GLX context!
Error opening/initializing the selected video_out (-vo) device.

Linux Mint 18.2

Gtk Sharp control doesn't work -- here is a fix

This is for Linux specifically:

In the control, you are pulling the WID param from drawable.Handle. The handle that returns is an internal handle that's not related to an X11 ID which mplayer needs.

In order to get this ID, we first need the Drawable object, which you can get using this method:

MyTargetWindow.GdkWindow.GetInternalPaintInfo(out var realDrawable, out var x, out var y);

We need to define a way to translate this drawable to the X11 ID, so define this:

[DllImport("gdk-x11-2.0", EntryPoint = "gdk_x11_drawable_get_xid")]
[return: MarshalAs(UnmanagedType.U8)]
public static extern ulong GdkX11DrawableGetXID(IntPtr drawable);

Then you can call it as so:
var x11id = GdkX11DrawableGetXID(realDrawable.Handle);

The value in x11id is what you'd pass in the WID parameter:
Arguments = $"-quiet -v -ontop -slave -idle -vo x11 -wid {x11id}"

Also, you have to use the X11 backend. In MPlayer's documentation, the -vo option only works with X11, OpenGL and DirectX.

Source code in question: https://github.com/majorsilence/MPlayerControl/blob/master/MPlayerGtkWidget/GtkMPlayerWidget.cs

Subtitle

Listing available subtitle tracks in media file, selecting subtitle track to be used and selecting external subtitle track.

WinForms Error when playing, following example

Summary

Error pressing Play button on winforms example

Description

I have followed the example for winforms, the player control is loaded, but then get an error when pressing play.
"Object reference not set to an instance of an object."
There is no inner exception and no other details.

Steps to Reproduce (for bugs)

  1. Create a basic winforms app:
  2. Reference Nuget Package:Install-Package MPlayerControl-Winform
    3 Also added: Install-Package MPlayerControl
  3. add code to button
LibMPlayerWinform.WinFormMPlayerControl playerControl = new LibMPlayerWinform.WinFormMPlayerControl();
            playerControl.Left = 0;
            playerControl.Top = 0;
            playerControl.Width = 200;
            playerControl.Height = 200;
            playerControl.MPlayerPath = @"MediaPlayer.exe";
            playerControl.VideoPath = @"ScreenSoda1.mp4";
            this.Controls.Add(playerControl);

I have tried setting specific paths and outputing the exe and mp4 to the bin folder

Expected Behavior

The video should play

Current Behavior

Get an error message: "Object reference not set to an instance of an object."

Possible Solution

Dont know

Context

Just trying a basic example

Your Environment

Visual Studio 2019
.Net Framework 4.7.2 (also tried 4.5)
Windows 10

Additional Comments:

  1. The example code references: MPlayer.exe, but the file MediaPlayer.exe is what actually exists.
  2. The control does show on screen (with the Stop and Play buttons) but clicking a button causes the error
  3. Ideas:
  • Is its possible to have properties on the control to show/hide the Start/Stop Buttons
  • Methods to Start() / Stop() the video?

Nuget

Add MPlayerControl to Nuget as a Nuget package.

Where is WpfMPlayer?

To use in a WPF application, it says: Add a reference to LibMPlayerCommon, LibImages, and WpfMPlayer

There is no LibImages nor WpfMPlayer in NuGet. Where do I get those libraries?

Video popping up in new window?

Hello!

This is a question about how this software is supposed to work, rather than a bug report.

When using the gtk-widget, should the video play inside the gtk window, or should mplayer start in a separate window, as it does for me? Using Ubuntu 18.04 with supplied mono and gtk from nuget.

I'm having problems problems building from git, so I'm just asking before spending much time on fixing something that might not really be broken. Thanks.

memory leak

When disposing instance of LibMPlayerCommon.MPlayer, mplayer executable (i'm using it on Linux) is not being killed and remains in memory. After few rounds, memory gets full (lot of orphaned mplayer processes).
Quick and dirty fix was to copy content of finalizer (which you are disabling in Dispose()) directly into Dispose method thus killing executable while doing Dispose()
Problem found in git version, on master

Aspect Ratio

Hello!
How to set Aspect Ratio in form?
ScreenAspectRatio.SixteenNine();
Please help. Thanks Gabee8

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.