Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 843459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:07:50+00:00 2026-05-15T06:07:50+00:00

I have what I suspect to be a logic problem with an algorithm I

  • 0

I have what I suspect to be a logic problem with an algorithm I am using to work with Video timecode in PHP. All help is appreciated.

The Objective

Well basically I want to work with timecode and perform calculations

For those not familiar with timecode it looks like this

01:10:58:12 or HH:MM:SS:FF ‘AKA’ HOURS:MINUTES:SECONDS:FRAMES

I have used the script from HERE to help me with working with this format.

The Problem

Now can i just say that this script works!!! Timecode calculations (in this case additions) are being performed correctly. However this script continually throws the following errors, yet still produces the correct output when I try and do the following calculation

00:01:26:00 + 00:02:00:12

The errors from this calculation are shown below

A PHP Error was encountered

Severity: Notice

Message: Undefined index: key

Filename: staff/tools.php

Line Number: 169

A PHP Error was
encountered

Severity: Notice

Message: Undefined index: key

Filename: staff/tools.php

Line Number: 169

Line Number 169 is in the parseInput() function

// feed it into the tc array
$i=0;
foreach ($tc AS $key=>$value) {
    if ( is_numeric($array["$i"]) ) {
        $tc["$key"]= $array["$i"];
        if ($tc["$key"] < 10 && $tc["$key"] > 0 && strlen($tc['key'])==1 ) $tc["$key"]= "0".$tc["$key"];
        }
    $i++;
    }

return $tc;

Now I should also mention that the number of times the above error is thrown depends on what I am calculating

00:00:00:00 + 00:00:00:00

returns no errors.

01:01:01:01 + 02:02:02:02

produces 8 of the above errors.


For your reference, here is the code in it’s entirety

function add_cue_sheet_clips_process()
{

$sheetID = $_POST['sheet_id'];
$clipName = $_POST['clip_name'];
$tcIn = $_POST['tc_in'];
$tcOut = $_POST['tc_out'];

// string $input
// returns an associative array of hours, minutes, seconds, and frames
//
function parseInput ($input) {
// timecode should look something like hh:mm:ss;ff
// allowed separators are : ; . ,
// values may be single or double digits
// hours are least-significant -- 5.4 == 00:00:05;04
$tc= array("frames"=>"00", "seconds"=>"00", "minutes"=>"00", "hours"=>"00");
$punct= array(":", ";", ".", ",");

// too big? too small?
$input= trim($input);
if (strlen($input)>11 || $input=="") {
    // invalid input, too long -- bzzt
    return $tc;
    }

// normalize punctuation
$input= str_replace( $punct, ":", $input);

// blow it up and reverse it so frames come first
$array= explode(":", $input);
$array= array_reverse($array);

// feed it into the tc array
$i=0;
foreach ($tc AS $key=>$value) {
    if ( is_numeric($array["$i"]) ) {
        $tc["$key"]= $array["$i"];
        if ($tc["$key"] < 10 && $tc["$key"] > 0 && strlen($tc['key'])==1 ) $tc["$key"]= "0".$tc["$key"];
        }
    $i++;
    }

return $tc;
}

// array $tc
// returns a float number of seconds
//
function tcToSec($tc) {
    $wholeseconds= ($tc['hours']*3600) + ($tc['minutes'] * 60) + ($tc['seconds']);
    $partseconds= ( $tc['frames']  / 25 );
    $seconds= $wholeseconds + $partseconds;
    return $seconds;
    }

// float $seconds
// bool $subtract
// returns a timecode array
//
function secToTc ($seconds=0, $subtract=0) {
    $tc= array("frames"=>"00", "seconds"=>"00", "minutes"=>"00", "hours"=>"00");

    $partseconds= fmod($seconds, 1);
    $wholeseconds= $seconds - $partseconds;

    // frames
    if ($subtract==1) $tc['frames']= floor( $partseconds * 25 );
    else $tc['frames']= floor( $partseconds * 25 );

    // hours
    $tc['hours']= floor( $wholeseconds / 3600 );
    $minsec= ($wholeseconds - ($tc['hours'] * 3600));

    // minutes
    $tc['minutes']= floor( $minsec / 60 );

    // seconds
    $tc['seconds']= ( $minsec - ($tc['minutes'] * 60) );

    // padding
    foreach ( $tc AS $key=>$value ) {
        if ($value > 0 && $value < 10) $tc["$key"]= "0".$value;
        if ($value=="0") $tc["$key"]= "00";
        }
    return $tc;
    }

// array $tc
// returns string of well-formed timecode
//
function tcToString (&$tc) {
    return $tc['hours'].":".$tc['minutes'].":".$tc['seconds'].";".$tc['frames'];
    }


$timecodeIN = parseInput($tcIn);
$timecodeOUT = parseInput($tcOut); 

// normalized inputs...
$tc1 = tcToString($timecodeIN);
$tc2 = tcToString($timecodeOUT);

// get seconds
$seconds1 = tcToSec($timecodeIN);
$seconds2 = tcToSec($timecodeOUT);

$result = $seconds1 + $seconds2;

$timecode3 = secToTc($result, 0);
$timecodeDUR = tcToString($timecode3);

$clipArray = array('clip_name' => $clipName, 'tc_in' => $tcIn, 'tc_out' => $tcOut, 'tc_duration' => $timecodeDUR);

$this->db->insert('tools_cue_sheets_clips', $clipArray);

redirect('staff/tools/add_cue_sheet_clips/'.$sheetID);
}

I hope this is enough information for someone to help me get on top of this, I would be extremely greatful.

Thanks,

Tim

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:07:51+00:00Added an answer on May 15, 2026 at 6:07 am

    The NOTICE Errors are usually minor, Heres an example

    if($unamedVaraible){/.../} //Notince: undefined variable
    
    if(isset($unamedVaraible)){/..../} //no error as its checking correctly for the purpose
    

    of you done

    error_reporting(E_ALL ^ E_NOTICE); ///Show all errors but E_NOTICE
    

    you will be able to supress these errors.

    You’ll find the error_reporting() function located at the top of your main index.php file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One day I suspect I'll have to learn hadoop and transfer all this data
I have the following situation in code, which I suspect may be a bit
I suspect this is impossible, but thought I'd ask. Say I have a class
Suppose I have a git repository with several branches. I suspect some of the
I have looked at the usual suspects...Spark, NHaml, etc. They all seem to be
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have constant problem with cookies on my Django site which is set up
I have a fair bit of experience with PHP frameworks and Python for scripting
I have a scenario which is causing very long running processes and suspect it
I've got no experience with this, so i suspect my logic is overly complicated,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.