• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Timecode Calculator

  • Автор темы Автор темы Sascha
  • Дата начала Дата начала

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,551
Баллы
155
Помогите с кодом я уже запутался ничего не получается, на видео Excel таблица всё работает перевёл в делфи и ничего не

сама функция кода написанная на Visual Basic
[HIDE]
Код:
Attribute VB_Name = "rgrTimeCodeTools"
Option Explicit

Function TC2F(TCtxt As String, Optional fps As Double = 24, Optional dropFrameTC As Boolean = False) As Long
    ' **********
    '   Convert a time code into a frame number.
    ' **********
  
    Dim hh As Long
    Dim mm As Long
    Dim ss As Long
    Dim ff As Long
      
    ' ***********
    '   Basic check if the time code is valid. If necessary convert number to valid time code.
    ' ***********
    If TCCheck(TCtxt) = "OK" Then
        If Len(TCtxt) <= 8 Then
            TCtxt = TC2FConversion(TCtxt)
        End If
    End If
  
    ' extracting values from string
    hh = Mid(TCtxt, 1, 2)
    mm = Mid(TCtxt, 4, 2)
    ss = Mid(TCtxt, 7, 2)
    ff = Mid(TCtxt, 10, 2)
  
  
    If TCCheckValue(hh, mm, ss, ff, fps, dropFrameTC, TCtxt) = "OK" Then
        If dropFrameTC = False Then
            ' calculating the frame number based on NONE drop frame time code
          
            Dim rFps As Long
            rFps = Round(fps)           ' round frame rate in case of 23,976 - 29,97 - 59,94 non drop frame time code
          
            ss = Int(ss * rFps)
            mm = Int(mm * rFps * 60)
            hh = Int(hh * rFps * 60 * 60)
            TC2F = ff + ss + mm + hh
        Else
            ' calculating the frame number based on drop frame time code
            If fps = 29.97 Or fps = 59.94 And dropFrameTC = True Then
                    TC2F = TC2dF(hh, mm, ss, ff, fps)
                Else
                    MsgBox "Sorry, only 29.97 or 59.94 fps are valid with drop frame time codes!", 16, Replace(ActiveCell.Address, "$", "")
                    Exit Function
            End If
        End If
    End If
  
End Function

Function F2TC(FNum As Long, Optional fps As Double = 24, Optional dropFrameTC As Boolean = False) As String
    ' **********
    '   Convert frame number to time code.
    ' **********

    Dim hh As Long
    Dim mm As Long
    Dim ss As Long
    Dim ff As Long
  
    ' generate time code format
    If dropFrameTC = False Then
            ff = FNum Mod fps
            ss = (FNum \ fps) Mod 60
            mm = ((FNum \ fps) \ 60) Mod 60
            hh = ((FNum \ fps) \ 60) \ 60
          
            ' check if the time code values are valid
            If TCCheckValue(hh, mm, ss, ff, fps, dropFrameTC, Str(FNum)) = "OK" Then
                    F2TC = Format(mm, "00") & ":" & Format(ss, "00")
      
                Else
                    Exit Function
            End If
          
        Else
            ' calculating the frame number based on drop frame time code
            If fps = 29.97 Or fps = 59.94 And dropFrameTC = True Then
                    F2TC = dF2TC(FNum, fps)
                Else
                    MsgBox "Only 29.97 or 59.94 fps are valid with drop frame time codes!", 16, Replace(ActiveCell.Address, "$", "")
                    Exit Function
        End If
    End If
  
End Function

Function FDur(TCtxtStart As String, TCtxtEnd As String, Optional fps As Double = 24, Optional dropFrameTC As Boolean = False) As Long
    ' **********
    '   Calculating frames duration from two time code values
    ' **********
              
    Dim inTC As Long        ' IN point of clip/time code
    Dim outTC As Long       ' OUT point of clip/time code
  
    inTC = TC2F(TCtxtStart, fps, dropFrameTC)
    outTC = TC2F(TCtxtEnd, fps, dropFrameTC)
  
    If inTC = 0 Or outTC = 0 Then
            Exit Function
        Else
            FDur = Abs(inTC - outTC)   ' FDur = (Abs(TC2F(TCtxtStart, fps, dropFrameTC) - TC2F(TCtxtEnd, fps, dropFrameTC))) - 1
    End If
  
End Function

Private Function TCCheckValue(hh As Long, mm As Long, ss As Long, ff As Long, fps As Double, Optional dropFrameTC As Boolean, Optional ErrTitle As String) As String
    ' **********
    '   Check values of the time code.
    ' **********

    TCCheckValue = "OK"
  
    ' check hours not higher than 23
    If hh > 23 Then
        MsgBox "Hour value (" & hh & ") higher than 23!", 16, Replace(ActiveCell.Address, "$", "") & ": " & ErrTitle
        TCCheckValue = "Error"
        Exit Function
    End If
  
    ' check minutes not higher than 59
    If mm > 59 Then
        MsgBox "Minutes value (" & mm & ") higher than 59!", 16, Replace(ActiveCell.Address, "$", "") & ": " & ErrTitle
        TCCheckValue = "Error"
        Exit Function
    End If
  
    ' check seconds not higher than 59
    If ss > 59 Then
        MsgBox "Seconds value (" & ss & ") higher than 59!", 16, Replace(ActiveCell.Address, "$", "") & ": " & ErrTitle
        TCCheckValue = "Error"
        Exit Function
    End If
  
    ' check frames not higher than frames per second
    If ff >= Round(fps) Then
        MsgBox "Frame value (" & ff & ") equal or higher than frames per second (" & fps & ")!", 16, Replace(ActiveCell.Address, "$", "") & ": " & ErrTitle
        TCCheckValue = "Error"
        Exit Function
    End If
  
    ' check drop frame rate values
    If dropFrameTC = True Then
        If fps = 29.97 Then
            If (mm = 10 Or mm = 20 Or mm = 30 Or mm = 40 Or mm = 50 Or mm = 0) And ss = 0 Then
                    ' do nothing yet
                ElseIf ff < 2 And ss = 0 Then
                    MsgBox "This time code value (" & ErrTitle & ") is not valid in combination with a drop frame timecode!", 16, Replace(ActiveCell.Address, "$", "") & ": " & ErrTitle
                    TCCheckValue = "Error"
                    Exit Function
            End If
        End If
        If fps = 59.94 Then
            If (mm = 10 Or mm = 20 Or mm = 30 Or mm = 40 Or mm = 50 Or mm = 0) And ss = 0 Then
                    ' do nothing yet
                ElseIf ff < 4 And ss = 0 Then
                    MsgBox "This time code value (" & ErrTitle & ") is not valid in combination with a drop frame timecode (" & fps & ")!", 16, Replace(ActiveCell.Address, "$", "") & ": " & ErrTitle
                    TCCheckValue = "Error"
                    Exit Function
            End If
        End If
    End If

End Function

Private Function TCCheck(TCtxt As String, Optional ErrTitle As String) As String
    ' **********
    '   Basic check if length of time code is correct.
    '   (less than 8 or 11 characters)
    ' **********
      
    ErrTitle = TCtxt
  
    If Len(TCtxt) > 11 Then                                 ' time code longer than 11 characters
            MsgBox "Timecode has to many characters.", 16, ErrTitle
            TCCheck = "Error"
            Exit Function
        ElseIf Len(TCtxt) > 8 And Len(TCtxt) < 11 Then      'time code has 9 to 10 characters
            MsgBox "Expected format 00:00:00:00 or up to 8 numbers!", 16, ErrTitle
            TCCheck = "Error"
            Exit Function
    End If
  
    TCCheck = "OK"

End Function

Private Function TC2FConversion(TCFormat As String) As String
    ' *********
    '   using a number as a timecode and convert it to a string
    ' *********
      
    Dim txtLen As String
    Dim tempTC As String
  
    ' *********
    '   figure out how many leading Nulls are missing
    ' *********
    txtLen = Len(TCFormat)
  
    If txtLen < 8 Then
        Dim i As Integer
        ' adding necessary Nulls
        i = 1
        Do
            Dim heading As String
            heading = heading + "0"
            i = i + 1
        Loop Until i = 9 - txtLen       ' 8 numbers for a timecode (+1 for proper calculation)
        TCFormat = heading + TCFormat   ' adding needed Nulls to the beginning of the timecode string
    End If
  
    TC2FConversion = Mid(TCFormat, 1, 2) & ":" & Mid(TCFormat, 3, 2) & ":" & Mid(TCFormat, 5, 2) & ":" & Mid(TCFormat, 7, 2) ' adding ":" between numbers
  
End Function

Private Function TC2dF(hh As Long, mm As Long, ss As Long, ff As Long, fps As Double) As Long
    ' *********
    '   proper drop frame time code conversion (time code to frame number)
    '   calculations based on http://www.andrewduncan.ws/Timecodes/Timecodes.html
    ' *********
  
    Dim fDrop As Long       ' value for frame numbers to be dropped
    Dim rFps As Long        ' fps rounded
  
    Dim Fph As Long         ' number of frames per hour
    Dim Fpm As Long         ' number of frames per minute
    Dim totalM As Long      ' total number minutes
  
    fDrop = Round(fps * 0.06666666) ' 6 % of rounded frame rate resutls in numbers of frames to be dopped (29,97 = 2 frames; 59,94 = 4 frames)
    rFps = Round(fps)               ' rounded fps
  
    Fph = (rFps * 60) * 60
    Fpm = rFps * 60
    totalM = (60 * hh) + mm
  
    TC2dF = ((Fph * hh) + (Fpm * mm) + (rFps * ss) + ff) - (fDrop * (totalM - (totalM \ 10)))
  
End Function

Private Function dF2TC(FNum As Long, Optional fps As Double) As String
    ' *********
    '   proper drop frame time code conversion (frame number to time code)
    '   calculations based on http://www.andrewduncan.ws/Timecodes/Timecodes.html
    ' *********
      
    Dim hh As Long          ' hours value
    Dim mm As Long          ' minutes value
    Dim ss As Long          ' seconds value
    Dim ff As Long          ' frames value
  
    Dim intD As Long        ' integer result of a division
    Dim remD As Long        ' remainder of a division
    Dim fDrop As Long       ' number of frames to drop every minutes
    Dim rFps As Long        ' rounded frame rate
  
    Dim Fph As Long         ' number of frames per hour
    Dim Fp24h As Long       ' number of frames in a day
    Dim Fp10m As Long       ' number of frames per ten minute
    Dim Fpm As Long         ' number of frames per minute
  
    fDrop = Round(fps * 0.06666666) ' 29,97 = 2 frames; 59,94 = 4 frames (6 % of rounded frame rate)
    rFps = Round(fps)               ' rounded fps
  
    Fph = (rFps * 60) * 60      ' frames per hour
    Fp24h = Fph * 24            ' frames per 24 hours
    Fp10m = (fps * 60) * 10     ' frames per 10 minutes (rounded fps would result in a wrong value)
    Fpm = (rFps * 60) - fDrop   ' frames per minute
      
    If FNum < 0 Then            ' turn negative frame value in positive
        FNum = Fp24h + FNum
    End If
    FNum = FNum Mod Fp24h       ' 24 h turn over
  
    intD = FNum \ Fp10m         ' store integer result of a division for further calculations
    remD = FNum Mod Fp10m       ' store remainder of a division for further calculations
  
    If remD > fDrop Then        ' calculating final frame number
            FNum = FNum + (fDrop * 9 * intD) + fDrop * ((remD - fDrop) \ Fpm)
        Else
            FNum = FNum + (fDrop * 9 * intD)
    End If

    ' calculate time code values
    ff = FNum Mod rFps
    ss = (FNum \ rFps) Mod 60
    mm = ((FNum \ rFps) \ 60) Mod 60
    hh = (((FNum \ rFps) \ 60) \ 60) Mod 24
  
    ' check if time code values are valid
    If TCCheckValue(hh, mm, ss, ff, fps, 1, Str(FNum)) = "OK" Then
            dF2TC = Format(hh, "00") & ":" & Format(mm, "00") & ":" & Format(ss, "00") & ":" & Format(ff, "00")
        Else
            End
    End If
  
End Function
[/HIDE]
вот что получается

Capture.PNG

на делфи код
[HIDE]
Код:
unit rgrTimeCodeTools;

interface

uses  Windows;





function TC2F(var TCtxt: String; fps: Double=24; dropFrameTC: Boolean=false): Longint;
function F2TC(FNum: Longint; fps: Double=24; dropFrameTC: Boolean=false): String;
function FDur(TCtxtStart: String; TCtxtEnd: String; fps: Double=24; dropFrameTC: Boolean=false): Longint;

implementation

uses  Forms, SysUtils, Math, VBto_Converter;

//==============================================================

function TC2F(var TCtxt: String; fps: Double; dropFrameTC: Boolean): Longint;
var
    hh, mm, ss, ff, rFps: Longint;
begin
//{$DEFINE def_TC2F}
{$IF Defined(def_TC2F)}
    // **********
    // Convert a time code into a frame number.
    // **********

    // ***********
    // Basic check if the time code is valid. If necessary convert number to valid time code.
    // ***********
    if TCCheck(TCtxt)='OK' then begin
        if Length(TCtxt)<=8 then begin
            TCtxt := TC2FConversion(TCtxt);
        end;
    end;

    // extracting values from string
    hh := Round(StrToFloat(Copy(TCtxt, 1, 2)));
    mm := Round(StrToFloat(Copy(TCtxt, 4, 2)));
    ss := Round(StrToFloat(Copy(TCtxt, 7, 2)));
    ff := Round(StrToFloat(Copy(TCtxt, 10, 2)));


    if TCCheckValue(hh, mm, ss, ff, fps, dropFrameTC, TCtxt)='OK' then begin
        if dropFrameTC=false then begin
            // calculating the frame number based on NONE drop frame time code

            rFps := CLng(fps); // round frame rate in case of 23,976 - 29,97 - 59,94 non drop frame time code

            ss := Floor(ss*rFps);
            mm := Floor(mm*rFps*60);
            hh := Floor(hh*rFps*60*60);
            Result := ff+ss+mm+hh;
        end  else  begin
            // calculating the frame number based on drop frame time code
            if fps=29.97 or fps=59.94 and dropFrameTC=true then begin
                Result := TC2dF(hh, mm, ss, ff, fps);
            end  else  begin
                Application.MessageBox('Sorry, only 29.97 or 59.94 fps are valid with drop frame time codes!', PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll, rfIgnoreCase])), MB_ICONSTOP);
                Exit;
            end;
        end;
    end;

{$IFEND} // def_TC2F
end;

function F2TC(FNum: Longint; fps: Double; dropFrameTC: Boolean): String;
var
    hh, mm, ss, ff: Longint;
begin
//{$DEFINE def_F2TC}
{$IF Defined(def_F2TC)}
    // **********
    // Convert frame number to time code.
    // **********

    // generate time code format
    if dropFrameTC=false then begin
        ff := Round(FNum mod Floor( fps));
        ss := Round(Floor((FNum div Floor( fps))) mod  60);
        mm := Round(Floor((Floor((FNum div Floor( fps))) div  60)) mod 60);
        hh := Round(Floor((Floor((FNum div Floor( fps))) div  60)) div 60);

        // check if the time code values are valid
        if TCCheckValue(hh, mm, ss, ff, fps, dropFrameTC, mStr(FNum))='OK' then begin
            Result := FormatVB(mm,'00')+':'+FormatVB(ss,'00');

        end  else  begin
            Exit;
        end;

    end  else  begin
        // calculating the frame number based on drop frame time code
        if fps=29.97 or fps=59.94 and dropFrameTC=true then begin
            Result := dF2TC(FNum, fps);
        end  else  begin
            Application.MessageBox('Only 29.97 or 59.94 fps are valid with drop frame time codes!', PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll, rfIgnoreCase])), MB_ICONSTOP);
            Exit;
        end;
    end;

{$IFEND} // def_F2TC
end;

function FDur(TCtxtStart: String; TCtxtEnd: String; fps: Double; dropFrameTC: Boolean): Longint;
var
    inTC, outTC: Longint;
begin
//{$DEFINE def_FDur}
{$IF Defined(def_FDur)}
    // **********
    // Calculating frames duration from two time code values
    // **********

    // IN point of clip/time code
    // OUT point of clip/time code

    inTC := TC2F(TCtxtStart, fps, dropFrameTC);
    outTC := TC2F(TCtxtEnd, fps, dropFrameTC);

    if inTC=0 or outTC=0 then begin
        Exit;
    end  else  begin
        Result := Abs(inTC-outTC); // FDur = (Abs(TC2F(TCtxtStart, fps, dropFrameTC) - TC2F(TCtxtEnd, fps, dropFrameTC))) - 1
    end;

{$IFEND} // def_FDur
end;

// VBto upgrade warning: dropFrameTC As Boolean    OnWrite(Boolean, Smallint)
function TCCheckValue(hh: Longint; mm: Longint; ss: Longint; ff: Longint; fps: Double; dropFrameTC: Boolean; ErrTitle: String): String;
begin
//{$DEFINE def_TCCheckValue}
{$IF Defined(def_TCCheckValue)}
    // **********
    // Check values of the time code.
    // **********

    Result := 'OK';

    // check hours not higher than 23
    if hh>23 then begin
        Application.MessageBox(PCHAR('Hour value ('+IntToStr(hh)+') higher than 23!'), PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll, rfIgnoreCase])+': '+ErrTitle), MB_ICONSTOP);
        Result := 'Error';
        Exit;
    end;

    // check minutes not higher than 59
    if mm>59 then begin
        Application.MessageBox(PCHAR('Minutes value ('+IntToStr(mm)+') higher than 59!'), PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll, rfIgnoreCase])+': '+ErrTitle), MB_ICONSTOP);
        Result := 'Error';
        Exit;
    end;

    // check seconds not higher than 59
    if ss>59 then begin
        Application.MessageBox(PCHAR('Seconds value ('+IntToStr(ss)+') higher than 59!'), PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll, rfIgnoreCase])+': '+ErrTitle), MB_ICONSTOP);
        Result := 'Error';
        Exit;
    end;

    // check frames not higher than frames per second
    if ff>=CLng(fps) then begin
        Application.MessageBox(PCHAR('Frame value ('+IntToStr(ff)+') equal or higher than frames per second ('+FloatToStr(fps)+')!'), PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll, rfIgnoreCase])+': '+ErrTitle), MB_ICONSTOP);
        Result := 'Error';
        Exit;
    end;

    // check drop frame rate values
    if dropFrameTC=true then begin
        if fps=29.97 then begin
            if (mm=10 or mm=20 or mm=30 or mm=40 or mm=50 or mm=0) and ss=0 then begin
                // do nothing yet
            end else if ff<2 and ss=0 then begin
                Application.MessageBox(PCHAR('This time code value ('+ErrTitle+') is not valid in combination with a drop frame timecode!'), PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll, rfIgnoreCase])+': '+ErrTitle), MB_ICONSTOP);
                Result := 'Error';
                Exit;
            end;
        end;
        if fps=59.94 then begin
            if (mm=10 or mm=20 or mm=30 or mm=40 or mm=50 or mm=0) and ss=0 then begin
                // do nothing yet
            end else if ff<4 and ss=0 then begin
                Application.MessageBox(PCHAR('This time code value ('+ErrTitle+') is not valid in combination with a drop frame timecode ('+FloatToStr(fps)+')!'), PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll, rfIgnoreCase])+': '+ErrTitle), MB_ICONSTOP);
                Result := 'Error';
                Exit;
            end;
        end;
    end;

{$IFEND} // def_TCCheckValue
end;

function TCCheck(TCtxt: String; var ErrTitle: String): String;
begin
//{$DEFINE def_TCCheck}
{$IF Defined(def_TCCheck)}
    // **********
    // Basic check if length of time code is correct.
    // (less than 8 or 11 characters)
    // **********

    ErrTitle := TCtxt;

    if Length(TCtxt)>11 then begin // time code longer than 11 characters
        Application.MessageBox('Timecode has to many characters.', PCHAR(ErrTitle), MB_ICONSTOP);
        Result := 'Error';
        Exit;
    end else if Length(TCtxt)>8 and Length(TCtxt)<11 then begin        // time code has 9 to 10 characters
        Application.MessageBox('Expected format 00:00:00:00 or up to 8 numbers!', PCHAR(ErrTitle), MB_ICONSTOP);
        Result := 'Error';
        Exit;
    end;

    Result := 'OK';

{$IFEND} // def_TCCheck
end;

function TC2FConversion(var TCFormat: String): String;
var
    txtLen, tempTC, heading: String;
    i: Smallint;
begin
//{$DEFINE def_TC2FConversion}
{$IF Defined(def_TC2FConversion)}
    // *********
    // using a number as a timecode and convert it to a string
    // *********

    // *********
    // figure out how many leading Nulls are missing
    // *********
    txtLen := IntToStr(Length(TCFormat));

    if txtLen<8 then begin
        // adding necessary Nulls
        i := 1;
        repeat
            heading := heading+'0';
            i := i+1;
        until i=9-txtLen; // 8 numbers for a timecode (+1 for proper calculation)
        TCFormat := String(heading)+TCFormat; // adding needed Nulls to the beginning of the timecode string
    end;

    Result := Copy(TCFormat, 1, 2)+':'+Copy(TCFormat, 3, 2)+':'+Copy(TCFormat, 5, 2)+':'+Copy(TCFormat, 7, 2); // adding ":" between numbers

{$IFEND} // def_TC2FConversion
end;

function TC2dF(hh: Longint; mm: Longint; ss: Longint; ff: Longint; fps: Double): Longint;
var
    fDrop, rFps, Fph, Fpm, totalM: Longint;
begin
//{$DEFINE def_TC2dF}
{$IF Defined(def_TC2dF)}
    // *********
    // proper drop frame time code conversion (time code to frame number)
    // calculations based on http://www.andrewduncan.ws/Timecodes/Timecodes.html
    // *********

    // value for frame numbers to be dropped
    // fps rounded

    // number of frames per hour
    // number of frames per minute
    // total number minutes

    fDrop := CLng(fps*0.06666666); // 6 % of rounded frame rate resutls in numbers of frames to be dopped (29,97 = 2 frames; 59,94 = 4 frames)
    rFps := CLng(fps); // rounded fps

    Fph := (rFps*60)*60;
    Fpm := rFps*60;
    totalM := (60*hh)+mm;

    Result := ((Fph*hh)+(Fpm*mm)+(rFps*ss)+ff)-(fDrop*(totalM-(totalM div  10)));

{$IFEND} // def_TC2dF
end;

function dF2TC(var FNum: Longint; fps: Double): String;
var
    hh, mm, ss, ff, intD, remD, fDrop, rFps, Fph, Fp24h, Fp10m, Fpm: Longint;
begin
//{$DEFINE def_dF2TC}
{$IF Defined(def_dF2TC)}
    // *********
    // proper drop frame time code conversion (frame number to time code)
    // calculations based on http://www.andrewduncan.ws/Timecodes/Timecodes.html
    // *********

    // hours value
    // minutes value
    // seconds value
    // frames value

    // integer result of a division
    // remainder of a division
    // number of frames to drop every minutes
    // rounded frame rate

    // number of frames per hour
    // number of frames in a day
    // number of frames per ten minute
    // number of frames per minute

    fDrop := CLng(fps*0.06666666); // 29,97 = 2 frames; 59,94 = 4 frames (6 % of rounded frame rate)
    rFps := CLng(fps); // rounded fps

    Fph := (rFps*60)*60; // frames per hour
    Fp24h := Fph*24; // frames per 24 hours
    Fp10m := Round((fps*60)*10); // frames per 10 minutes (rounded fps would result in a wrong value)
    Fpm := (rFps*60)-fDrop; // frames per minute

    if FNum<0 then begin // turn negative frame value in positive
        FNum := Fp24h+FNum;
    end;
    FNum := FNum mod  Fp24h; // 24 h turn over

    intD := FNum div  Fp10m; // store integer result of a division for further calculations
    remD := FNum mod  Fp10m; // store remainder of a division for further calculations

    if remD>fDrop then begin // calculating final frame number
        FNum := FNum+(fDrop*9*intD)+fDrop*((remD-fDrop) div  Fpm);
    end  else  begin
        FNum := FNum+(fDrop*9*intD);
    end;

    // calculate time code values
    ff := FNum mod  rFps;
    ss := (FNum div  rFps) mod  60;
    mm := ((FNum div  rFps) div  60) mod 60;
    hh := (((FNum div  rFps) div  60) div 60) mod 24;

    // check if time code values are valid
    if TCCheckValue(hh, mm, ss, ff, fps, 0<>(1), mStr(FNum))='OK' then begin
        Result := FormatVB(hh,'00')+':'+FormatVB(mm,'00')+':'+FormatVB(ss,'00')+':'+FormatVB(ff,'00');
    end  else  begin
        Application.Terminate();
    end;

{$IFEND} // def_dF2TC
end;






end.
[/HIDE]

мне нужно написать программу которая считала данные, пример даных что я получаю
Код:
10:01:50:24    10:02:27:10    00:36:11    00:36    GAL074_16_RODEO_JUNIOR_E_GEMSA_A_GIOVANNI_C_PELOUSE.MP3
10:02:27:09    10:02:41:09    00:14:00    00:14    1- 20.HEY YA!-THE BOSSHOSS.MP3
10:02:47:07    10:02:55:24    00:08:17    00:08    JOHNNY CASH - RING OF FIRE.MP3
10:02:55:24    10:02:56:09    00:00:10    00:00    JOHNNY CASH - RING OF FIRE.MP3
10:03:18:10    10:03:27:15    00:09:05    00:09    060 - KID ROCK - ALL SUMMER LONG.MP3
10:03:35:23    10:03:53:11    00:17:13    00:17    GAS BAND - 13 - AN ANGEL WENT UP IN FLAMES+++.MP3
10:03:57:16    10:04:09:16    00:12:00    00:12    3ING-021-08.2_POSSUM-BOOTS_STINGER.MP3
10:04:23:14    10:04:39:02    00:15:13    00:15    80.DO IT (SINGLE MIX)-THE BOSSHOSS.MP3
10:04:44:14    10:04:53:23    00:09:09    00:09    VHP05-14 COYOTE MISCHIEF (MAIN).MP3
10:05:29:19    10:06:50:20    01:21:01    01:21    2-30 SO HOT (MADE FAMOUS BY KID ROCK.M4A
10:07:32:19    10:07:42:23    00:10:04    00:10    ORCHESTRA ENNIO MORRICONE - 02 AS A JUDGEMENT.MP3
10:07:42:23    10:07:52:07    00:09:09    00:09    14-ENNIO_MORRICONE-RABBIA_E_TARANTELLA.MP3
10:08:06:18    10:08:22:08    00:15:15    00:15    098-THE_BOSSHOSS_-_RODEO_RADIO-MINISTRY.MP3
10:08:28:02    10:08:42:11    00:14:09    00:14    04-FC_VENUS-THE_BOSSHOSS-I_SAY_A_LITTLE_PRAYER_CAMPFIRE-MST.MP3
10:08:42:09    10:08:48:15    00:06:06    00:06    27.JETZT (INSTRUMENTAL)-CRO.M4A
10:08:48:15    10:08:58:12    00:09:22    00:09    27.JETZT (INSTRUMENTAL)-CRO.M4A
10:09:24:15    10:09:30:01    00:05:11    00:05    24.HEY GIRL (INSTRUMENTAL)-CRO.M4A
10:09:30:01    10:09:37:18    00:07:17    00:07    24.HEY GIRL (INSTRUMENTAL)-CRO.M4A
10:10:19:02    10:10:32:07    00:13:05    00:13    02_VL063Q_MOONLIGHT_STOMPIN_D_HOLTER_K_WHITE.MP3
10:10:48:08    10:10:56:14    00:08:06    00:08    23 ANNIBALE E I CANTORI MODERNI - TRINITY (TITOLI).MP3
10:10:56:14    10:11:13:07    00:16:18    00:16    23 ANNIBALE E I CANTORI MODERNI - TRINITY (TITOLI).MP3
а где получаются 00:00 автоматом заменяло на 00:01
Помогите пожалуйста решить задачу
 
Можешь кинуть сам код сюда,а то я на работе с телефона нельзя посмотреть
 
Вот архив всё что есть
 

Вложения

  • tc.rar
    tc.rar
    49.5 КБ · Просмотры: 2
Код:
unit rgrTimeCodeTools;

interface

uses Windows;

function TC2F(var TCtxt: String; fps: Double = 24;
  dropFrameTC: Boolean = false): Longint;
function F2TC(FNum: Longint; fps: Double = 24;
  dropFrameTC: Boolean = false): String;
function FDur(TCtxtStart: String; TCtxtEnd: String; fps: Double = 24;
  dropFrameTC: Boolean = false): Longint;

implementation

uses Forms, SysUtils, Math;

// ==============================================================

function TC2F(var TCtxt: String; fps: Double; dropFrameTC: Boolean): Longint;
var
  hh, mm, ss, ff, rFps: Longint;
begin
  // {$DEFINE def_TC2F}
{$IF Defined(def_TC2F)}
  // **********
  // Convert a time code into a frame number.
  // **********

  // ***********
  // Basic check if the time code is valid. If necessary convert number to valid time code.
  // ***********
  if TCCheck(TCtxt) = 'OK' then
  begin
    if Length(TCtxt) <= 8 then
    begin
      TCtxt := TC2FConversion(TCtxt);
    end;
  end;

  // extracting values from string
  hh := Round(StrToFloat(Copy(TCtxt, 1, 2)));
  mm := Round(StrToFloat(Copy(TCtxt, 4, 2)));
  ss := Round(StrToFloat(Copy(TCtxt, 7, 2)));
  ff := Round(StrToFloat(Copy(TCtxt, 10, 2)));

  if TCCheckValue(hh, mm, ss, ff, fps, dropFrameTC, TCtxt) = 'OK' then
  begin
    if dropFrameTC = false then
    begin
      // calculating the frame number based on NONE drop frame time code

      rFps := CLng(fps);
      // round frame rate in case of 23,976 - 29,97 - 59,94 non drop frame time code

      ss := Floor(ss * rFps);
      mm := Floor(mm * rFps * 60);
      hh := Floor(hh * rFps * 60 * 60);
      Result := ff + ss + mm + hh;
    end
    else
    begin
      // calculating the frame number based on drop frame time code
      if fps = 29.97 or fps = 59.94 and dropFrameTC = true then
      begin
        Result := TC2dF(hh, mm, ss, ff, fps);
      end
      else
      begin
        Application.MessageBox
          ('Sorry, only 29.97 or 59.94 fps are valid with drop frame time codes!',
          PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll,
          rfIgnoreCase])), MB_ICONSTOP);
        Exit;
      end;
    end;
  end;

{$IFEND} // def_TC2F
end;

function F2TC(FNum: Longint; fps: Double; dropFrameTC: Boolean): String;
var
  hh, mm, ss, ff: Longint;
begin
  // {$DEFINE def_F2TC}
{$IF Defined(def_F2TC)}
  // **********
  // Convert frame number to time code.
  // **********

  // generate time code format
  if dropFrameTC = false then
  begin
    ff := Round(FNum mod Floor(fps));
    ss := Round(Floor((FNum div Floor(fps))) mod 60);
    mm := Round(Floor((Floor((FNum div Floor(fps))) div 60)) mod 60);
    hh := Round(Floor((Floor((FNum div Floor(fps))) div 60)) div 60);

    // check if the time code values are valid
    if TCCheckValue(hh, mm, ss, ff, fps, dropFrameTC, mStr(FNum)) = 'OK' then
    begin
      Result := FormatVB(mm, '00') + ':' + FormatVB(ss, '00');

    end
    else
    begin
      Exit;
    end;

  end
  else
  begin
    // calculating the frame number based on drop frame time code
    if fps = 29.97 or fps = 59.94 and dropFrameTC = true then
    begin
      Result := dF2TC(FNum, fps);
    end
    else
    begin
      Application.MessageBox
        ('Only 29.97 or 59.94 fps are valid with drop frame time codes!',
        PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll,
        rfIgnoreCase])), MB_ICONSTOP);
      Exit;
    end;
  end;

{$IFEND} // def_F2TC
end;

function FDur(TCtxtStart: String; TCtxtEnd: String; fps: Double;
  dropFrameTC: Boolean): Longint;
var
  inTC, outTC: Longint;
begin
  // {$DEFINE def_FDur}
{$IF Defined(def_FDur)}
  // **********
  // Calculating frames duration from two time code values
  // **********

  // IN point of clip/time code
  // OUT point of clip/time code

  inTC := TC2F(TCtxtStart, fps, dropFrameTC);
  outTC := TC2F(TCtxtEnd, fps, dropFrameTC);

  if inTC = 0 or outTC = 0 then
  begin
    Exit;
  end
  else
  begin
    Result := Abs(inTC - outTC);
    // FDur = (Abs(TC2F(TCtxtStart, fps, dropFrameTC) - TC2F(TCtxtEnd, fps, dropFrameTC))) - 1
  end;

{$IFEND} // def_FDur
end;

// VBto upgrade warning: dropFrameTC As Boolean    OnWrite(Boolean, Smallint)
function TCCheckValue(hh: Longint; mm: Longint; ss: Longint; ff: Longint;
  fps: Double; dropFrameTC: Boolean; ErrTitle: String): String;
begin
  // {$DEFINE def_TCCheckValue}
{$IF Defined(def_TCCheckValue)}
  // **********
  // Check values of the time code.
  // **********

  Result := 'OK';

  // check hours not higher than 23
  if hh > 23 then
  begin
    Application.MessageBox(PCHAR('Hour value (' + IntToStr(hh) +
      ') higher than 23!'), PCHAR(StringReplace(ActiveCell.Address, '$', '',
      [rfReplaceAll, rfIgnoreCase]) + ': ' + ErrTitle), MB_ICONSTOP);
    Result := 'Error';
    Exit;
  end;

  // check minutes not higher than 59
  if mm > 59 then
  begin
    Application.MessageBox(PCHAR('Minutes value (' + IntToStr(mm) +
      ') higher than 59!'), PCHAR(StringReplace(ActiveCell.Address, '$', '',
      [rfReplaceAll, rfIgnoreCase]) + ': ' + ErrTitle), MB_ICONSTOP);
    Result := 'Error';
    Exit;
  end;

  // check seconds not higher than 59
  if ss > 59 then
  begin
    Application.MessageBox(PCHAR('Seconds value (' + IntToStr(ss) +
      ') higher than 59!'), PCHAR(StringReplace(ActiveCell.Address, '$', '',
      [rfReplaceAll, rfIgnoreCase]) + ': ' + ErrTitle), MB_ICONSTOP);
    Result := 'Error';
    Exit;
  end;

  // check frames not higher than frames per second
  if ff >= CLng(fps) then
  begin
    Application.MessageBox(PCHAR('Frame value (' + IntToStr(ff) +
      ') equal or higher than frames per second (' + FloatToStr(fps) + ')!'),
      PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll,
      rfIgnoreCase]) + ': ' + ErrTitle), MB_ICONSTOP);
    Result := 'Error';
    Exit;
  end;

  // check drop frame rate values
  if dropFrameTC = true then
  begin
    if fps = 29.97 then
    begin
      if (mm = 10 or mm = 20 or mm = 30 or mm = 40 or mm = 50 or mm = 0) and
        ss = 0 then
      begin
        // do nothing yet
      end
      else if ff < 2 and ss = 0 then
      begin
        Application.MessageBox(PCHAR('This time code value (' + ErrTitle +
          ') is not valid in combination with a drop frame timecode!'),
          PCHAR(StringReplace(ActiveCell.Address, '$', '', [rfReplaceAll,
          rfIgnoreCase]) + ': ' + ErrTitle), MB_ICONSTOP);
        Result := 'Error';
        Exit;
      end;
    end;
    if fps = 59.94 then
    begin
      if (mm = 10 or mm = 20 or mm = 30 or mm = 40 or mm = 50 or mm = 0) and
        ss = 0 then
      begin
        // do nothing yet
      end
      else if ff < 4 and ss = 0 then
      begin
        Application.MessageBox(PCHAR('This time code value (' + ErrTitle +
          ') is not valid in combination with a drop frame timecode (' +
          FloatToStr(fps) + ')!'), PCHAR(StringReplace(ActiveCell.Address, '$',
          '', [rfReplaceAll, rfIgnoreCase]) + ': ' + ErrTitle), MB_ICONSTOP);
        Result := 'Error';
        Exit;
      end;
    end;
  end;

{$IFEND} // def_TCCheckValue
end;

function TCCheck(TCtxt: String; var ErrTitle: String): String;
begin
  // {$DEFINE def_TCCheck}
{$IF Defined(def_TCCheck)}
  // **********
  // Basic check if length of time code is correct.
  // (less than 8 or 11 characters)
  // **********

  ErrTitle := TCtxt;

  if Length(TCtxt) > 11 then
  begin // time code longer than 11 characters
    Application.MessageBox('Timecode has to many characters.', PCHAR(ErrTitle),
      MB_ICONSTOP);
    Result := 'Error';
    Exit;
  end
  else if Length(TCtxt) > 8 and Length(TCtxt) < 11 then
  begin // time code has 9 to 10 characters
    Application.MessageBox('Expected format 00:00:00:00 or up to 8 numbers!',
      PCHAR(ErrTitle), MB_ICONSTOP);
    Result := 'Error';
    Exit;
  end;

  Result := 'OK';

{$IFEND} // def_TCCheck
end;

function TC2FConversion(var TCFormat: String): String;
var
  txtLen, tempTC, heading: String;
  i: Smallint;
begin
  // {$DEFINE def_TC2FConversion}
{$IF Defined(def_TC2FConversion)}
  // *********
  // using a number as a timecode and convert it to a string
  // *********

  // *********
  // figure out how many leading Nulls are missing
  // *********
  txtLen := IntToStr(Length(TCFormat));

  if txtLen < 8 then
  begin
    // adding necessary Nulls
    i := 1;
    repeat
      heading := heading + '0';
      i := i + 1;
    until i = 9 - txtLen;
    // 8 numbers for a timecode (+1 for proper calculation)
    TCFormat := String(heading) + TCFormat;
    // adding needed Nulls to the beginning of the timecode string
  end;

  Result := Copy(TCFormat, 1, 2) + ':' + Copy(TCFormat, 3, 2) + ':' +
    Copy(TCFormat, 5, 2) + ':' + Copy(TCFormat, 7, 2);
  // adding ":" between numbers

{$IFEND} // def_TC2FConversion
end;

function TC2dF(hh: Longint; mm: Longint; ss: Longint; ff: Longint;
  fps: Double): Longint;
var
  fDrop, rFps, Fph, Fpm, totalM: Longint;
begin
  // {$DEFINE def_TC2dF}
{$IF Defined(def_TC2dF)}
  // *********
  // proper drop frame time code conversion (time code to frame number)
  // calculations based on http://www.andrewduncan.ws/Timecodes/Timecodes.html
  // *********

  // value for frame numbers to be dropped
  // fps rounded

  // number of frames per hour
  // number of frames per minute
  // total number minutes

  fDrop := CLng(fps * 0.06666666);
  // 6 % of rounded frame rate resutls in numbers of frames to be dopped (29,97 = 2 frames; 59,94 = 4 frames)
  rFps := CLng(fps); // rounded fps

  Fph := (rFps * 60) * 60;
  Fpm := rFps * 60;
  totalM := (60 * hh) + mm;

  Result := ((Fph * hh) + (Fpm * mm) + (rFps * ss) + ff) -
    (fDrop * (totalM - (totalM div 10)));

{$IFEND} // def_TC2dF
end;

function dF2TC(var FNum: Longint; fps: Double): String;
var
  hh, mm, ss, ff, intD, remD, fDrop, rFps, Fph, Fp24h, Fp10m, Fpm: Longint;
begin
  // {$DEFINE def_dF2TC}
{$IF Defined(def_dF2TC)}
  // *********
  // proper drop frame time code conversion (frame number to time code)
  // calculations based on http://www.andrewduncan.ws/Timecodes/Timecodes.html
  // *********

  // hours value
  // minutes value
  // seconds value
  // frames value

  // integer result of a division
  // remainder of a division
  // number of frames to drop every minutes
  // rounded frame rate

  // number of frames per hour
  // number of frames in a day
  // number of frames per ten minute
  // number of frames per minute

  fDrop := CLng(fps * 0.06666666);
  // 29,97 = 2 frames; 59,94 = 4 frames (6 % of rounded frame rate)
  rFps := CLng(fps); // rounded fps

  Fph := (rFps * 60) * 60; // frames per hour
  Fp24h := Fph * 24; // frames per 24 hours
  Fp10m := Round((fps * 60) * 10);
  // frames per 10 minutes (rounded fps would result in a wrong value)
  Fpm := (rFps * 60) - fDrop; // frames per minute

  if FNum < 0 then
  begin // turn negative frame value in positive
    FNum := Fp24h + FNum;
  end;
  FNum := FNum mod Fp24h; // 24 h turn over

  intD := FNum div Fp10m;
  // store integer result of a division for further calculations
  remD := FNum mod Fp10m;
  // store remainder of a division for further calculations

  if remD > fDrop then
  begin // calculating final frame number
    FNum := FNum + (fDrop * 9 * intD) + fDrop * ((remD - fDrop) div Fpm);
  end
  else
  begin
    FNum := FNum + (fDrop * 9 * intD);
  end;

  // calculate time code values
  ff := FNum mod rFps;
  ss := (FNum div rFps) mod 60;
  mm := ((FNum div rFps) div 60) mod 60;
  hh := (((FNum div rFps) div 60) div 60) mod 24;

  // check if time code values are valid
  if TCCheckValue(hh, mm, ss, ff, fps, 0 <> (1), mStr(FNum)) = 'OK' then
  begin
    Result := FormatVB(hh, '00') + ':' + FormatVB(mm, '00') + ':' +
      FormatVB(ss, '00') + ':' + FormatVB(ff, '00');
  end
  else
  begin
    Application.Terminate();
  end;

{$IFEND} // def_dF2TC
end;

end.
 
при откритии нужно активировать макрос
Capture.PNG
 
25 Fps восновном, но нужно сделать комбобох где можно будет менять 24; 25;30;29.97 к примеру вот http://www.michaelcinquin.com/tools/timecode_keykode только там водить нужно начало и конец трека а мне нужно из текста
 
я так понял тебе нужно создать таблицу в проекте или открывать по exell,уже все параметры по конвектору есть,просто нужно влипнуть в этот проект и тогда получиться,но у тебя уже один плюс есть это конвектор и и таймер.
 
сейчас всё так и считается а мне нужно чтобы всё было в программе при нажатии копли всё готово записал в файл и всё 1.PNG 2.PNG
 
Вот пробовал что-то не хочет компилироваться
Код:
function TimecodeToFrames(x_: OleVariant): String;
var
    kh_, km_, ks_, kf_, TimecodeToFrame: Double;
begin
//{$DEFINE def_TimecodeToFrames}
{$IF Defined(def_TimecodeToFrames)}
    //
    // x_ is Timecode: 00:00:00:00  (PAL or NTSC)
    {? On Error Resume Next  }

    if Form1.NTSC.Checked=false then begin
        // PAL
        kh_ := Val(LeftStr(x_, 2))*3600*25;
        km_ := Val(Copy(x_, 4, 2))*60*25;
        ks_ := Val(Copy(x_, 7, 2))*25;
        kf_ := Val(Copy(x_, 10, 2));

    end  else  begin
        // NTSC (simple - no dropframe)
        kh_ := Val(LeftStr(x_, 2))*3600*30;
        km_ := Val(Copy(x_, 4, 2))*60*30;
        ks_ := Val(Copy(x_, 7, 2))*30;
        kf_ := Val(Copy(x_, 10, 2));

    end;

    TimecodeToFrame := kh_+km_+ks_+kf_;

{$IFEND} // def_TimecodeToFrames
end;

function FramesToTimecode(var x_: Smallint): Double;
var
    Minus: String;
    sm_, F_, h_, M_, s_: Longint;
begin
//{$DEFINE def_FramesToTimecode}
{$IF Defined(def_FramesToTimecode)}
    //
    // x_  is the frames-value

    if x_<0 then begin
        x_ := x_*-1;
        Minus := '-';
    end  else  begin
        Minus := '';
    end;

    if Form1.NTSC.Checked=false then begin
        // PAL
        sm_ := Floor(x_/25);
        F_ := x_-sm_*25;

        h_ := Floor(sm_/3600);
        M_ := Floor((sm_-h_*3600)/60);
        s_ := Floor(sm_-h_*3600-M_*60);

        Result := StrToFloat(Minus+FormatVB(h_,'00:')+FormatVB(M_,'00:')+FormatVB(s_,'00:')+FormatVB(F_,'00'));

    end  else  begin
        // NTSC
        sm_ := Floor(x_/30);
        F_ := x_-sm_*30;

        h_ := Floor(sm_/3600);
        M_ := Floor((sm_-h_*3600)/60);
        s_ := Floor(sm_-h_*3600-M_*60);

        Result := StrToFloat(Minus+FormatVB(h_,'00:')+FormatVB(M_,'00:')+FormatVB(s_,'00:')+FormatVB(F_,'00'));

    end;

{$IFEND} // def_FramesToTimecode
end;



procedure TForm1.Button2Click(Sender: TObject);
var
    Duration1: Double;
    Duration,InCue,OutCue: String;

begin
InCue:= '10:02:10:12';
OutCue:= '10:05:10:12';
Duration:= (TimecodeToFrames(OutCue)-TimecodeToFrames(InCue));
Duration1:= FramesToTimecode(TimecodeToFrames(OutCue)-TimecodeToFrames(InCue)) ;
Edit3.Text:=Duration1;
end;
 
Вот оригинал на visual basic код:
Hi!
I'm working in a film-subtitle-lab and write all software for it.
What I do is:
all operations are made frame-based. That's an easy way to add and subtract values. After operation frames are turned back into timecode.

To convert timecode to frames use following function:

Code:
Function TimecodeToFrames(x_) as String
'
'x_ is Timecode: 00:00:00:00 (PAL or NTSC)
On Error Resume Next

If Form1.NTSC.Checked = False Then
'PAL
kh_ = Val(Left(x_, 2)) * 3600 * 25
km_ = Val(Mid(x_, 4, 2)) * 60 * 25
ks_ = Val(Mid(x_, 7, 2)) * 25
kf_ = Val(Mid(x_, 10, 2))

Else
'NTSC (simple - no dropframe)
kh_ = Val(Left(x_, 2)) * 3600 * 30
km_ = Val(Mid(x_, 4, 2)) * 60 * 30
ks_ = Val(Mid(x_, 7, 2)) * 30
kf_ = Val(Mid(x_, 10, 2))

End If

TimecodeToFrame = kh_ + km_ + ks_ + kf_

End Function

Convert back frames to timecode after operations:

Code:
Function FramesToTimecode(x_) as Double
'
'x_ is the frames-value

If x_ < 0 Then
x_ = x_ * -1
Minus = "-"
Else
Minus = ""
End If

If Form1.NTSC.Checked = False Then
'PAL
sm_ = Int(x_ / 25)
F_ = x_ - sm_ * 25

h_ = Int(sm_ / 3600)
M_ = Int((sm_ - h_ * 3600) / 60)
s_ = Int(sm_ - h_ * 3600 - M_ * 60)

FramesToTimecode = Minus + Format(h_, "00:") + Format(M_, "00:") + Format(s_, "00:") + Format(F_, "00")

Else
'NTSC
sm_ = Int(x_ / 30)
F_ = x_ - sm_ * 30

h_ = Int(sm_ / 3600)
M_ = Int((sm_ - h_ * 3600) / 60)
s_ = Int(sm_ - h_ * 3600 - M_ * 60)

FramesToTimecode = Minus + Format(h_, "00:") + Format(M_, "00:") + Format(s_, "00:") + Format(F_, "00")

End If

End Function

Example:

Code:
InCue = "10:02:10:12"
OutCue = "10:05:10:12"
'Duration in frames is:
Dim Duration as Double
Duration = TimecodeToFrames(OutCue) - TimecodeToFrames(InCue)

'Duration in TC is:
Dim Duration as String
Duration = FramesToTimecode(TimecodeToFrames(OutCue) - TimecodeToFrames(InCue))
 
Вот пробовал что-то не хочет компилироваться
Код:
function TimecodeToFrames(x_: OleVariant): String;
var
    kh_, km_, ks_, kf_, TimecodeToFrame: Double;
begin
//{$DEFINE def_TimecodeToFrames}
{$IF Defined(def_TimecodeToFrames)}
    //
    // x_ is Timecode: 00:00:00:00  (PAL or NTSC)
    {? On Error Resume Next  }

    if Form1.NTSC.Checked=false then begin
        // PAL
        kh_ := Val(LeftStr(x_, 2))*3600*25;
        km_ := Val(Copy(x_, 4, 2))*60*25;
        ks_ := Val(Copy(x_, 7, 2))*25;
        kf_ := Val(Copy(x_, 10, 2));

    end  else  begin
        // NTSC (simple - no dropframe)
        kh_ := Val(LeftStr(x_, 2))*3600*30;
        km_ := Val(Copy(x_, 4, 2))*60*30;
        ks_ := Val(Copy(x_, 7, 2))*30;
        kf_ := Val(Copy(x_, 10, 2));

    end;

    TimecodeToFrame := kh_+km_+ks_+kf_;

{$IFEND} // def_TimecodeToFrames
end;

function FramesToTimecode(var x_: Smallint): Double;
var
    Minus: String;
    sm_, F_, h_, M_, s_: Longint;
begin
//{$DEFINE def_FramesToTimecode}
{$IF Defined(def_FramesToTimecode)}
    //
    // x_  is the frames-value

    if x_<0 then begin
        x_ := x_*-1;
        Minus := '-';
    end  else  begin
        Minus := '';
    end;

    if Form1.NTSC.Checked=false then begin
        // PAL
        sm_ := Floor(x_/25);
        F_ := x_-sm_*25;

        h_ := Floor(sm_/3600);
        M_ := Floor((sm_-h_*3600)/60);
        s_ := Floor(sm_-h_*3600-M_*60);

        Result := StrToFloat(Minus+FormatVB(h_,'00:')+FormatVB(M_,'00:')+FormatVB(s_,'00:')+FormatVB(F_,'00'));

    end  else  begin
        // NTSC
        sm_ := Floor(x_/30);
        F_ := x_-sm_*30;

        h_ := Floor(sm_/3600);
        M_ := Floor((sm_-h_*3600)/60);
        s_ := Floor(sm_-h_*3600-M_*60);

        Result := StrToFloat(Minus+FormatVB(h_,'00:')+FormatVB(M_,'00:')+FormatVB(s_,'00:')+FormatVB(F_,'00'));

    end;

{$IFEND} // def_FramesToTimecode
end;



procedure TForm1.Button2Click(Sender: TObject);
var
    Duration1: Double;
    Duration,InCue,OutCue: String;

begin
InCue:= '10:02:10:12';
OutCue:= '10:05:10:12';
Duration:= (TimecodeToFrames(OutCue)-TimecodeToFrames(InCue));
Duration1:= FramesToTimecode(TimecodeToFrames(OutCue)-TimecodeToFrames(InCue)) ;
Edit3.Text:=Duration1;
end;
потому что формы нет...
 
Всё разобрался всем спасибо
1.JPG 2.JPG 3.JPG
 
Вверх Снизу