Class TVideo
Unit
Declaration
type TVideo = class(TObject)
Description
Video.
It can load movie from a sequence of image files. With the help of ffmpeg, it can also load any normal movie file format, like avi (compressed by anything ffmpeg can handle), OggTheora and many others. ffmpeg really handles probably everything you will ever want.
Video is stored simply as a sequence of uncompressed images in memory. This is not good for real movies, so don't even try to open any real, 2 hour, full dvd resolution movie — loading will take hours and you will clog your memory. This class is not supposed to be used in a real movie player.
However, this simple storage is perfect to load a short movie for some effect in a game, for example a simple movie with flames or smoke to be shown as texture in your 3D game. Memory and loading time is acceptable then, and you want to prepare all your textures before the game starts anyway (for a 3D game, there's no time to decode some movie format while playing...).
See example program examples/images_videos/simple_video_editor/
in our engine for example of a simple movie player/editor implemented on top of this class.
Hierarchy
- TObject
- TVideo
Overview
Methods
constructor Create; |
|
destructor Destroy; override; |
|
function Count: Integer; |
|
function Width: Cardinal; |
|
function Height: Cardinal; |
|
function IndexFromTime(const Time: TFloatTime): Integer; |
|
function ImageFromTime(const Time: TFloatTime): TCastleImage; |
|
function TimeDuration: Single; |
|
procedure LoadFromFile(const Url: String; const ResizeToX: Cardinal = 0; const ResizeToY: Cardinal = 0; const Interpolation: TResizeInterpolation = riBilinear; const LoadOptions: TLoadImageOptions = []); |
|
procedure SaveToFile(const Url: String); |
|
procedure Resize(const ResizeToX, ResizeToY: Cardinal; const Interpolation: TResizeInterpolation = riBilinear); |
|
procedure Close; |
|
procedure MixWithSelfBackwards; |
|
procedure FadeWithSelf(FadeFrames: Cardinal); |
|
class function FrameIndexFromTime(const Time: TFloatTime; const ACount: Integer; const AFramesPerSecond: Single; const ATimeLoop, ATimeBackwards: boolean): Integer; |
|
function AlphaChannel( const AlphaTolerance: Byte = DefaultAlphaTolerance): TAlphaChannel; |
|
procedure FlipHorizontal; |
|
procedure FlipVertical; |
Properties
property Items [Index: Integer]: TCastleImage read GetItems; |
|
property FramesPerSecond: Single read FFramesPerSecond; |
|
property Loaded: boolean read FLoaded; |
|
property TimeLoop: boolean read FTimeLoop write FTimeLoop default false; |
|
property TimeBackwards: boolean
read FTimeBackwards write FTimeBackwards default false; |
Description
Methods
constructor Create; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
function Count: Integer; |
|
Loaded video properties. Use these only when Loaded is Time is supposed to be in seconds. (Actually, we don't care; but when the movie file says to play "25 frames per second", then we will make 25 frames per this Time unit. So you probably want to count the Time in seconds too.) Count is always >= 1 when the video is loaded. That is, we don't allow videos with zero frames (I don't know if any movie format allows this.) |
function Width: Cardinal; |
|
This item has no description. |
function Height: Cardinal; |
|
This item has no description. |
function IndexFromTime(const Time: TFloatTime): Integer; |
|
This item has no description. |
function ImageFromTime(const Time: TFloatTime): TCastleImage; |
|
This item has no description. |
function TimeDuration: Single; |
|
Duration of the video. In seconds (or, more precisely, in the same time units as for ImageFromTime and other methods). Note that this doesn't count the "backwards" running time, so it ignores TimeBackwards and TimeLoop values. Use this only when Loaded. |
procedure LoadFromFile(const Url: String; const ResizeToX: Cardinal = 0; const ResizeToY: Cardinal = 0; const Interpolation: TResizeInterpolation = riBilinear; const LoadOptions: TLoadImageOptions = []); |
|
Loads video from file or URL. URL is downloaded using CastleDownload unit. As always, if you all you care about is loading normal files, then just pass a normal filename (absolute or relative to the current directory) as the URL parameter. Supported video formats:
Parameters ResizeToX, ResizeToY allow you to resize video frames. If one of them is non-zero, the appropriate video size (width and/or height) will be resized. Resizing quality is controlled by Interpolation parameter. |
procedure SaveToFile(const Url: String); |
|
Save video to file (or image sequence). Handled formats: just like LoadFromFile. Also, just like LoadFromFile, we need ffmpeg on $PATH to save to any single-file movie format. |
procedure Resize(const ResizeToX, ResizeToY: Cardinal; const Interpolation: TResizeInterpolation = riBilinear); |
|
This item has no description. |
procedure Close; |
|
Release all resources allocated by LoadFromFile. Loaded property changes to It's safe to call this even if Loaded is already |
procedure MixWithSelfBackwards; |
|
Mix the video with itself played backwards, to force the video to play seamless in a loop. This edits the loaded video, such that every frame becomes a mix between itself and the corresponding frame from the second half of the video. This forces any movie to become seamless when played in a loop. After this, the movie frames count is halved and TimeBackwards is set to Unfortunately, this doesn't look perfect, human eye can easily notice the extreme time points (in the middle and at the end), when objects in the video reverse their directions etc. So the video is seamless, and it's a better trick than just setting TimeBackwards := true, but it still doesn't really look good. |
procedure FadeWithSelf(FadeFrames: Cardinal); |
|
Edit the video beginning to fade with the video ending, thus forcing the video to play seamless in a loop. The idea is to take out last FadeFrames from the video (FadeFrames must be >= 0 and <= Count div 2). And then mix the beginning of the video, such that the beginning FadeFrames frames gradually fade from the original end of video to original begin of the video. Video must be loaded when using this. Exceptions raised
|
class function FrameIndexFromTime(const Time: TFloatTime; const ACount: Integer; const AFramesPerSecond: Single; const ATimeLoop, ATimeBackwards: boolean): Integer; |
|
Similar to IndexFromTime, this is a class method that calculates frame index using the same algorithm. (Actually, IndexFromTime just calls this, but this is implementation detail...). The idea is that you can reuse the same algorithm in cases when you somehow have the video data but do not have an instance of TVideo class. In particular, this public for TGLVideo.IndexFromTime, TGLVideo.GLTextureFromTime methods. |
function AlphaChannel( const AlphaTolerance: Byte = DefaultAlphaTolerance): TAlphaChannel; |
|
Alpha channel type of loaded video. See TCastleImage.AlphaChannel for precise meaning of this. Currently based on the first video image, so it's fast although in some cases possibly inaccurate. |
procedure FlipHorizontal; |
|
This item has no description. |
procedure FlipVertical; |
|
This item has no description. |
Properties
property Items [Index: Integer]: TCastleImage read GetItems; |
|
This item has no description. |
property Loaded: boolean read FLoaded; |
|
This item has no description. |
property TimeLoop: boolean read FTimeLoop write FTimeLoop default false; |
|
Play the video in a never-ending loop. If It's Ok to change the value of this property at any time (even when video is not yet loaded), since this doesn't really cause any internal recalculation. It only affects what *FromTime methods return. |
property TimeBackwards: boolean
read FTimeBackwards write FTimeBackwards default false; |
|
Play the video backwards after playing it forward. This cooperates with TimeLoop. If this is It's Ok to change the value of this property at any time (even when video is not yet loaded), since this doesn't really cause any internal recalculation. It only affects what *FromTime methods return. |
Generated by PasDoc 0.16.0-snapshot.