22-07-2024, Saat: 17:53
(21-07-2024, Saat: 12:23)mrmarman Adlı Kullanıcıdan Alıntı: Aramaktansa yeniden yazmak daha kolay geldi. Kolları sıvadım size üç tane birbiri ile ilişkili fonksiyon hazırladım.
Dönüşüm fonksiyonlarında FPS değeri girmezseniz (özgürlük için bir varsayılan atadım) varsayılan olarak 25.0 FPS (PAL sistemi) kabul edilir.
type tTimeCode = record H, M, S, F : Integer; end; function StrToTimeCode( aTC : string ): tTimeCode; var LSL : TStringList; begin result := default(tTimeCode); LSL := TStringList.Create; try LSL.Delimiter := ':'; LSL.DelimitedText := aTC; while LSL.Count < 4 do LSL.Add('00'); with result do begin H := StrToInt(LSL[0]); M := StrToInt(LSL[1]); S := StrToInt(LSL[2]); F := StrToInt(LSL[3]); end; finally FreeAndNil(LSL); end; end; function TimeCodeToFrame( aTC: tTimeCode; aFPS: Double = 25.0 ): Double; begin result := 0 + aTC.H*60*60*aFPS + aTC.M*60*aFPS + aTC.S*aFPS + aTC.F; end; function FrameToTimeCode( aFrame: Double; aFPS: Double = 25.0 ): tTimeCode; begin result := Default(tTimeCode); if aFrame > 0 then begin result.H := trunc(aFrame / aFps / 60 / 60 ); aFrame := aFrame - (result.H * 60 * 60 * aFPS); result.M := trunc(aFrame / aFps / 60 ); aFrame := aFrame - (result.M * 60 * aFPS); result.S := trunc(aFrame / aFps ); aFrame := aFrame - (result.S * aFPS); result.F := Round(aFrame); end; end;
Kullanım Örneği için boş bir projede Forma bir tane MEMO ve BUTTON ekleyip aşağıdaki il deneyin
procedure TForm1.BitBtn1Click(Sender: TObject); var LTC_01 : tTimeCode; LTC_02 : tTimeCode; LFr_01 : double; LFr_02 : double; begin LTC_01 := StrToTimeCode('01:00:00:14'); LTC_02 := StrToTimeCode('02:00:00:13'); LFr_01 := TimeCodeToFrame(LTC_01); LFr_02 := TimeCodeToFrame(LTC_02); With LTC_01 do Memo1.Lines.Add( 'IN.: ' + format('%.2d:%.2d:%.2d:%.2d', [H,M,S,F]) ); Memo1.Lines.Add( 'IN. Frame(s): ' + format('%0.2f', [ LFr_01 ]) ); With LTC_02 do Memo1.Lines.Add( 'OUT: ' + format('%.2d:%.2d:%.2d:%.2d', [H,M,S,F]) ); Memo1.Lines.Add( 'OUT Frame(s): ' + format('%0.2f', [ LFr_02 ]) ); With FrameToTimeCode(LFr_02 - LFr_01) do Memo1.Lines.Add( 'Duration : ' + format('%.2d:%.2d:%.2d:%.2d', [H,M,S,F]) ); Memo1.Lines.Add( 'Duration Frame(s): ' + format('%0.2f', [ LFr_02 - LFr_01 ] ) ); end;
Sonuç şu değerler ile oluşacaktır :
Kod: (Select All)
IN.: 01:00:00:14
IN. Frame(s): 90014,00
OUT: 02:00:00:13
OUT Frame(s): 180013,00
Duration : 00:59:59:24
Duration Frame(s): 89999,00
Çok, çok teşekkür ederim saygılarımla @mrmarman

