A
A
Alex Alex2016-10-02 01:12:56
Delphi
Alex Alex, 2016-10-02 01:12:56

How to programmatically get the length of a video in seconds?

How to programmatically find out the length of a video in seconds / milliseconds in Delphi, it is desirable that there be more than one format

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2016-10-02
@dimonchik2013

www.delphiffmpeg.com

O
ORTOL, 2016-10-07
@ORTOL

Delphi has a MediaPlayer component from the System tab...
Load a Video/Audio into it and look at its length in MediaPlayer1.Length...
This is the easiest way...

function SecInTime(Sec:Integer):String;
var
 H, M, S: Integer;
 Hs, Ms, Ss: String;
begin
 H := sec div 3600;
 M := (sec - H * 3600) div 60;
 S := sec - H * 3600 - M * 60;

 Hs:=IntToStr(H);
 Ms:=IntToStr(M);
 Ss:=IntToStr(S);

 If (Length(IntToStr(H))=1) Then Hs:='0'+IntToStr(H);
 If (Length(IntToStr(M))=1) Then Ms:='0'+IntToStr(M);
 If (Length(IntToStr(S))=1) Then Ss:='0'+IntToStr(S);

 Result := Hs+':'+Ms+':'+Ss;
end;

procedure TForm1.Button1Click(Sender: TObject);
var str: string;
begin
 MediaPlayer1.FileName := 'C:\Todd Rundgren - Can We Still Be Friends (1978).mp4'; // Присваиваем имя файла ...
 MediaPlayer1.Open; // Открываем плеер ...
 str := IntToStr(MediaPlayer1.Length); // Присваиваем миле секунды в переменную str
 ShowMessage('Sec: '+(str)); // Показываем миле секунды ...
 str:=Copy(str,0,(Length(str)-3)); // Удаляем последние 3 символа из строки (это миле секунды) ...
 ShowMessage('Min: '+SecInTime(StrToInt(str))); // Нормальный показ времени ...
end;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question