...get properties of a video file with TMediaPlayer?
Author: Antonio Bueno
{
--- english -------------------------------------------------------------------
Easiest way I know to get frame count, video length (in ms) and pixel resolution
of a video file.
--- german --------------------------------------------------------------------
Anzahl der Frames, Länge (in Millisekunden) und Auflösung (in Pixel) einer Video
können wie folgt ermittelt werden.
}
unit MPlayerUnit;
interface
uses
Forms, Classes, Controls, MPlayer;
type
THiddenForm = class(TForm)
MediaPlayer: TMediaPlayer;
public
procedure GetProperties(FileName: string;
var MediaFrames, MediaLength, MediaWidth, MediaHeight: Integer);
end;
var
HiddenForm: THiddenForm;
implementation
{$R *.dfm}
procedure THiddenForm.GetProperties(FileName: string;
var MediaFrames, MediaLength, MediaWidth, MediaHeight: Integer);
begin
MediaPlayer.FileName := FileName;
MediaPlayer.Wait := False;
MediaPlayer.Open;
MediaPlayer.TimeFormat := tfFrames;
MediaFrames := MediaPlayer.Length;
MediaPlayer.TimeFormat := tfMilliseconds;
MediaLength := MediaPlayer.Length;
MediaPlayer.DisplayRect := Rect(1, 1, 0, 0); {"0, 0" forces resolution autodetect}
MediaWidth := MediaPlayer.DisplayRect.Right;
MediaHeight := MediaPlayer.DisplayRect.Bottom;
if (MediaWidth <= 0) or (MediaHeight <= 0) then
begin {invalid values mean not video}
MediaWidth := 0;
MediaHeight := 0;
end;
MediaPlayer.Close;
end;
end.
printed from
www.swissdelphicenter.ch
developers knowledge base