简体   繁体   中英

How to play videos with pygame?

I am trying to make Pygame run some mpg vids for the intro of my rpg. But it isnt working. I have read the pygame docs and it says that video support is currently unstable and that i should use pymedia instead. I personally cannot make heads nor tails of pymedia. So is there ANY way to play videos with pygame?

(I decided to risk posting this as an answer rather than a comment.)

The three "hopeful" candidates for video editing/processing in Python that I have found are PyMedia (which I gave up on), PyGame (which may meet your needs but did not meet mine) and pyffmpeg (which is very promising but depends on Cython, and I could not get Cython to work on my system).

Most mature video editing or processing applications out there (commercial or open source) use the FFmpeg libraries in some way. PyMedia includes a modified version of the libav* libraries, for example. Even many commercial tools use these libraries in violation of the FFmpeg license.

FFmpeg is implemented in C, and has no hooks for other languages "out of the box". Learning the API for the libav* libraries is not for the faint of heart (no straight-forward docs provided, just read the source and examples and FAQ), but as far as I can tell, FFmpeg is basically how video is done in the "real world".

So if you can't find an out-of-the-box solution for Python that meets your needs, you could use SWIG or another interface generator to wrap the stock FFmpeg libraries as a starting point. I have in mind to do this myself in the future if I find the time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM