How to use multiple variables in time calculator c#

Posted by Peter O'Dwyer on Super User See other posts from Super User or by Peter O'Dwyer
Published on 2013-11-01T15:16:15Z Indexed on 2013/11/01 16:01 UTC
Read the original article Hit count: 261

Filed under:
|

I am building a video time calculator and need to use the number of frames instead of milliseconds.

e.g

25FPS

HH:MM:SS:FR
00:00:10:24 <-- Last frame of 10 seconds
00:00:11:00 <-- First frame of 11 seconds

My problem is that if the start frames are lower than my end frames it can't calculate the time.

00:00:10:05 <-- Start
01:00:10:10 <-- End
00:59:59:05 <-- Answer which I can't get!!

HERE'S MY CODE

                    string Startdate = Dur_txtStart.Text;
                    string Enddate = Dur_txtEnd.Text;

                    string Startdate1 = Startdate.Substring(0, 8);
                    int Startframe1 = Convert.ToInt32(Startdate.Substring(9, 2));
                    string Startdate2 = Enddate.Substring(0, 8);
                    int Startframe2= Convert.ToInt32(Enddate.Substring(9, 2));

                    TimeSpan diff = DateTime.Parse(Startdate2).Subtract(DateTime.Parse(Startdate1));
                    int frameDiff = Startframe2 - Startframe1;

                    int Hour = Convert.ToInt32(diff.Hours);
                    int Min = Convert.ToInt32(diff.Minutes);
                    int Sec = Convert.ToInt32(diff.Seconds);
                    if (frameDiff < 0 && Sec > 0)
                    {
                        Sec -= 1;
                        string frameDiffBuild = string.Format("{0}:{1}:{2}:{3}",Hour.ToString("D2"), Min.ToString("D2"), Sec.ToString("D2"), (Convert.ToInt32(Dur_txtFPS.Text + frameDiff)).ToString("D2"));
                        Dur_txtOutTime.Text = frameDiffBuild;
                    }
                    else
                    {
                        string frameDiffBuild = string.Format("{0}:{1}:{2}:{3}",Hour.ToString("D2"), Min.ToString("D2"), Sec.ToString("D2"), frameDiff.ToString("D2"));
                        Dur_txtOutTime.Text = frameDiffBuild;
                    }

Hope you can help guys my head is mashed!

© Super User or respective owner

Related posts about video

Related posts about c#