Welcome Guest, Not a member yet? Register   Sign In
file size and duration
#1

(This post was last modified: 07-26-2016, 03:57 AM by matin.)

how to save file size and duration of a uploaded video file.
$this->upload->data(file_size)
must work for storing file size but it doesn't work on my server, here is the error:
Use of undefined constant file_size - assumed 'file_size'
Reply
#2

$this->upload->data('file_size')
KeepĀ calm.
Reply
#3

to calculate the length of a song in seconds all you need is samplerate, (bitspersample / 8 ) and the size of the song in bytes. Sample rate is samples per second so knowing that, if the size of the song is 4.194.304 bytes you divide byte 2 bytes, which is the size of a single sample, that gives you 2.097.152 samples total, now you know that the sample rate is 22050 samples per second so divide the number of samples with that number will give you seconds in this case that will be 95 seconds. All this are for a single channel if you know the number of channels then simple divide the total samples or the seconds you have calculated by the number of channels and you should rich the correct answer.

Now that i said that you have to keep in mind that if the song is recorded using VBR all the above is just an aproximation.
Engligh only, no SEO spam
Reply
#4

(07-23-2016, 11:26 PM)matin Wrote: how to save file size and duration of a uploaded video file.
$this->upload->data(file_size)
must work for storing file size but it doesn't work on my server, here is the error:
Use of undefined constant file_size - assumed 'file_size'

As @arma7x points out, you need to put quotes around file_size. Keep in mind that upload->data() isn't going to work until after upload->do_upload() has been called.

@site2017 presents a reasonable method to approximate the duration. If you want more accuracy here are a couple libraries that you might find interesting.

Zedwood.com PHP Calculate Duration of MP3
jagneshchawla/audio length Mp3 class- PHP

If you are looking for a library that provides additional file info and/or is useful for many different file formats beyond mp3 check out the following.

getID3()
Reply




Theme © iAndrew 2016 - Forum software by © MyBB