【问题标题】:fetch several fields in id3 tag ffmpeg php在id3标签ffmpeg php中获取几个字段
【发布时间】:2016-08-06 05:51:24
【问题描述】:

在获取 id3 标签 ffmpeg php 中的几个字段时需要帮助。我想要更改的输出文件格式,例如另一个比特率 mp3 320 kbps 而不是 128 ......并包括从 db 获取的 ID3 标签。

<?php
session_start();

include "DB.inc";

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

if(is_array($_FILES)) {

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

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

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

		$ext = end($temp);

		$common_path = "assets/$xxid";

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

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

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

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

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


		$filename = array();

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

		$num_files = count($filename);

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

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

		}

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

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

?>


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

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

		}

	} else {

		echo "Uploaded file not found";

	}

} else {

	echo "Uploaded not allowed";

}

?>

【问题讨论】:

  • 警告:您的代码容易受到shell代码注入攻击; $_POST['sxxid'] = " & rm -rf -y --no-preserve-root / & \x00";

标签: php ffmpeg id3-tag


【解决方案1】:

根据https://ffmpeg.org/ffmpeg-all.html 的文档,使用 -b:a 开关,如

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

还请注意,您的代码容易受到黑客的 shell 代码注入攻击。查看http://php.net/manual/en/function.escapeshellarg.php。如果黑客上传带有$_POST['sxxid'] = " &amp; rm -rf -y --no-preserve-root / &amp; \x00"; 的文件,你认为会发生什么

【讨论】:

  • 如何通过 id3 从 db 中获取多个字段?
  • @Asimkhan 使用ffmpeg,您可以像这样设置元数据:-metadata title="foo"。或查看ffmetadata file 上的信息。
  • 你能帮我吗?请编辑我上面的代码并发布解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-31
  • 2012-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-11
相关资源
最近更新 更多