baudm / mplayer.py Goto Github PK
View Code? Open in Web Editor NEWLightweight Python wrapper for MPlayer
Home Page: http://pypi.python.org/pypi/mplayer.py
License: GNU Lesser General Public License v3.0
Lightweight Python wrapper for MPlayer
Home Page: http://pypi.python.org/pypi/mplayer.py
License: GNU Lesser General Public License v3.0
Hi, I was trying to use mplayer.py and expect the mplayer process can exit when the music is done. tried to remove "-idle" parameter in the base args, while it didn't work. wondering is there a way to let the mplayer exit when play completes?
Thanks.
Original issue 2 created by baudm on 2011-03-17T10:58:35.000Z:
What steps will reproduce the problem?
import mplayer
p = mplayer.Player()
for attribute in dir(p):
getattr(p, attribute)
What is the expected output? What do you see instead?
Either nothing if the value of the property can be retrieved or a message in the form "Failed to get value of property %s" % property.
Instead MPlayer crashes with signal "11" in module "unknown"
What version of the product are you using? On what operating system?
Machine # 1: Python 2.6.6 on Debian 6.6.0 (squeeze) with PyMPlayer-0.6.0 (installed through pip) and MPlayer SVN-r31918 from debian-multimedia.org repository
Machine # 2: Debian unstable with identical Python and PyMPlayer versions, but MPlayer SVN-r33057 from same repository
Please provide any additional information below.
I was able to fix the problem by adding a list of properties to be excluded to the "_generate_properties(cls)" method in line 190 and not adding those to the class. The list of properties to exclude that I arrived at through trial&error on my machine is as follows:
exclude = ['capturing','sub', 'sub_demux', 'sub_file', 'sub_source',
'sub_vob', 'switch_program', 'teletext_page',
'tv_brightness', 'tv_contrast', 'tv_hue', 'tv_saturation']
If I don't have mplayer
in PATH and specify it with mplayer.Player.exec_path = /whatever/mplayer
then I get errors:
AttributeError: 'Player' object has no attribute 'loadfile'
I found that this is because all those dynamic methods/are generated by introspect
class method. It runs on module import, but there is no mplayer
in PATH already, then it fails silently
# Introspect on module load
try:
Player.introspect()
except OSError:
pass
Then I specify exec path and get errors for every dynamic attribute because then has not been generated.
I've added mplayer.Player().introspect()
after specifying exec_path
and it works, but it's just a workaround.
I'm wondering why introspect()
gets called on module import and not in __init__
, for example? Also, why specify exec_path
on class level and not pass it as a parameter? Should I submit PR to fix this or there is a good reason why it's done this way?
***** this is my test does not play:
import Player
player = Player()
player.args=['-vfm', 'ffmpeg', '-autosync', '30', '-mc', '2.0',
'-ontop', '-vf', 'scale', '-xy', '640:480', '-panscan', '1',
'-cache', '8192', '-ontop']if name == "main":
player.loadfile('*.mkv')
***** and this will play:
import time
import Playerplayer = Player()
player.args=['-vfm', 'ffmpeg', '-autosync', '30', '-mc', '2.0',
'-ontop', '-vf', 'scale', '-xy', '640:480', '-panscan', '1',
'-cache', '8192', '-ontop']if name == "main":
player.loadfile('*.mkv')
time.sleep(player.length)
and it does not going "-ontop" as mentioned in player.args
my player version:
CPU vendor name: GenuineIntel max cpuid level: 22
CPU: Intel(R) Core(TM) i3-8130U CPU @ 2.20GHz (Family: 6, Model: 142, Stepping: 10)
extended cpuid-level: 8
extended cache-info: 16801856
Detected cache-line size is 64 bytes
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNowExt: 0 SSE: 1 SSE2: 1 SSE3: 1 SSSE3: 1 SSE4: 1 SSE4.2: 1 AVX: 1
Compiled with runtime CPU detection.
get_path('codecs.conf') -> 'C:/Program Files/MPlayer/mplayer/codecs.conf'
Reading optional codecs config file C:/Program Files/MPlayer/mplayer/codecs.conf: No such file or directory
Using built-in default codecs.conf.
init_freetype
Hi, baudm,
I encountered 2 issues when trying to use loop parameter to play an item, could you help to take a look?
(1). For local files, e.g., I have a wma file in which I recorded counting from 1, 2, 3, 4.
if I try to loop 3 times, the first 2 times will skip the last seconds of the wma file, it will only count 1, 2, 3. with 4 skipped. and the last time, it can play correctly.
i.e. loop 3 times, it will count like: 1, 2, 3, 1, 2, 3, 1, 2, 3, 4.
(2) when play https links, the loop will not work at all (http link will played in loop), no matter what loop value I set, it will only play once, and print below messages:
[tls @ 00000000017712c0]The TLS connection was non-properly terminated.
[tls @ 00000000017712c0]The specified session has been invalidated for some reason.
[tls @ 00000000017712c0]The specified session has been invalidated for some reason.
[tls @ 00000000017712c0]The specified session has been invalidated for some reason.
[tls @ 00000000017712c0]The specified session has been invalidated for some reason.
I can repro these 2 issues on both windows and ubuntu systems.
Here's my test code:
url = '/tmp/count1to4.wma'
p = Player()
p.loadfile(url)
time.sleep(1)
p.loop = 3
p.pause()
Thanks in advance.
Original issue 15 created by baudm on 2014-10-31T12:37:46.000Z:
I try to implement a audio player using the library. Somehow I cannot get the audio to load
No error message is displayed.
seems like p.loadfile doesnt work as ps ax shows
/usr/bin/mplayer -slave -idle -really-quiet -msglevel global=4 -input nodefault-bindings -noconfig all
but no file seems loaded
import pygame
import os
import subprocess
import sys
import time
import mpylayer
import subprocess
from mplayer import *
audiofile = "/mp3/80er/A\ Flock\ of\ Seagulls\ -\ I\ Ran.mp3"
gfx_rev_normal = pygame.image.load('rev_normal.png')
pygame.init()
screen = pygame.display.set_mode((800, 480))
font = pygame.font.SysFont("monospace", 36)
source_text = font.render("Audio Player", 1, (255, 255, 255))
text_width = source_text.get_width()
source_text_x = screen.get_width() / 2
source_text_x = source_text_x - (text_width/2)
source_text_y = 10
screen.blit(source_text,(source_text_x, source_text_y))
Player.exec_path="/usr/bin/mplayer"
p = Player()
p.loadfile('audiofile')
p.volume=100
running = True
while running:
time.sleep(0.1)
print p.stream_pos
screen.blit(gfx_rev_normal,(30,120))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
running = False
Original issue 13 created by baudm on 2013-04-01T22:35:20.000Z:
I'd like to be able to see on the Player class if the player is done playing current file or list.
Actually, even better would be if there was a callback that fires when the player is done playing. That would save me the trouble of checking periodically if the player is done.
Original issue 5 created by baudm on 2011-04-28T14:22:52.000Z:
What steps will reproduce the problem?
What version of the product are you using? On what operating system?
0.6.0 on Fedora Linux
Original issue 3 created by baudm on 2011-03-18T22:30:53.000Z:
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Expected is to switch the video file playing.
Insteda the application is closed.
What version of the product are you using? On what operating system?
latest hg clone from today (March 18)
Please provide any additional information below.
Some debugging showed that during changing the files
GtkPlayerView._handle_data is called. It assumes that
once you get "EOF code" this is the end.
In mp_core.h there are the EOF codes:
I changed the method to check for "EOF code: 4"
which works for me.
I have a mobile wheeled robot with camera. I using Python script to control it via keyboard. Normally I will open mplayer in the 1st terminal for the camera steaming and open another terminal for controller. My question is whether I can use this wrapper to create a single window to streaming the camera and run my Python script in the background? My robot website: www.opendr.xyz
Original issue 14 created by baudm on 2013-05-20T16:51:18.000Z:
What steps will reproduce the problem?
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
In core.py, line 252, change this:
t = mtypes.type_map[arg]
sig.append('{0}{1}{2}'.format(t.name, i, optional))
types.append('mtypes.{0},'.format(t.name))
to this:
if(arg in mtypes.type_map):
t = mtypes.type_map[arg]
sig.append('{0}{1}{2}'.format(t.name, i, optional))
types.append('mtypes.{0},'.format(t.name))
This gets rid of the KeyError during installation.
Original issue 12 created by baudm on 2013-01-15T19:52:29.000Z:
What steps will reproduce the problem?
1.Start stream
from mplayer import Player
p = Player()
p.loadfile('http://1live.akacast.akamaistream.net/7/706/119434/v1/gnl.akacast.a$
What is the expected output? What do you see instead?
mplayer: could not connect to socket
mplayer: No such file or directory
What version of the product are you using? On what operating system?
Latest mplayer
https://pypi.python.org/pypi/mplayer.py/ still lists the obsolete
Home Page: http://code.google.com/p/python-mplayer/
which probably originates in https://github.com/baudm/mplayer.py/blob/master/setup.py#L14
Original issue 6 created by baudm on 2011-07-10T20:01:54.000Z:
What steps will reproduce the problem?
python gtk2.py /path/filename/with/special/characters/vidéo.avi
What version of the product are you using? On what operating system?
PyMPlayer: last version (e03cdd3f41e9)
Python: 2.7.1
OS: Archlinux
Please provide any additional information below.
It comes from line 94 in mtypes.py:
return MPlayerType.adapt(obj.encode('utf-8', 'ignore'))
For example:
>>> obj = u"é"
>>> obj.encode('utf-8', 'ignore')
'\xc3\xa9'
>>> repr(obj.encode('utf-8', 'ignore'))
"'\xc3\xa9'"
I replaced this line with:
return obj.encode('utf-8', 'ignore').replace(' ', '\ ')
It seems to work for paths with special characters and spaces, but I'm not sure it's a good solution.
Running
Mplayer 1.3.0-7
Fedora 26
Python 3.6.2
using your example code:
from mplayer import Player, CmdPrefix
Player.cmd_prefix = CmdPrefix.PAUSING_KEEP
player = Player()
player.loadfile('music/Haunted.mp3')
My file does not play.
I get the following:
do_connect: could not connect to socket
connect: No such file or directory
But, i get that no matter how I interface with mplayer, so I assume that's normal.
Thank you!
The docs for the Player suggest importing a class named CommandPrefix
, but the corrent name is CmdPrefix
. Note tthe wrong name is given in 2 different import statements on that page.
Hello,
I'm trying to test mplayer.py with the examples provided, but reach this errors:
do_connect: could not connect to socket
connect: No such file or directory
How could I solve this?
Thank you!
Original issue 11 created by baudm on 2012-10-07T17:48:28.000Z:
What steps will reproduce the problem?
from mplayer import Player, CmdPrefix
# Set default prefix for all Player instances
Player.cmd_prefix = CmdPrefix.PAUSING_KEEP
# Since autospawn is True by default, no need to call player.spawn() manually
player = Player()
# Play a file
player.loadfile('test.mov')
# Pause playback
player.pause()
# Get title from metadata
metadata = player.metadata or {}
print metadata.get('Title', '')
# Print the filename
print player.filename
# Seek +5 seconds
player.time_pos += 5
# Set to fullscreen
player.fullscreen = True
# Terminate MPlayer
player.quit()
<b>What is the expected output? What do you see instead?</b>
if I run from the command line
mplayer test.mov
it works
but if I run python test.py
it opens the file an instant and throws this error:
jjdenis@jj-linux:~/Programas$ python test.py
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open VDPAU backend libvdpau_nvidia.so: cannot open shared object file: No such file or directory
Unsupported PixelFormat 61
Unsupported PixelFormat 53
Unsupported PixelFormat 81
<b>What version of the product are you using? On what operating system?</b>
mplayer.py-0.7.0.tar.gz (md5) on Ubuntu 12.04
<b>Please provide any additional information below.</b>
Thanks for your help.
When i run the qt4.py example file, two things happen:
v.player.pause()
just to see it startThe line of code that seems to break it is: self._stdout = _StdoutWrapper(handle=stdout)
When I comment out the stdout wrapper, it works fine.
Hey, I had an issue with audio detection. I skimmed the network of projects from this one for solutions and found a fork with a solution. Don't know why there isn't a pull request for it, however, changing it in this project solved the problem:
https://github.com/tb0hdan/mplayer.py/commit/a392ca594dfe7a25278881581342b9910ea27ff4
Could we please get this corrected in the official project too?
Hi,
When using QtPlayer object (or QPlayerView), I am not able to access video properties. For example, print(v.player.height)
in the example given in qt4.py returns None. However, I don't encounter this issue if I use directly a Player instance. Any idea why?
Thanks
Does it work on all systems where mplayer does?
Personally I had this error when running p = mplayer.Player()
on ubuntu 16.04 with python 3.5.2.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/mplayer/core.py", line 109, in __init__
self.spawn()
File "/usr/local/lib/python3.5/dist-packages/mplayer/core.py", line 319, in spawn
close_fds=(not subprocess.mswindows))
AttributeError: module 'subprocess' has no attribute 'mswindows'
Hi,
To play some url, I have to change the mplayer cache option dynamically.
Is it possible to set the mplayer cache option with mplayer.py (~/.mplayer/config doesn't fit my needs, as it set the same cache for any url)
Thanks
Error
Traceback (most recent call last):
File "/python/code/play.py", line 13, in <module>
m = mplayer.Player()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mplayer/core.py", line 109, in __init__
self.spawn()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mplayer/core.py", line 319, in spawn
close_fds=(not subprocess._mswindows))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1540, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'mplayer'
code
import mplayer
m = mplayer.Player()
Platform: MAC OS
Python Vension: 3.5
Excuse me, hope to get the answer
Original issue 9 created by baudm on 2011-12-20T13:03:26.000Z:
When using for example Celery with mplayer.py the Queue gets filled in _StdoutWrapper._process_output
but for some reasons i dont fully understand the same Queue stays empty on the other side at Player _run_command.
By changing the queue import in misc.py to
from multiprocess import Queue as queue
and changing the instantiation of self._answers to queue() fixed this problem for me.
Sorry i cant create a diff right now i just wanted to report it.
Thanks for the great work with mplayer.py :)
Well, I solved the errors in my previous post by doing a fresh clone from github and reinstalling. The pip install doesn't seem to be working. Now my test program below runs without error and outputs the expected lines. The only problem is there is NO SOUND from the Raspberry Pi. Have tried both HDMI and Analog audio. When using mplayer from command line, the audio plays fine I am running on an RPi 3b+ with latest versions of Linux and Python. Here is the code:
#!/usr/bin/env python3
from mplayer import Player, CmdPrefix
import time
Player.cmd_prefix = CmdPrefix.PAUSING_KEEP
player = Player()
player.loadfile('/home/pi/Music/dc.mp3')
metadata = player.metadata
print (metadata.get('Artist', ''))
print (metadata.get('Title', ''))
print (player.filename)
print(player.length)
Here is the output:
pi@raspberrypi:/pp $ ./mptest.py/pp $
Dixie Chicks
Ready To Run
dc.mp3
232.0
pi@raspberrypi:
If I could get audio, I could finish this project. Please help
Thanks,
Ken
Original issue 4 created by baudm on 2011-04-28T14:15:55.000Z:
Please allow adding of extra parameters to mplayer command line. For
example I need "-volume 0". When it's started, it's playing at 100% volume
and even if I am trying to immediatelly change it to real volume set in my
application, it's aprox 1 second playing at max volume, which is very
disturbing.
What version of the product are you using? On what operating system?
0.6.0 on Fedora Linux
Environment:
Raspberry Pi Stretch
Python 3.5.3
MPlayer 1.3.0 (Debian)
I am attempting top use mplayer.py using the python command interface.
I have not found any documentation as to the actual methods and properties that can be used.
I am able to do a p.loadfile and can print the correct filename and length. However, I get no audio either via local or HDMI audio devices., The file plays fine when using mplayer from the linux command line. Also, when I try the metadata it seems to return None. Here is my code:
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
from mplayer import Player
p = Player()
p.loadfile('kk.mp3')
print (p.filename)
kk.mp3
print (p.length)
252.0
metadata = p.metadata
print (metadata)
None
print (metadata.get('Title', ''))
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'NoneType' object has no attribute 'get'
I'm trying to do this
import mplayer
url = "https://www.youtube.com/watch?v=n93bga1b1gs&t=7s"
print url
p = mplayer.Player()
But I'm getting this:
Traceback (most recent call last):
File "\test.py", line 36, in <module>
stream = Stream()
File "\test.py", line 19, in __init__
p = mplayer.Player()
File "\mplayer\core.py", line 110, in __init__
self.spawn()
File "C:\Python27\lib\site-packages\mplayer\core.py", line 324, in spawn
close_fds=(sys.platform != 'win32'))
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Original issue 1 created by baudm on 2010-12-29T19:22:37.000Z:
What steps will reproduce the problem?
from mplayer import Player
import time
p = Player()
p.start()
p.loadfile('...any file...')
while p.is_alive():
time.sleep(1) # at the moment you press 'q' so quit mplayer
print p.filepath # the program hangs at this point
timeout is not working, self._stdout._file is not None
I simply add line 306 in core.py:
'if not self.is_alive(): return None'
may be is a better solution to this problem
So sorry if this is the most dumbest question ever, I am a noob that's has been trying to install this mplayer wrapper all day, and can't seem to get it.
So my steps basically are:
git clone https://github.com/baudm/mplayer.py.git
cd mplayer.py
Than I tried to install:
3. sudo python setup.py install
But I keep getting this error:
pi@raspberrypi:~/mplayer.py $ python setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in
from mplayer import version
File "/home/pi/mplayer.py/mplayer/init.py", line 38, in
from mplayer.core import Player, Step
File "/home/pi/mplayer.py/mplayer/core.py", line 417, in
Player.introspect()
File "/home/pi/mplayer.py/mplayer/core.py", line 312, in introspect
cls._generate_properties()
File "/home/pi/mplayer.py/mplayer/core.py", line 199, in _generate_properties
pname, ptype, ptype2, pmin, pmax = line
ValueError: need more than 1 value to unpack
Could someone please help me with this? I have no clue what to do to fix this.
Original issue 10 created by baudm on 2012-01-03T04:57:37.000Z:
What steps will reproduce the problem?
What is the expected output? What do you see instead?
I expect to see the stream info and song titles, but neither appear.
What version of the product are you using? On what operating system?
0.7 on Kubuntu
Original issue 8 created by baudm on 2011-08-03T00:44:15.000Z:
Hi,
I am not sure this is the right place for the question, but I wouldn't want to pollute the wiki pages.
Anyway, I have done related work interfacing mplayer through a remuco (code.google.com/p/remuco) adapter.
Our problem has always been getting information from the player, as it seems to export it solely to stdout.
I took a very quick look and so far you are always running mplayer in slave mode. Is that true? Have you tried to talk to a player which is already running?
Maybe we can help each other.
Congratulations on your work :)
Original issue 16 created by baudm on 2015-03-25T02:00:58.000Z:
What steps will reproduce the problem?
1.sudo pip install mplayer.py
On what operating system?
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.10
DISTRIB_CODENAME=utopic
DISTRIB_DESCRIPTION="Ubuntu 14.10"
NAME="Ubuntu"
VERSION="14.10 (Utopic Unicorn)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.10"
VERSION_ID="14.10"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
Please provide any additional information below.
jack@ubuntu:~/Shared/pyratao$ sudo pip install mplayer.py
Downloading/unpacking mplayer.py
Downloading mplayer.py-0.7.0.tar.gz
Running setup.py (path:/tmp/pip_build_root/mplayer.py/setup.py) egg_info for package mplayer.py
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/mplayer.py/setup.py", line 5, in <module>
from mplayer import version
File "mplayer/init.py", line 37, in <module>
from mplayer.core import Player, Step
File "mplayer/core.py", line 412, in <module>
Player.introspect()
File "mplayer/core.py", line 308, in introspect
cls._generate_methods()
File "mplayer/core.py", line 292, in _generate_methods
func = cls._gen_method_func(name, args)
File "mplayer/core.py", line 252, in _gen_method_func
t = mtypes.type_map[arg]
KeyError: u'2.0-728-g2c378c7-2ubuntu3'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/mplayer.py/setup.py", line 5, in <module>
from mplayer import __version__
File "mplayer/init.py", line 37, in <module>
from mplayer.core import Player, Step
File "mplayer/core.py", line 412, in <module>
Player.introspect()
File "mplayer/core.py", line 308, in introspect
cls._generate_methods()
File "mplayer/core.py", line 292, in _generate_methods
func = cls._gen_method_func(name, args)
File "mplayer/core.py", line 252, in _gen_method_func
t = mtypes.type_map[arg]
KeyError: u'2.0-728-g2c378c7-2ubuntu3'
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/mplayer.py
Storing debug log for failure in /home/jack/.pip/pip.log
Original issue 7 created by baudm on 2011-07-26T08:21:47.000Z:
i will be great if there is clutter support available i know it can done by embedding Player object clutter actor but it would be nice if there clutter class available like gtkplayerview
clutter have better support for zooming etc
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.