Check status of background convert for videos

hello guys

its been a while since my last question here :stuck_out_tongue:

am working right now on PHP script to upload and convert video files to several resolutions ( 360 - 720 ),

here a piece of my php code to convert

move_uploaded_file($file_tmp, 'upload/'.$fileName);
add_to_queue($time,"360-".$fileName,$status="pending");
//where add_to_queue is simple function to add these information to queue table
$cmd = 'ffmpeg -i upload/'.$fileName.' -vf scale=480:360 -c:v libx264 -q:v 1 -strict experimental -c:a aac -b:a 160k convert/360-'.$fileName.' >/dev/null 2>/dev/null &';
shell_exec($cmd);

now everything here is OK and working great, but I need to check if the
video encoding is completed and update the ā€œstatusā€ column in queue
table set it to complete and delete original file in ā€œuploadā€ directory.

another thing , I want only 5 videos for example to be encoded at same time to save server resources.

Could you use proc_open() instead of shell_exec(), and then use proc_get_status() to figure out how itā€™s going? Or instead of calling ffmpeg directly, embed it in a batch file of whatever kind your OS allows, and have the final part of that batch file execute a query that updates the status column.


[off topic] Have you considered uploading the largest video to YouTube and let them handle the conversion? [/off topic]

You could use proc_open() as droopsnot said, and you could also output the response of the ffmpeg call in the cmd to a file and then parse the output for the status. And there is this function proc_close() which returns the result of the command, but i donā€™t know what will happen if any error occur.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.