AJAX-PHP-FFMPEG-执行未完成

AJAX-PHP-FFMPEG-执行未完成,php,ajax,ffmpeg,Php,Ajax,Ffmpeg,这里有一个稍微棘手的情况: 我使用ajax调用一个函数,该函数使用FFMpeg转换视频 除以下情况外,本规范适用: 执行被缩短了,所以我最终得到了一个2帧的视频 我假设这是ajax造成的问题,因为就其而言,它调用了函数并向我的php页面返回了一个成功的输出 换句话说,当ajax完成时,ffmpeg脚本将被切断 有没有一种方法可以告诉ajax等待ffmpeg函数完成,或者我需要设置一个cron作业以便它在后台运行 编辑: 代码如下: 阿贾克斯: 修好了 我不得不补充一句 async: false,

这里有一个稍微棘手的情况:

我使用ajax调用一个函数,该函数使用
FFMpeg
转换视频

除以下情况外,本规范适用:

执行被缩短了,所以我最终得到了一个2帧的视频

我假设这是ajax造成的问题,因为就其而言,它调用了函数并向我的php页面返回了一个成功的输出

换句话说,当ajax完成时,ffmpeg脚本将被切断

有没有一种方法可以告诉ajax等待ffmpeg函数完成,或者我需要设置一个cron作业以便它在后台运行

编辑:

代码如下:

阿贾克斯:

修好了

我不得不补充一句

async: false,
到ajax请求


干杯;)

分享您的代码也完成问题。谢谢,添加代码
// Watermark ***************
// IMPORTANT!
// This action & function can be called by ajax but requires absolute file paths!

add_action( 'wp_ajax_watermark', 'do_watermark' );
add_action( 'wp_ajax_nopriv_watermark', 'do_watermark' );

function getabspath( $file_url ){
   return realpath($_SERVER['DOCUMENT_ROOT'] . parse_url( $file_url, PHP_URL_PATH ));
}

function do_watermark() {

    session_start();   
    ini_set('display_errors', 1);
    error_reporting(E_ALL);

//  $thevideo = $_POST['thevideo'];
    $thevideo = getabspath($_POST['thevideo']);

    $newvideo = getabspath('./wp-content/uploads') . '/test.mp4';

    $thewatermark = getabspath('./wp-content/uploads/mefbpic.png');
//  For some reason we have to OMIT THE DRIVE LETTER from the watermark image path
//  AND the backslashes need to be turned forward even tho its an absolute path!?!
    $thewatermark = substr($thewatermark,2); // Cuts off the first 2 chars. - (C:)
    $thewatermark = str_replace('\\','/',$thewatermark);

//  require_once('./vendor/autoload.php');
    require_once(getabspath('./vendor/autoload.php'));

$ffmpeg = FFMpeg\FFMpeg::create(array(
'ffmpeg.binaries' => getabspath('./FFMpeg/bin/ffmpeg.exe'),
'ffprobe.binaries' => getabspath('./FFMpeg/bin/ffprobe.exe'),
'timeout' => 3600, // The timeout for the underlying process
'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
));

    $video = $ffmpeg->open($thevideo);

    $video
      ->filters()
      ->resize(new \FFMpeg\Coordinate\Dimension(640, 360))
      ->watermark($thewatermark, [
        'position' => 'relative',
        'bottom' => 50,
        'right' => 50,
      ])
      ->synchronize();
    //$video
    //  ->save(new \FFMpeg\Format\Video\X264(), $thevideo);

        $format = new \FFMpeg\Format\Video\X264();
        $format->setAdditionalParameters(array('-y'));
        $video->save($format, $newvideo);

    echo 'done!';

}
async: false,