ffmpeg獲取視頻封面圖片


ffmpeg百度雲盤下載地址:https://pan.baidu.com/s/1Am_x0abBvXTrbCFPHs5e9Q

提取碼:4y2r

/**
 * ffmpeg百度雲盤下載地址:https://pan.baidu.com/s/1Am_x0abBvXTrbCFPHs5e9Q
 * 提取碼:4y2r
 * 獲取視頻封面圖片
 * @param string $inFile 視頻文件地址
 * @param int $time 截圖的秒數
 * @param int $width 圖片寬度
 * @param int $height 圖片高度
 */
function getVideoCover($inFile, $time = 1, $width = 320, $height = 240)
{
    //文件根目錄
    $rootPath = realpath(__ROOT__) . './Public';

    //輸入文件路徑
    $inFile = $rootPath . $inFile;

    //輸出文件名
    $outFileName = uniqid('video_') . ".jpg";

    //輸出文件目錄
    $outFileDir = '/uploads/videocover/' . date("Ymd", time()) . '/';
    if (!is_dir($rootPath . $outFileDir)) {
        mkdir($rootPath . $outFileDir, 0777, true);
    }
    //輸出文件路徑
    $outFile = $rootPath . $outFileDir . $outFileName;

    //ffmpeg.exe文件路徑
    $ffmpeg = realpath(__ROOT__) . './ffmpeg/ffmpeg.exe';

    //運行命令
    $command = $ffmpeg . " -i " . $inFile . " -y -f image2 -t {$time} -s {$width}x{$height} " . $outFile;

    system($command);

    return $outFileDir . $outFileName;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM