如何在此代码中执行ffmpeg命令

时间:2011-02-09 06:56:44

标签: php ffmpeg

想知道如何执行ffmpeg命令以在此代码中截取屏幕截图。我无法弄清楚何时创建屏幕截图,通过哪个功能或通过哪一行完成。

  $ffmpeg = '/usr/bin/ffmpeg';
        $video  = $sourceUrl;// the input video file
        $thumbId = uniqid();
        $thumbId .= ".jpg";
        // where you'll save the image
        $image = "uploads/$thumbId";
        // default time to get the image
        $second = 1;
        // get the duration and a random place within that
        $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));
        }

        // get the screenshot
        $cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -s 120x90 -vcodec mjpeg -f mjpeg $image 2>&1";
        $return = `$cmd`;
        $thumbLink = "";

1 个答案:

答案 0 :(得分:3)

此行执行您存储在变量$cmd中的命令:

    $return = `$cmd`;

在PHP中,反引号为execution operator,其用法与调用shell_exec相同。