Code Monkey home page Code Monkey logo

python-mediadecoder's Introduction

Movie decoder for Python based on MoviePy

This library allows you to decode and render movies in Python. It is based on the (rather excellent) MoviePy module created by Zulko, which offers a convenient Python interface to ffmpeg. This library should hence be able to decode any format that ffmpeg supports. If ffmpeg is not found to be installed, moviepy will download it for you on first use, which may take some time (keep an eye on that terminal/command prompt to see the download progress).

One will have to implement the actual rendering of each frame himself, but you can use the play.py module included in this repository as an example. The play.py shows how to play a video using OpenGL+pygame for the video rendering and pyaudio for audio playback (using pygame.mixer is also an option, but that doesn't work smoothly yet).

To see it run right away, you can invoke play.py with the following options:

usage: play.py [-h] [-d] [-f] [-l] [-s {pygame,pyaudio}] [-r RESOLUTION]
               mediafile

positional arguments:
  mediafile             the path to the media file to play

optional arguments:
  -h, --help            show this help message and exit
  -d, --debug           debugging mode: print lots of info
  -f, --fullscreen      show movie in fullscreen
  -l, --loop            loop the video
  -s {pygame,pyaudio}, --soundrenderer {pygame,pyaudio}
                        the backend that should render the sound (default:
                        pyaudio)
  -r RESOLUTION, --resolution RESOLUTION
                        The resolution of the video. Specify as
                        <width>x<height> (default: 1024x768)

This example player furthermore supports pausing playback (by pressing space), seeking 10s forward or backward (by pressing left or right arrow keys) and can be exited by pressing ESC or clicking the close button.

Dependencies

This module depends on the following other libraries.

That should be enough to get you started, if you plan to implement your own rendering functions for video and audio. If you also want to be able to view the example provided by play.py you further need

TODO's

This module is (and will probably always be) a 'work in progress'. For now

  • Implementing volume control functions.
  • Find a faster method than glTexSubImage2D to get the frame onto the texture to improve performance of the player (even though it works quite well now, it plays Big Buck Bunny at 1080p @60fps without too many dropped frames, but performance is still far behind to other players such as vlc).
  • Get pygame audiorenderer working with the current audioqueue implementation.
  • Let the decoder also work for audio-only streams/files.

are on my to-do list, but if you have more suggestions, feel free to open up an issue with a feature request.

API reference

Further documentation, including an API reference, can be found here.

License

Like moviepy, this module is licensed under the MIT license:

The MIT License (MIT) Copyright (c) 2016 Daniel Schreij

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

python-mediadecoder's People

Contributors

dschreij avatar smathot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-mediadecoder's Issues

UnicodeDecodeError when processing import Exception

I received the following automated bug report via OpenSesame. Essentially, the problem is that you're inserting non-Unicode text (coming from the Exception) into a Unicode template string when handling an Exception. The result is that users actually see an error message that results from parsing the error message--confusing.

Traceback:
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 159, in new
    self.experiment, script, self.experiment.item_prefix())
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\plugins.py", line 361, in load_plugin
    item_module = import_plugin(plugin, _type=_type)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\plugins.py", line 332, in import_plugin
    return imp.load_source(plugin, path)
  File "C:\Program Files (x86)\OpenSesame\share\opensesame_plugins\media_player_mpy\media_player_mpy.py", line 42, in <module>
    import mediadecoder
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\mediadecoder\__init__.py", line 6, in <module>
    from mediadecoder.decoder import Decoder
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\mediadecoder\decoder.py", line 21, in <module>
    Please make sure that they are installed.""".format(e))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 30: ordinal not in range(128)

movies shorter than 1s give an error

When playing movies that are shorter than 1s I get an error about the max_duration in timer.py:

max_duration needs to be greater than 1.0

The goal of this condition is unclear to me. Removing the condition fixes the problem (but maybe creates problems in other cases).

Python 3: Crash on exit

Hi Daniel,

I am getting weird behaviour under Python 3 in Expyriment using mediadecoder:

I play a video, then call the stop method on the Decoder object, then call sys.exit(). On OS X I get a Abort trap: 6 error, and an error report window pops open. On Linux it also crashes, according to Oliver. I assume this has to do with the video (or audio) thread not properly being terminated. Is there anything else mediadecoder-related that I have to call before I can quit Python, such that it does not crash?

Cheers,
Florian

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.