我不确定我做了什么,但是当我运行代码时,它以某种方式删除了我的视频文件,也就是说,它将每个视频文件减少到仅20-40Kb。
我正在使用目录树迭代器来遍历选定的文件夹,并迭代其中的所有文件和子文件夹,每个命令都有一个命令。在这个阶段,我只做文件,而代码只是
现在我可以使用它一次,并且可以保存2个我用于测试的视频文件。由于某些原因,这些文件被删除。我尝试再次运行它,并删除了所有视频。
可能是什么问题?
$mysqli = new mysqli("localhost", "refit_2_admin", "asd123", "refit_2");
if($mysqli->connect_error)
{
exit('Error db');
}
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli->set_charset("utf8mb4");
$_SESSION['mysqli'] = $mysqli;
// DIRECTORY
$dir = 'videos';
$it = new RecursiveTreeIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS));
foreach($it as $path => $branch)
{
if(is_dir($path)) // if is a directory
{
// echo something
}
if(is_file($path)) // if is a file
{
$schism = pathinfo($path);
$string = str_replace(' ', '_', $schism['filename']);
//$string = str_replace($replace, $with, $string);
rename($path, $dir.'\\'.$string.'.mp4');
$ffmpeg = 'ffmpeg.exe';
$video = dirname(__FILE__) . '\\'.$dir.'\\'.$string.'.mp4';
//echo ''.$video.'<br>';
$image = dirname(__FILE__) . '\\'.$dir.'\\'.$string.'.jpg';
//echo ''.$image.'<br>';
$second = 1;
/*$cmd = "$ffmpeg -i $video 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}*/
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";
$return = `$cmd`;
$video_title = substr($schism['filename'], 0, -5);
$video_filename = $schism['filename'].'.mp4';
$video_thumbnail = $schism['filename'].'.jpg';
$video_include = basename(__DIR__);
// Insert
$stmt = $mysqli->prepare("INSERT INTO videos (video_title, video_filename, video_include, video_tags, video_thumbnail) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $video_title, $video_filename, $dir, $video_title, $video_thumbnail);
$stmt->execute();
$stmt->close();
}
}