注意:最新版pygameのpygame.movieモジュールは、現在Windows環境では動作しません。pygameの環境でsmpegライブラリを動作させることがまだできていないからです。代わりにpymediaライブラリを使用してください。
Pygameでは基本的なMPEG1形式の動画ファイルを再生することができます。動画の再生はバックグラウンドのスレッドで行われており、これにより簡単に再生の制御を行えます。
動画の音声はサウンドシステムによって完全に制御されていななければいけません。要するに、動画の音声を再生するのであれば pygame.mixerモジュールを初期化してはいけないのです。動画を再生する前にはpygame.mixer.quit命令で初期化の解除を実行するとよいでしょう。動画の再生が終われば再度Mixerモジュールは初期化できます。
The video overlay planes are drawn on top of everything in the display window.動画を通常の画像として画面に表示するには、描写先として一旦隠しSurfaceを作成してそれを画面に出力します。1フレームに付き1度の割合で隠しSurfaceから画面へコピー描写されます。
NOTE: pygame.movie currently does not work on windows with the latest pygame release. As no one has managed to get smpeg working there. The alternative is to use
pymediaPygame can playback video and audio from basic encoded MPEG1 video files. Movie playback happens in background threads, which makes playback easy to manage.
The audio for Movies must have full control over the sound system. This means the pygame.mixer module must be uninitialized if the movie's sound is to be played. The common solution is to call pygame.mixer.quit - uninitialize the mixer before the movie begins. The mixer can be reinitialized after the movie is finished.
The video overlay planes are drawn on top of everything in the display window. To draw the movie as normal graphics into the display window, create an offscreen Surface and set that as the movie target. Then once per frame blit that surface to the screen.
ファイルやpythonオブジェクトから、新規にMPEG形式の動画を読み込みます。Movieオブジェクトは、pygame.mixerモジュールで使用されるSoundオブジェクトと同じように動作します。
Movieオブジェクトには動画描写先となるSurfaceを設定します。動画のSurfaceへの描写はバックグラウンドスレッドで行われます。描写先が画面に表示されるSurfaceだった場合は、ハードウェア側で処理を行う高速な動画描写が行われます。既定では、描写先は画面に表示されるSurfaceとなっています。
Load a new MPEG movie stream from a file or a python file object. The Movie object operates similar to the Sound objects from pygame.mixer.
Movie objects have a target display Surface. The movie is rendered into this Surface in a background thread. If the target Surface is the display Surface, the movie will try to use the hardware accelerated video overlay. The default target is the display Surface.
動画の再生を開始します。音声と映像が無効になっていない場合に、それらの再生が始まります。任意に指定できるloops引数を設定することで、動画を再生する回数を決められます。loops引数に-1を設定すると、動画は無限に再生されます。
Starts playback of the movie. Sound and video will begin playing if they are not disabled. The optional loops argument controls how many times the movie will be repeated. A loop value of -1 means the movie will repeat forever.
動画の再生を停止します。 動画および音声は、現在の再生位置で停止されます。
Stops the playback of a movie. The video and audio playback will be stopped at their current position.
動画を一時停止させたり、再生を再開したりします。
This will temporarily stop or restart movie playback.
動画の再生位置を秒単位で進めます。動画の再生が始まる前の、再生開始時間が決まっていない状態でもこの命令は実行できます。再生位置を前に進めることはできますが、後ろに戻すことはできません。引数には浮動小数点を設定します。
Advance the movie playback time in seconds. This can be called before the movie is played to set the starting playback time. This can only skip the movie forward, not backwards. The argument is a floating point number.
動画の再生位置を開始地点に設定します。動画が停止状態だった場合でも、自動的に再生が開始されます。
動画の巻き戻しができなかった場合は、ValueErrorのエラーが発生します。巻き戻しができないmovieオブジェクトは無効なものと見なされます。
Sets the movie playback position to the start of the movie. The movie will automatically begin playing even if it stopped.
The can raise a ValueError if the movie cannot be rewound. If the rewind fails the movie object is considered invalid.
描写に使用するフレーム数を整数値で設定します。この命令では、動画ファイルから描写先Surfaceオブジェクトに描写する際のフレーム数を、単に伝えるだけです。実際に使われたフレーム数は戻り値として返されるものとなります。
This takes an integer frame number to render. It attempts to render the given frame from the movie to the target Surface. It returns the real frame number that got rendered.
在設定されているビデオフレーム数を整数型の戻り値として返します。
Returns the integer frame number of the current video frame.
現時点の動画再生時間を、秒単位の浮動小数点の戻り値として返します。この命令は現在正常に動作しないようで、常に0.0が取得されてしまいます。
Return the current playback time as a floating point value in seconds. This method currently seems broken and always returns 0.0.
動画が再生中ならtrueが戻り値として返ります。
Returns true if the movie is currently being played.
動画の総再生時間を秒単位の浮動小数点の戻り値として返します。
Returns the length of the movie in seconds as a floating point value.
動画の解像度を取得します。動画のサイズは描写先のSurfaceに応じて拡大されますが、この命令は拡大前の元動画サイズから解像度を取得します。
Gets the resolution of the movie video. The movie will be stretched to the size of any Surface, but this will report the natural video size.
再生動画を含んだMovieファイルを正常に開けた場合はTrueとなります。
True when the opened movie file contains a video stream.
再生する音声を含んだMovieファイルを正常に開けた場合はTrueとなります。
True when the opened movie file contains an audio stream.
動画で再生する音量を設定します。0.0 から 1.0までの値を引数として設定します。音量を0に設定すると、動画ファイルの音声は復号処理されません。
Set the playback volume for this movie. The argument is a value between 0.0 and 1.0. If the volume is set to 0 the movie audio will not be decoded.
動画の出力先となるSurfaceオブジェクトを設定します。追加の引数としてrect型の四角形範囲を設定できます。この範囲は動画の表示位置として使用され、動画の位置やサイズがこれに合わせて変更されます。
出力先SurfaceとしてNone値が設定された場合、動画の復号処理は行われません。
Set the output target Surface for the movie video. You may also pass a rectangle argument for the position, which will move and stretch the video into the given area.
If None is passed as the target Surface, the video decoding will be disabled.