Create Video Thumbnail of All Files in a Directory via FFmpeg and PHP

谁说我不能喝 提交于 2019-12-03 21:50:39

It's just a quick one:

$videos_dir = 'path/to/videos';
$videos_dir = opendir($videos_dir);
$output_dir = 'path/to/output/dir/';
while (false !== ($file = readdir($videos_dir))) {
    if ($file != '.' && $file != '..'){
        $in = $videos_dir.'/'.$file;
        $out = $output_dir.$file.'.jpg';
        exec("/usr/local/bin/ffmpeg -itsoffset -105 -i ".$in." -vcodec mjpeg -vframes 1 -an -f rawvideo -s 100x100 ".$out);
    }
}

try this

try
    {
        $directory = 'your directory name';
        $dir = new RecursiveDirectoryIterator($directory);
        $it = new RecursiveIteratorIterator($dir);
        while($it->valid()) {

            if (!$it->isDot()) {
                //echo 'SubPathName: ' . $it->getSubPathName() . "\n";
                //echo 'SubPath:     ' . $it->getSubPath() . "\n";
                //echo 'Key:         ' . $it->key() . "\n\n";
                echo $name = $it->key(),"\n";
                exec("/usr/local/bin/ffmpeg -itsoffset -105 -i $name -vcodec mjpeg -vframes 1 -an -f rawvideo -s 100x100 $name.'.jpg'");    
            }

            $it->next();
        }
    }
    catch(Exception $e)
    {
        echo 'No files Found!<br />';
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!