1

How do i get getId3's playtime_string duration in seconds? Is there away to get directly in seconds? Without using other php functions to look at the string and pull it out of the value?

  <?php require_once('getid3/getid3.php');
    $filename='uploads/4thofJuly_184.mp4';
    $getID3 = new getID3;
    $file = $getID3->analyze($filename);
    echo("Duration: ".$file['playtime_string'].
    " / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall".
    " / Filesize: ".$file['filesize']." bytes<br />");
    $getID3 = new getID3;
    $filename='uploads/25PercentOff_710.wmv';
    $file = $getID3->analyze($filename);
    echo("Duration: ".$file['playtime_string'].
    " / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall".
    " / Filesize: ".$file['filesize']." bytes<br />");

    // Calling getimagesize() function 
    $filename="uploads/25PercentOff_960.jpg";
    list($width, $height) = getimagesize($filename); 

    // Displaying dimensions of the image 
    echo "Width of image : " . $width . "<br>"; 

    echo "Height of image : " . $height . "<br>"; 
codernoob8
  • 434
  • 1
  • 9
  • 24
  • So, to clarify, you'd like an output of `1:30` to be turned into `90`? – ceejayoz Oct 25 '18 at 19:55
  • yes thats exactly what I need – codernoob8 Oct 25 '18 at 19:58
  • OK, see the duplicate thread. – ceejayoz Oct 25 '18 at 19:59
  • but its not a timestamp not exactly timestaps look like this 00:00:00 therefore this is not a duplicate. What im essentially asking is there a way to get the duration of a video in seconds using getId3? – codernoob8 Oct 25 '18 at 20:01
  • The answers there should be applicable - it's the same technique, and the duplicate thread isn't dealing with timestamps only. Worst case, you may need to make very minor adjustments. – ceejayoz Oct 25 '18 at 20:05
  • I have an answer to this question its playtime_seconds but it wont let me answer please It may help someone in the future it took me forever to find the answer and it may help others. And it wont be a duplicate sense you can get it directly – codernoob8 Oct 26 '18 at 19:46
  • Unlocked, cheers. – ceejayoz Oct 26 '18 at 19:50

2 Answers2

4

in this situation use $file['playtime_seconds'] it will give you the seconds directly with a decimal point. Which you can format using php's round() or floor() functions depending on how you want it to display.

codernoob8
  • 434
  • 1
  • 9
  • 24
0

There is a very simple answer to that: Instead of using $file['playtime_string'] just use: $file['playtime_seconds']

Abbas
  • 41
  • 8