Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php FFMpeg+;Beanstalk:如何在不使用Beanstalk的情况下将进程传递给它或获得相同的结果_Php_Ffmpeg_Task Queue_Beanstalkd - Fatal编程技术网

Php FFMpeg+;Beanstalk:如何在不使用Beanstalk的情况下将进程传递给它或获得相同的结果

Php FFMpeg+;Beanstalk:如何在不使用Beanstalk的情况下将进程传递给它或获得相同的结果,php,ffmpeg,task-queue,beanstalkd,Php,Ffmpeg,Task Queue,Beanstalkd,我的问题是FFMpeg和Mencoder非常灵活,即使运行一个进程也会使HTTPd变慢,但是(FFMpeg/Mencoder)的多个进程只是完全挂起了它(HTTPd)。例如,我希望使用Beanstalk处理转换 我的具体问题是:如何将我目前的工作转移到Beanstalk 我有一个触发转换的简单PHP代码: RunInBackground('convert.php', array($upload, $video_id), $log_path); 现在,Beanstalk正确的代码是什么样子的?如

我的问题是FFMpeg和Mencoder非常灵活,即使运行一个进程也会使HTTPd变慢,但是(FFMpeg/Mencoder)的多个进程只是完全挂起了它(HTTPd)。例如,我希望使用Beanstalk处理转换

我的具体问题是:如何将我目前的工作转移到Beanstalk

我有一个触发转换的简单PHP代码:

RunInBackground('convert.php', array($upload, $video_id), $log_path);
现在,Beanstalk正确的代码是什么样子的?如果上传多个视频,这些过程不会同时启动

如果您认为为了满足我的需要,最好使用Beanstalk以外的其他工具,并且您知道如何实现它,我仍然很高兴看到它

提前感谢,
伊利亚有两种可能性:
-尝试xuggler进行转换-内联运行,而不必生成作业
-使用数据库或文件创建“文件处理队列”。。让您的转换过程只查询“要处理的未完成文件”,但一次只能运行其中一个文件。它将独立于您的主要任务运行,但可以将其状态发布到您的主要任务可以阅读的地方。例如“忙”或“队列中有3个文件”或“可用”

两种可能性:
-尝试xuggler进行转换-内联运行,而不必生成作业

-使用数据库或文件创建“文件处理队列”。。让您的转换过程只查询“要处理的未完成文件”,但一次只能运行其中一个文件。它将独立于您的主要任务运行,但可以将其状态发布到您的主要任务可以阅读的地方。例如“忙”或“队列中有3个文件”或“可用”

基于ethrbunny提供的好主意,我决定不使用Beanstalk或Resque就可以实现我的目标!毕竟我非常高兴!我敢打赌,对于那些试图将FFMpeg/MPlayer/MEncoder进程限制为服务器上唯一一个活动进程的人来说,这将是非常有用的,以便能够保持其他进程良好运行,例如httpd

一步一步

  • 创建一个数据库,我称之为“编码队列”:

  • 在主上载文件中,触发转换过程的右侧:

    // Let's check if ffmpeg, mplayer, mencoder or mediainfo processes are running //   
    exec("ps ax | grep -v grep | grep ffmpeg", $ffmpeg);
    exec("ps ax | grep -v grep | grep mplayer", $mplayer);
    exec("ps ax | grep -v grep | grep mencoder", $mencoder);
    exec("ps ax | grep -v grep | grep mediainfo", $mediainfo);
    
    if(empty($ffmpeg) && empty($mplayer) && empty($mencoder) && empty($mediainfo)) {
    // As non of them are running we start conversion process //
    
       RunInBackground('convert.php', array($uploaded_file_name , $uploaded_video_id ), $log_file_path);
    
    } else {
    
    // As the ffmpeg or mplayer or mencoder or mediainfo is running we add the process to the queue into the database//
    
       //Connecting to database using ADOdb //             
    
       $sql = "INSERT INTO encoding_queue SET queue_timestamp = '" .time(). "', 
       uploaded_video_id = '" .mysql_real_escape_string($uploaded_video_id ). "',
       uploaded_file_name = '" .mysql_real_escape_string($uploaded_file_name ). "',
       log_file_path = '" .mysql_real_escape_string($log_file_path). "'";
       $conn->execute($sql);
    }
    
  • 在向数据库添加值之后,我们需要检查上一次转换是否完成,并准备开始新的转换!创建convert_queue.php文件并将其添加到CRON作业中,假设每5分钟一次

    <?php
    require('path/to/your/config.php');
    require('path/to/your/function.php');
    
    exec("ps ax | grep -v grep | grep ffmpeg", $ffmpeg);
    exec("ps ax | grep -v grep | grep mplayer", $mplayer);
    exec("ps ax | grep -v grep | grep mencoder", $mencoder);
    exec("ps ax | grep -v grep | grep mediainfo", $mediainfo);
    
    $sql = "SELECT * FROM encoding_queue ORDER BY queue_timestamp ASC LIMIT 1";
    $rs = $conn->execute($sql);
    $queue = $rs->getrows();
    if ( $conn->Affected_Rows() == 0 ) {
    die ("Error! There is no records in the database. Nothing to convert. Stopping...");
    }
    if (file_exists($config['VDO_DIR'] . '/' .$queue[0]['uploaded_file_name'])) {
      if(empty($ffmpeg) && empty($mplayer) && empty($mencoder) && empty($mediainfo)) {
         RunInBackground('convert.php', array($queue[0]['uploaded_file_name'], $queue[0]['uploaded_video_id']), $queue[0]['log_file_path']);
    } else {
         die ("Another conversion process is still in progress. Stopping...");
     }
      } else { 
         die ("Error! There is no video file ".$queue[0]['uploaded_file_name']." found. Nothing to convert. Stopping..."); }
     ?>
    
  • 那么我们得到了什么?如果上传的文件是目前唯一的文件,并且服务器上没有发生更多的转换,那么我们就开始转换过程! 如果有一个视频文件已经被转换,那么我们将上传文件的信息放入数据库,然后等待另一个文件转换完成后开始正确转换

    队列是真正的队列-文件正在根据上载时间进行处理

    这是一个FFMpeg/MPlayer/MEncoder队列解决方案

    祝你一切顺利,
    伊利亚

    基于ethrbunny提供的好主意,我决定不使用Beanstalk或Resque来实现我的目标!毕竟我非常高兴!我敢打赌,对于那些试图将FFMpeg/MPlayer/MEncoder进程限制为服务器上唯一一个活动进程的人来说,这将是非常有用的,以便能够保持其他进程良好运行,例如httpd

    一步一步

  • 创建一个数据库,我称之为“编码队列”:

  • 在主上载文件中,触发转换过程的右侧:

    // Let's check if ffmpeg, mplayer, mencoder or mediainfo processes are running //   
    exec("ps ax | grep -v grep | grep ffmpeg", $ffmpeg);
    exec("ps ax | grep -v grep | grep mplayer", $mplayer);
    exec("ps ax | grep -v grep | grep mencoder", $mencoder);
    exec("ps ax | grep -v grep | grep mediainfo", $mediainfo);
    
    if(empty($ffmpeg) && empty($mplayer) && empty($mencoder) && empty($mediainfo)) {
    // As non of them are running we start conversion process //
    
       RunInBackground('convert.php', array($uploaded_file_name , $uploaded_video_id ), $log_file_path);
    
    } else {
    
    // As the ffmpeg or mplayer or mencoder or mediainfo is running we add the process to the queue into the database//
    
       //Connecting to database using ADOdb //             
    
       $sql = "INSERT INTO encoding_queue SET queue_timestamp = '" .time(). "', 
       uploaded_video_id = '" .mysql_real_escape_string($uploaded_video_id ). "',
       uploaded_file_name = '" .mysql_real_escape_string($uploaded_file_name ). "',
       log_file_path = '" .mysql_real_escape_string($log_file_path). "'";
       $conn->execute($sql);
    }
    
  • 在向数据库添加值之后,我们需要检查上一次转换是否完成,并准备开始新的转换!创建convert_queue.php文件并将其添加到CRON作业中,假设每5分钟一次

    <?php
    require('path/to/your/config.php');
    require('path/to/your/function.php');
    
    exec("ps ax | grep -v grep | grep ffmpeg", $ffmpeg);
    exec("ps ax | grep -v grep | grep mplayer", $mplayer);
    exec("ps ax | grep -v grep | grep mencoder", $mencoder);
    exec("ps ax | grep -v grep | grep mediainfo", $mediainfo);
    
    $sql = "SELECT * FROM encoding_queue ORDER BY queue_timestamp ASC LIMIT 1";
    $rs = $conn->execute($sql);
    $queue = $rs->getrows();
    if ( $conn->Affected_Rows() == 0 ) {
    die ("Error! There is no records in the database. Nothing to convert. Stopping...");
    }
    if (file_exists($config['VDO_DIR'] . '/' .$queue[0]['uploaded_file_name'])) {
      if(empty($ffmpeg) && empty($mplayer) && empty($mencoder) && empty($mediainfo)) {
         RunInBackground('convert.php', array($queue[0]['uploaded_file_name'], $queue[0]['uploaded_video_id']), $queue[0]['log_file_path']);
    } else {
         die ("Another conversion process is still in progress. Stopping...");
     }
      } else { 
         die ("Error! There is no video file ".$queue[0]['uploaded_file_name']." found. Nothing to convert. Stopping..."); }
     ?>
    
  • 那么我们得到了什么?如果上传的文件是目前唯一的文件,并且服务器上没有发生更多的转换,那么我们就开始转换过程! 如果有一个视频文件已经被转换,那么我们将上传文件的信息放入数据库,然后等待另一个文件转换完成后开始正确转换

    队列是真正的队列-文件正在根据上载时间进行处理

    这是一个FFMpeg/MPlayer/MEncoder队列解决方案

    祝你一切顺利,
    Ilia

    您认为使用db队列比使用Beanstalk或Resque更好吗?因为听起来您的部分问题在于控制Beanstalk/etc的运行实例数量。。这就是为什么我建议使用单独的转换机制来维护一个实例。我不知道BeanStalk或Resque,但听起来您的资源有限。您认为使用db queue比使用BeanStalk或Resque更好吗?因为您的部分问题是控制BeanStalk/etc的运行实例数。。这就是为什么我建议使用单独的转换机制来维护一个实例。我不知道BeanStalk或Resque,但听起来你的资源有限。