Jump to content

Math From Filesize


Go to solution Solved by Psycho,

Recommended Posts

I have a directory of mp3 files that I need to find out the combined length in minutes and seconds of all the audio files.

The files are all 128kbps stereo mp3's. 

Here's what I have so far...

 

<?php

//connect to remote server (hostname, port)
$connection = ssh2_connect('192.168.2.4', 22);

//authenticate
ssh2_auth_password($connection, 'username', 'password');

//execute remote command (replace /path/to/directory with absolute path)
$stream = ssh2_exec($connection, 'du -k /remotedirectory');
stream_set_blocking($stream, true);

//get the output
$dirSize = stream_get_contents($stream);

//show the output and close the connection

$showsize = $dirSize;
//echo $showsize; exit;

$math = (($showsize * 1000) / 128);  //without the /128 it shows 34308000...which is correct.  the files are 128kbps
//echo $math; exit;

echo gmdate("i:s", $math);  // shows 27:11 which is wrong...the actual total time of all of the files in the directory is 36:34 ...minutes and seconds

fclose($stream);

?>




Any ideas where I'm off in the logic of the math?

Thanks.

Edited by bschultz
Link to comment
https://forums.phpfreaks.com/topic/303321-math-from-filesize/
Share on other sites

Are the files all constant-rate 128Kbps? Have they been stripped of all ID3 tags?

 

$showsize is in KB so the /1000 would be both wrong (check the man page for what -k means) and unnecessary.

 

34308 KB * 8 = 274464 Kb / 128 Kbps = 2144.25 sec = 35:44. So there's something else going on.

Link to comment
https://forums.phpfreaks.com/topic/303321-math-from-filesize/#findComment-1543559
Share on other sites

All files are 128k constant.  id3 tags are empty.  That's how they're downloaded.

 

I read that -k would force KB...but without it, $showsize was off from what right clicking the directory showed me for file size. 

Would it be better to get size of all files instead of directory size?  Does du take into account the size of all files individually, or just the combined disk space used?

Edited by bschultz
Link to comment
https://forums.phpfreaks.com/topic/303321-math-from-filesize/#findComment-1543560
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.