I am trying to detect the duration of any video file before it is uploaded with PHP
so if it is less than one minute for example I will refuse uploading it.
if it is not possible , how can I do it after uploading the video ??
Asked
Active
Viewed 2.5k times
6

Evan Lévesque
- 3,115
- 7
- 40
- 61
-
Sorry there is none .. you need to upload the file first :D – Baba Apr 06 '12 at 12:22
-
@Baba and how can I do it after uploading the file? – Evan Lévesque Apr 06 '12 at 12:23
-
Hm not really sure about videos but for audio it works. Try getID3 http://getid3.sourceforge.net/. There are some classes which can be used to get basic video data. – StudioArena Apr 06 '12 at 12:27
-
There are ways to detect the file size before uploading , if you use flash based uploaders. May work for you if u think just making a thorough guess would work for you – kommradHomer Apr 06 '12 at 12:33
-
Possible duplicate of [How to get video duration, dimension and size in PHP?](http://stackoverflow.com/questions/4847752/how-to-get-video-duration-dimension-and-size-in-php) – M Khalid Junaid Dec 29 '15 at 12:40
2 Answers
14
You can get video duration
with ffmpeg
or getID3
Example
$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 />");
Or
ob_start();
passthru("ffmpeg -i working_copy.flv 2>&1");
$duration = ob_get_contents();
$full = ob_get_contents();
ob_end_clean();
$search = "/duration.*?([0-9]{1,})/";
print_r($duration);
$duration = preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);
print_r('<pre>');
print_r($matches[1][0]);
print_r($full);
Please see
http://getid3.sourceforge.net/
How to get video duration, dimension and size in PHP?
Thanks
:D
-
-
1See his comment `@Baba and how can I do it after uploading the file? – Ayman Jitan 6 mins ago` @kommradHomer – Baba Apr 06 '12 at 12:30
-
wow. i've to read every comment before commenting for not being ashamed – kommradHomer Apr 06 '12 at 12:31
-
@kommradHomer , if I can do it before uploading that will be great :) – Evan Lévesque Apr 06 '12 at 12:36
-
you can just make a wide guess , by using a flash-based uploader to check the file size before uploading. Actually , if u try to avoid having small files , then whats the problem ? let them load small files , its not a big burden. it would be a burden if u were trying to run away from big files, as thats what we usually do. – kommradHomer Apr 06 '12 at 12:39
-
What is the essence of duration before upload ... kommradHomer has a valid point – Baba Apr 06 '12 at 12:43
0
for people coming to check this out this is a solution a little more advanced for the year 2017
first download the latest version from the first link above in the accepted answer the (green checkmark)
require_once('getid/getid3/getid3.php'); //path to your get id file if you do not include this in your file it will result in an error meaning the code will not work
$file = "sade.mp4"; //what you want extract info from maybe mp3,or mp4 file anything you want to get file size in bytes or time duration
$uuuuu = "videos/"; //path to your video file it could also be music not only video
$getID3 = new getID3; //initialize engine
$ThisFileInfo = $getID3->analyze($uuuuu.$file);
getid3_lib::CopyTagsToComments($ThisFileInfo);
echo '<pre>'.htmlentities(print_r($ThisFileInfo, true)).'</pre>'; //use this to print array to pick whatever you like that you want value like playduration, filesize

chiz
- 71
- 1
- 1
- 8