I have a python script that runs on my web server. The main function is called when it returns, it just sleeps for a few seconds and is called again. The goal is to pick up all the new uploaded videos uploaded by users and convert them to a website, pull out the middle frame as an image and a bunch of other funky stuff. I am using an external ffmpeg call. Below is a snippet of code, as I call it.
duration = output[durationIndex+10:durationIndex+18] durationBits = duration.split(":") lengthInSeconds = (int(durationBits[0])*60*60) + (int(durationBits[1])*60) + (int(durationBits[2])) child = subprocess.Popen(["ffmpeg","-y","-i",sourceVideo,"-f","mjpeg","-vframes","1","-ss",str(lengthInSeconds/2),destination], shell=True, stderr=subprocess.PIPE) output = "" while True: out = child.stderr.read(1) if out == '' and child.poll() != None: break if out != '': output += out updateSQL = "update `videos_graduatevideo` set thumbnail = '" + str(destination) + "' where `original_video` = '" + sourceVideo + "'" cursor.execute(updateSQL)
This script runs on a computer running Windows, but I will most likely deploy it on a Unix system when it is complete.
Problem. I need this python script to continue working. If something goes wrong when ffmpeg and my script freeze, the videos uploaded by the user will just be in a wait state until I mix up the python script. I know that the specific mov file that I have, ffmpeg hangs indefinitely. Is there any way to check how long the process has been running and then kill it if it runs too long?
Drlazer
source share