View Full Version : timecode to frames - em I wrong ?!?
Amnon82
22nd April 2006, 22:29
hmm. I don't get the frames right. Maybe I missed something ...
Formula I used:
frames=ff + framesPerSecond*( ss + 60*( mm + 60*h))
example:
0:03:15.20 is in frames with my formula 4895 using 25.000 as framesPerSecond
ChapterXtractor reported me 4880 using 25000 as FPS Rate, so what is wrong?
procedure TForm1.DisplayChapters;
var
j,framesPerSecond: integer;
hh,mm,ss,ff,fra,s:string;
begin
Form1.Memo3.Clear;
with IFOArray[Form1.TreeView1.Selected.Parent.Index] do
with VTS_VOBS.VideoStream do
for j:=0 to VTS_PGCI.ProgramChainArray[Form1.TreeView1.Selected.Index].NumberOfPGC-1 do
begin
if Form1.Durations.Checked then Form1.Memo3.Lines.Add(Format('Chapter %d [%s]', [j+1, VTS_PGCI.ProgramChainArray[Form1.TreeView1.Selected.Index].PGCPlaybackTime[j]]));
if Form1.Offsets.Checked then Form1.Memo3.Lines.Add(Format('Chapter %d [%s]', [j+1, VTS_PGCI.ProgramChainArray[Form1.TreeView1.Selected.Index].PGCStartTime[j]]));
if Form1.frames.Checked then
begin
framesPerSecond:=strtoint(fpsec.text);
s:=VTS_PGCI.ProgramChainArray[Form1.TreeView1.Selected.Index].PGCStartTime[j];
HH:=Copy(s, 1, pos(':',s)-1);
Delete(s, 1, Pos(':', s));
MM:=Copy(s, 1, pos(':',s)-1);
Delete(s, 1, Pos(':', s));
SS:=Copy(s, 1, pos('.',s)-1);
Delete(s, 1, Pos('.', s));
FF:=Copy(s, Pos('.', s) + 1, Length(s)-1);
FRA:=floattostr(strtoint(ff) + framesPerSecond*( strtoint(ss) + 60*( strtoint(mm) + 60*strtoint(hh))));
Form1.Memo3.Lines.Add(Format('Chapter %d [%s]', [j+1, fra]));
end;
end;
end;
IFOParser (frames added) - based on Kurtnoise13 release (http://home.arcor.de/autoq2_amsoft/files/IFOParser_frames_v1.zip)
Zeul
22nd April 2006, 22:48
here is what i am using:
Function FramesToTime(cFrames As Long, Optional FrameRate As Double, Optional Resolution As String) As String
Dim tFrames As Long
Dim iHour As Integer
Dim iMin As Integer
Dim iSec As Integer
Dim iHourStr As String
Dim iMinStr As String
Dim iSecStr As String
Dim iFramesStr As String
Dim FP As Double
If FrameRate = 0 Then
If Resolution = "" Then
If pRate = 3003 Or ProjectType = "NTSC" Then
FP = 30
Else
FP = 25
End If
Else
If LCase(Resolution) = "ntsc" Then
FP = 30
Else
FP = 25
End If
End If
Else
FP = FrameRate
End If
tFrames = cFrames
iHour = Int(tFrames / (3600# * FP))
tFrames = tFrames - (iHour * 3600# * FP)
iMin = Int(tFrames / (60# * FP))
tFrames = tFrames - (iMin * 60# * FP)
iSec = Int(tFrames / FP)
tFrames = tFrames - (iSec * FP)
iHourStr = iHour
iMinStr = iMin
iSecStr = iSec
iFramesStr = tFrames
If Len(iHourStr) = 1 Then iHourStr = "0" & iHourStr
If Len(iMinStr) = 1 Then iMinStr = "0" & iMinStr
If Len(iSecStr) = 1 Then iSecStr = "0" & iSecStr
If Len(iFramesStr) = 1 Then iFramesStr = "0" & iFramesStr
FramesToTime = iHourStr & ":" & iMinStr & ":" & iSecStr & ":" & iFramesStr
End Function
Function TimeToFrames(cTime As String, Optional p As String) As Long
Dim t() As String
Dim FP As Double, cFrames As Long
On Error GoTo errH
If cTime = "" Then
TimeToFrames = 0
Exit Function
End If
If p = "" Then
If pRate = 3003 Then
FP = 30
Else
FP = 25
End If
Else
If LCase(p) = "pal" Then
FP = 25
Else
FP = 30
End If
End If
cTime = Replace(cTime, ";", ":")
t = Split(cTime, ":")
cFrames = (t(0) * FP * 3600) + (t(1) * FP * 60) + (t(2) * FP) + t(3)
TimeToFrames = cFrames
errH:
End Function
Your calcs are correct - chapterxtractor is wrong. If you are doing NTSC either choose 30fps or 29.97fps and account for dropframe. For 23.976 you need to account for pulldown also when setting the chapter points for cce.
Amnon82
23rd April 2006, 14:24
IFOParser v1 by Offset:
Chapter 1 [0:00:00.000]
Chapter 2 [0:06:51.840]
Chapter 3 [0:11:48.200]
Chapter 4 [0:22:21.680]
Chapter 5 [0:27:50.960]
Chapter 6 [0:35:14.960]
Chapter 7 [0:41:50.960]
Chapter 8 [0:47:05.160]
Chapter 9 [0:51:21.480]
Chapter 10 [0:55:07.560]
Chapter 11 [1:08:17.720]
Chapter 12 [1:15:33.960]
Chapter 13 [1:23:54.000]
Chapter 14 [1:26:21.680]
Chapter 15 [1:32:34.640]
Chapter 16 [1:39:41.720]
Chapter 17 [1:45:14.360]
Chapter 18 [1:52:03.440]
Chapter 19 [1:59:39.600]
DVDDecrypter for Scenarist
00:00:00;00
00:06:51;21
00:11:48;05
00:22:21;17
00:27:50;24
00:35:14;24
00:41:50;24
00:47:05;04
00:51:21;12
00:55:07;14
01:08:17;18
01:15:33;24
01:23:54;00
01:26:21;17
01:32:34;16
01:39:41;18
01:45:14;09
01:52:03;11
01:59:39;15
DVDDecrypter for IFOEdit
10296
17705
33542
41774
52874
62774
70629
77037
82689
102443
113349
125850
129542
138866
149543
157859
168086
179490
ChapterXtractor by frames (25000)
0
10296
17705
33542
41774
52874
62774
70629
77037
82689
102443
113349
125850
129542
138866
149543
157859
168086
IFOParser v1 by frames (fps 25.000)
* timecode of IFOPraser by Offset without last 0 was used ...
Chapter 1 [0]
Chapter 2 [10359]
Chapter 3 [17720]
Chapter 4 [33593]
Chapter 5 [41846]
Chapter 6 [52946]
Chapter 7 [62846]
Chapter 8 [70641]
Chapter 9 [77073]
Chapter 10 [82731]
Chapter 11 [102497]
Chapter 12 [113421]
Chapter 13 [125850]
Chapter 14 [129593]
Chapter 15 [138914]
Chapter 16 [149597]
Chapter 17 [157886]
Chapter 18 [168119]
Chapter 19 [179535]
IFOParser v1 by frames using Zeulformula (fps 25.000)
* timecode of IFOPraser by Offset without last 0 was used ...
* FRA:=floattostr((strtoint(HH) * framesPerSecond * 3600) + (strtoint(MM) * framesPerSecond * 60) + (strtoint(SS) * framesPerSecond) + strtoint(FF));
Chapter 1 [0]
Chapter 2 [10359]
Chapter 3 [17720]
Chapter 4 [33593]
Chapter 5 [41846]
Chapter 6 [52946]
Chapter 7 [62846]
Chapter 8 [70641]
Chapter 9 [77073]
Chapter 10 [82731]
Chapter 11 [102497]
Chapter 12 [113421]
Chapter 13 [125850]
Chapter 14 [129593]
Chapter 15 [138914]
Chapter 16 [149597]
Chapter 17 [157886]
Chapter 18 [168119]
Chapter 19 [179535]
IFOParser v2 by frames (fps 25.000)
* Using HH:MM:SS.FFF timecode with FFF/40
FF:=floattostr(strtoint(Copy(s, Pos('.', s) + 1, Length(s)))/40);
FF:=StringReplace(FF, '.', '', [rfReplaceAll]);
FF:=StringReplace(FF, ',', '', [rfReplaceAll]);
FRA:=floattostr(strtoint(ff) + framesPerSecond*( strtoint(ss) + 60*( strtoint(mm) + 60*strtoint(hh))));
Chapter 1 [0]
Chapter 2 [10296]
Chapter 3 [17705]
Chapter 4 [33542]
Chapter 5 [41774]
Chapter 6 [52874]
Chapter 7 [62774]
Chapter 8 [70629]
Chapter 9 [77037]
Chapter 10 [82689]
Chapter 11 [102443]
Chapter 12 [113349]
Chapter 13 [125850]
Chapter 14 [129542]
Chapter 15 [138866]
Chapter 16 [149543]
Chapter 17 [157859]
Chapter 18 [168086]
Chapter 19 [179490]
Hmm, FFF/40 is the right way. Is it 40 also in other framerates?
IfoParser for Delphi thread (http://forum.doom9.org/showthread.php?t=110226)
Amnon82
24th April 2006, 10:37
Here my final code:
{==== Frames to Time ===============================================}
function FramesToTime(s:String):string;
var iHour,iMin,iSec,tFrames:real;
iHourStr,iMinStr,iSecStr,iFramesStr:string;
FP:real;
begin
FP := strtofloat(form1.rate.text);
if FP=0 then exit;
tFrames := strtofloat(s);
iHour := int(tFrames / (3600 * FP));
tFrames := tFrames - (iHour * 3600 * FP);
iMin := int(tFrames / (60 * FP));
tFrames := tFrames - (iMin * 60 * FP);
iSec := int(tFrames / FP);
tFrames := tFrames - (iSec * FP);
iHourStr := floattostr(iHour);
iMinStr := floattostr(iMin);
iSecStr := floattostr(iSec);
iFramesStr := floattostr(round(tFrames));
If strtofloat(iHourstr) < 10 Then iHourstr:='0' + ihourstr;
If strtofloat(iMinstr) < 10 Then iminstr:='0' + iminstr;
If strtofloat(iSecstr) < 10 Then isecstr:='0' + isecstr;
If strtofloat(iFramesstr) < 10 Then iframesstr:='0' + iframesstr;
result := iHourStr +':'+ iMinStr +':'+ iSecStr +':'+ iFramesStr;
end;
{===================================================================}
{=== Time to Frames ================================================}
function TimeToFrames(s:String):string;
var HH,MM,SS,FF:string;
FP :real;
begin
FP := strtofloat(form1.rate.text);
if FP=0 then exit;
HH:=Copy(s, 1, pos(':',s)-1);
Delete(s, 1, Pos(':', s));
MM:=Copy(s, 1, pos(':',s)-1);
Delete(s, 1, Pos(':', s));
SS:=Copy(s, 1, pos('.',s)-1);
Delete(s, 1, Pos('.', s));
FF:=Copy(s, Pos('.', s) + 1, Length(s));
if strtofloat(FF) > 99 then
begin
FF:=floattostr(strtofloat(Copy(s, Pos('.', s) + 1, Length(s)))/40);
FF:=StringReplace(FF, '.', '', [rfReplaceAll]);
FF:=StringReplace(FF, ',', '', [rfReplaceAll]);
end;
result:=floattostr(round(strtofloat(ff) + FP*( strtofloat(ss) + 60*( strtofloat(mm) + 60*strtofloat(hh)))));
end;
{===================================================================}
You can use this code with IfoParser for Delphi (http://forum.doom9.org/showthread.php?t=110226)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.