开发者

Getting progress for two ongoing processes

开发者 https://www.devze.com 2023-03-20 16:14 出处:网络
When a user uploads a video, I do two conversions. A high res, and a low res. I use popen() in the upload processing script and run the linux ffmpeg conversion command for each conversion. When I used

When a user uploads a video, I do two conversions. A high res, and a low res. I use popen() in the upload processing script and run the linux ffmpeg conversion command for each conversion. When I used to have just one conversion, I simply calculated the progress based on the output of popen and put it in a database table (conversion_progress), and updated it as the process outputted results.

Now what I want to do is insert two entries into my conversion_progress table and calculate the difference of each progress. However when I use a select statement, since both entries have the same vid_id I cannot distinguish between each process since two rows are returned. I do not need need to and I would just like to obtain th开发者_开发问答e average of both rows. Anyone have any suggestions on this?

$sql = 'SELECT progress from conv_progress WHERE vid_id=?';
$stmt4 = $conn->prepare($sql);
$result=$stmt4->execute(array('123')) or die(print_r($db->errorInfo(), true));
while ($row=$stmt4->fetch(PDO::FETCH_ASSOC)){
$data['progress']=$row['progress']; 
}

    $out = json_encode($data);
    print $out;

returns 5070 meaning one upload is 50% and another is 70%. Can I use foreach or something to do a calculation on this?


You might want to let MySQL take the average:

$sql = 'SELECT AVG(progress) AS progress from conv_progress WHERE vid_id=? GROUP BY vid_id';
0

精彩评论

暂无评论...
验证码 换一张
取 消