duan97689 2018-10-29 17:10
浏览 48

php重命名ffmpeg删除/减少我的视频文件到20Kb

I'm not sure what I did but somehow when I ran my code it deleted my video files, that is, it reduced each video file to a mere 20-40Kb.

I'm using a directory tree iterator to go through the selected folder and iterate all the files and subfolders in there, with commands for each. I'm only doing the files at this stage, and the code simply

  1. renames the video file so that it has no spaces in it's name
  2. extracts a thumbnail using ffmpeg and places it in the videos directory
  3. inserts data in to database for displaying on a website.

Now I was able to use it once, and it worked save for 2 video files that I had been using for testing. For some reason those files were deleted. I tried running it again and it deleted all the videos.

What might be the problem?

$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();
    }

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)