I'm trying to capture the output with ffmpeg and I've noticed that this binary throws the outputs by the stderr
but I realized that when the file already exists it is thrown by stdout but here I have a problem and that the script it gets stuck, my purpose is to capture the outputs without waiting for the process to finish both the stdout
and the stdin
but I can not do it.
If the file does not exist everything works very well but if it exits then I am here with the problem.
from subprocess import PIPE,Popen
from time import sleep
import subprocess
p = Popen(['ffmpeg','-i','rufian.mp4','-f','mp3','rufiannn.mp3'],stdin=PIPE,\
stdout=PIPE,\
stderr=PIPE,universal_newlines=True)
while p.poll() == None:
err = p.stderr.readline()
print(err)
the problem is that once the file exists the script stops because the console says if you want to overwrite it and I can not capture this in any way even with stdout.readline()
, with communicate it does not help me because it always waits for the process finish.
Is there a solution for this? for now all I find is having to program code to check if it exists.