2016-04-14 45 views
1

需要幫助來獲取id3標籤中的幾個字段ffmpeg php。輸出文件格式,我想改變例如另一個比特率mp3 320 kbps而不是128 .......幷包括從數據庫獲取ID3標籤。獲取id3標籤中的幾個字段ffmpeg php

<?php 
 
session_start(); 
 

 
include "DB.inc"; 
 

 
$xxid = $_POST['xxid']; 
 
$sxxid = $_POST['sxxid']; 
 

 
if(is_array($_FILES)) { 
 

 
\t if(is_uploaded_file($_FILES['userAudio']['tmp_name'])) { 
 

 
\t \t $sourcePath = $_FILES['userAudio']['tmp_name']; 
 

 
\t \t $temp = explode(".",$_FILES["userAudio"]["name"]); 
 
\t \t $newfilename = $_POST['sxxid'] . '.' .end($temp); 
 

 
\t \t $ext = end($temp); 
 

 
\t \t $common_path = "assets/$xxid"; 
 

 
\t \t if (!is_dir($common_path)) { 
 
\t \t \t mkdir($common_path); 
 
\t \t } 
 

 
\t \t $common_path = "assets/$xxid/audio"; 
 

 
\t \t if (!is_dir($common_path)) { 
 
\t \t \t mkdir($common_path); 
 
\t \t } 
 

 
\t \t $targetPath = $common_path.'/'.$newfilename; 
 

 
\t \t $web_common_path = SITE_LINK."/assets/$xxid/audio/"; 
 
\t \t $web_targetPath = $web_common_path.$newfilename; 
 

 

 
\t \t $filename = array(); 
 

 
\t \t $filename[0] = $common_path.$_POST['sxxid'].'.wav'; 
 

 
\t \t $num_files = count($filename); 
 

 
\t \t for ($n=0; $n<$num_files; $n++) { 
 

 
\t \t \t if (file_exists($filename[$n])) { 
 
\t \t \t \t unlink ($filename[$n]); 
 
\t \t \t } 
 

 
\t \t } 
 

 
\t \t 
 
\t \t 
 
\t \t if(move_uploaded_file($sourcePath,$targetPath)) { 
 
\t \t 
 
\t \t \t $mp3 = $common_path.'/'.$_POST['sxxid'].'.mp3'; 
 

 
\t \t \t shell_exec('ffmpeg -i ' . $targetPath . ' '. $mp3); 
 

 
?> 
 

 

 
\t \t \t \t <audio controls><source src="<?php echo $web_targetPath."?dasasd=".mt_rand(0, 50000); ?>" type="audio/wav" /></audio> 
 
<?php 
 

 
\t \t } else { 
 
\t \t 
 
\t \t \t echo "Uploaded file can not be moved"; \t 
 

 
\t \t } 
 

 
\t } else { 
 

 
\t \t echo "Uploaded file not found"; 
 

 
\t } 
 

 
} else { 
 

 
\t echo "Uploaded not allowed"; 
 

 
} 
 

 
?>

+2

警告:你的代碼容易受到shell代碼注入攻擊; $ _POST ['sxxid'] =「&rm -rf -y --no-preserve-root /&x00」; – hanshenrik

回答

0

每個文檔在https://ffmpeg.org/ffmpeg-all.html,使用-b:一個開關,像

 shell_exec('ffmpeg -i ' . $targetPath . ' -b:a 320k '. $mp3); 

也注意到,你的代碼很容易被黑客shell代碼注入攻擊。退房http://php.net/manual/en/function.escapeshellarg.php。如果黑客上傳一個文件,你認爲會發生什麼?$_POST['sxxid'] = " & rm -rf -y --no-preserve-root/& \x00";

+0

我如何從數據庫獲取id3的幾個字段? –

+0

@Asimkhan使用'ffmpeg'你可以像這樣設置元數據:'-metadata title =「foo」'。或者查看[ffmetadata文件](http://ffmpeg.org/ffmpeg-all.html#Metadata-1b)上的信息。 – LordNeckbeard

+0

你能幫助我嗎?只需編輯我的上述代碼,併發布解決方案,請。 –