2012-04-06 29 views
5

Tôi đang cố gắng phát hiện thời lượng của bất kỳ tệp video nào trước khi được tải lên bằng PHP
vì vậy nếu ít hơn một phút chẳng hạn, tôi sẽ từ chối tải lên.
nếu không thể, làm thế nào tôi có thể làm điều đó sau khi tải lên video ??Làm cách nào để phát hiện thời lượng tệp video trong vài phút bằng PHP?

+0

Xin lỗi không có gì .. bạn cần phải tải lên tập tin đầu tiên: D – Baba

+0

@Baba và làm thế nào tôi có thể làm điều đó sau khi tải lên các tập tin? –

+0

Hm không thực sự chắc chắn về video nhưng âm thanh hoạt động. Hãy thử getID3 http://getid3.sourceforge.net/. Có một số lớp có thể được sử dụng để lấy dữ liệu video cơ bản. – StudioArena

Trả lời

14

Bạn có thể nhận video duration với ffmpeg hoặc getID3

Ví dụ

$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 />"); 

Hoặc

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); 

Xin xem

http://getid3.sourceforge.net/

http://ffmpeg.org/

How to get video duration, dimension and size in PHP?

get flv video length

Cảm ơn

: D

+0

anh ấy nói anh ấy cần điều này trước khi tải lên. Cảm ơn: D – kommradHomer

+0

Xem nhận xét của anh ấy '@Baba và làm thế nào tôi có thể làm điều đó sau khi tải lên tệp? - Ayman Jitan cách đây 6 phút '@kommradHomer – Baba

+0

wow. Tôi đã đọc tất cả các bình luận trước khi bình luận vì không xấu hổ – kommradHomer

0

cho người đến kiểm tra này ra đây là một giải pháp một chút cao cấp hơn cho năm 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 
Các vấn đề liên quan