jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
554 stars 69 forks source link

is there any way to play video loaded to memory using python-mpv? #86

Closed redstoneleo closed 5 years ago

redstoneleo commented 5 years ago

Any way to play bytes object in python-mpv? For example , how to play the contents in Axel in the following ?

File1 = open('vid.webm','rb')
Axel  = File1.read()
jaseg commented 5 years ago

The obvious way would be mpv's memory:// protocol, but I'd advise against that for anything beyond a few megabytes. You could try stuffing it into some mmap'ed shm buffer and shove the fd into mpv using the fd:// protocol but it'd be hard to get one of those in python. I think I'd do this by simply dumping the bytes into a named temporary file and simply playing that.

redstoneleo commented 5 years ago

Thanks ! Is it easy to implement that dumping the bytes into an io.BytesIO object and then playing it ? And what should I do ?

jaseg commented 5 years ago

BytesIO works with python's read and write, but doesn't give you an fd that you could pass into libmpv.