I’m creating a simple media player. It will be used by non-coders, so I’d like for them to be able to launch it in an intuitive way, eg. by double clicking an .exe
The code I built works as desired in spyder. I managed to export it using pyinstaller, and when launched from powershell prompt in the correct environment, the executable works as expected (except for ghosting at the beginning, that I’m also working on.)
If I launch the executable from root, or by double clicking however, I get the following error:
Traceback (most recent call last):
File "PygletCodec.py", line 7, in <module>
File "pygletmedia__init__.py", line 142, in load
File "pygletmedia__init__.py", line 132, in load
File "pygletmediacodecswmf.py", line 880, in decode
File "pygletmediacodecswmf.py", line 504, in __init__
File "pygletmediacodecswmf.py", line 626, in _load_video
pyglet.media.exceptions.MediaDecodeException: [WinError -1072875852] Les données spécifiées pour le type de média ne sont pas valides, sont incohérentes ou ne sont pas prises en charge par cet objet
[13344] Failed to execute script 'blablabla' due to unhandled exception!
I’ve looked at the corresponding file on github, (Here) and the error is raised in the following lines:
try:
self._source_reader.SetCurrentMediaType(self._video_stream_index, None, uncompressed_mt)
except OSError as err: # Can't decode codec.
raise DecodeException(err) from None
where the comment indicates that the codec can’t be used (and as whoever wrote it surely knows much better than I do, I’m inclined to agree).
The error can be reproduced by exporting the following minimal version of the code with pyinstaller (the command I used was simply “pyinstaller filename.py” as I hardcoded the full filepath for simplicity):
import pyglet
window = pyglet.window.Window(width = 1800, height= 1000)
player = pyglet.media.Player()
source = pyglet.media.load(r"full_filepath.mp4")
player.queue(source)
player.play()
@window.event
def on_draw():
window.clear()
if player.source and player.source.video_format:
player.get_texture().blit(0, 0)
pyglet.app.run()
I’m from a more scientific use background, so don’t know much about codecs or media playback, though I’ve been trying to learn. Thank you for any help.
I thought that codecs were available system wide, so I don’t understand why they can’t be found. Pyglet seems to have been imported without problem, and I can’t see a secondary import that’s failing, so I don’t understand what one environment has access to that the other doesn’t.
I’ve tried building and playing the executable on two windows computers that I have available to me, with the same results. I’ve tried changing the codec used to build the video. I’ve asked chatgpt which says that the problem is pyglet can’t access windows media framework, but I hon’t know how to import this manually.
THFermat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.