ffmpeg-php to create thumbnail of video

前端 未结 2 1716
一个人的身影
一个人的身影 2020-12-28 12:05

I am trying to use this script to create thumbnail of a video using ffmpeg. At first I used phpinfo(); and I found ffmpeg is installed on my se

2条回答
  •  既然无缘
    2020-12-28 12:42

    Looked over the code, made it simpler and runnable, maybe this helps some of you.

    class VideoTile
    {
        public static function createMovieThumb($srcFile, $destFile = "test.jpg")
        {
            // Change the path according to your server.
            $ffmpeg_path = 'D:\\ffmpeg\\bin\\';
    
            $output = array();
    
            $cmd = sprintf('%sffmpeg -i %s -an -ss 00:00:05 -r 1 -vframes 1 -y %s', 
                $ffmpeg_path, $srcFile, $destFile);
    
            if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
                $cmd = str_replace('/', DIRECTORY_SEPARATOR, $cmd);
            else
                $cmd = str_replace('\\', DIRECTORY_SEPARATOR, $cmd);
    
            exec($cmd, $output, $retval);
    
            if ($retval)
                return false;
    
            return $destFile;
        }
    }
    

    Usage is

    $file = VideoTile::createMovieThumb("../video3.mp4");
    

提交回复
热议问题