Hi


I am brand new to python so not much of a clue what im doing to be honest.
I have spent the morning googling like a nutter but im having a hard old time finding a solution to my problem.

Ill start by explaining the problem as i experience it and with a bit of luck somone reading this will be able to help!

Im trying to encode a live stream using ffmpeg and its a never ending task but occasionally ffmpeg either looses connection to the source stream or something comes along that causes a problem

I have been doing this for a while now using windows and normally what happens is ffmpeg will self terminate if there is a problem and using a simple batch file to call the process again will start if off running again. Simple!

HOWEVER, using Linux, i dont seem to have such luxuries, when ffmpeg "craps out", the process tends to just sit there doing noting!

No amount of -reconnect , or other such ffmpeg commands helps



What i had hoped to be able to do was check for the process id and if it was no longer running, run my command again but thats pointless if the process just sits there doing nothing

I thought about using something like htop that would tell me the cpu usage of a process so i might determine if the process was just hanging or not

i have included my ffmpeg.py script below but as i have to pay for the source streams i have not been able to include the real source, I hope you understand that.


if anyone has any clever way to determine what ffmpeg is doing, please let me know.

Thanks

Code:
import subprocess
import time



command = [
'ffmpeg',
'-nostdin',
'-reconnect', '1', 
'-y', 
'-thread_queue_size', '5512', 
'-i', 'http://somesite.fake/manager/sourcestream.ts', 
'-r', '25', 
'-s', '858x480',  
'-profile:v', 'baseline', 
'-level', '3.0', 
'-c:v', 'h264', 
'-preset:v', 'superfast', 
'-crf', '20', 
'-maxrate', '1M', 
'-bufsize', '2M', 
'-use_localtime', '1',  
'-segment_list_flags', 
'+live', 
'-strftime', '1', 
'-start_number', '0', 
'-hls_flags', 
'+split_by_time', 
'-hls_time', '8', 
'-hls_list_size', '6', 
'-hls_segment_filename', '/var/www/html/live/14/file-%Y%m%d-%s.ts', 
'-f', 'hls', 
'/var/www/html/live/14/playlist.m3u8'
]
p = subprocess.Popen(command, close_fds=True, stdout=subprocess.PIPE)

pid = p.pid
print ('###############################################################')
print (pid)
print ('###############################################################')