Why is this Popen with threading not working?
up vote
0
down vote
favorite
I wrote a little tkinter GUI to handle 4 inputs to ffmpeg. Since the subprocess will take some time i want to status the process. Therefore I use threading so tkinter doesn't freeze while the subprocess is executed.
My problem is that with threading the ffmpeg command outputs the destination file with 0kb and nothing is anymore written to the file. If I use my function without threading everything works, but the GUI is freezing.
Here is the main part of the code:
def ffmpeg(v0,v1,v2,v3):
cmd = [ path+'ffmpeg.exe',"-y","-i",v0,"-i",v1,"-i",v2,'-i',v3,'-filter_complex',"[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack,format=yuv420p[v]",'-map',"[v]","out.mp4"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
inpu = process.stderr.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(output.strip()) # HERE i will insert into tkinter textfield
rc = process.poll()
def buttonClick(v0,v1,v2,v3):
#ffmpeg(v0,v1,v2,v3) # This line works
t = threading.Thread(target=ffmpeg,args=(v0,v1,v2,v3,)) #This doesn't work
t.start()
#t.join()
#tkvar list elements are absolute paths to the videofiles
submitButton = Button(mainframe, text="Process Video", command=lambda: buttonClick(tkvar[0].get(),tkvar[1].get(),tkvar[2].get(),tkvar[3].get()))
submitButton.grid(row = 7, column =3)
Why is my thread not working?
python multithreading tkinter ffmpeg subprocess
add a comment |
up vote
0
down vote
favorite
I wrote a little tkinter GUI to handle 4 inputs to ffmpeg. Since the subprocess will take some time i want to status the process. Therefore I use threading so tkinter doesn't freeze while the subprocess is executed.
My problem is that with threading the ffmpeg command outputs the destination file with 0kb and nothing is anymore written to the file. If I use my function without threading everything works, but the GUI is freezing.
Here is the main part of the code:
def ffmpeg(v0,v1,v2,v3):
cmd = [ path+'ffmpeg.exe',"-y","-i",v0,"-i",v1,"-i",v2,'-i',v3,'-filter_complex',"[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack,format=yuv420p[v]",'-map',"[v]","out.mp4"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
inpu = process.stderr.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(output.strip()) # HERE i will insert into tkinter textfield
rc = process.poll()
def buttonClick(v0,v1,v2,v3):
#ffmpeg(v0,v1,v2,v3) # This line works
t = threading.Thread(target=ffmpeg,args=(v0,v1,v2,v3,)) #This doesn't work
t.start()
#t.join()
#tkvar list elements are absolute paths to the videofiles
submitButton = Button(mainframe, text="Process Video", command=lambda: buttonClick(tkvar[0].get(),tkvar[1].get(),tkvar[2].get(),tkvar[3].get()))
submitButton.grid(row = 7, column =3)
Why is my thread not working?
python multithreading tkinter ffmpeg subprocess
Move this lineinpu = process.stderr.readline()
, outside thewhile
. It blocks untils the process finished.
– stovfl
Nov 6 at 15:10
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wrote a little tkinter GUI to handle 4 inputs to ffmpeg. Since the subprocess will take some time i want to status the process. Therefore I use threading so tkinter doesn't freeze while the subprocess is executed.
My problem is that with threading the ffmpeg command outputs the destination file with 0kb and nothing is anymore written to the file. If I use my function without threading everything works, but the GUI is freezing.
Here is the main part of the code:
def ffmpeg(v0,v1,v2,v3):
cmd = [ path+'ffmpeg.exe',"-y","-i",v0,"-i",v1,"-i",v2,'-i',v3,'-filter_complex',"[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack,format=yuv420p[v]",'-map',"[v]","out.mp4"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
inpu = process.stderr.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(output.strip()) # HERE i will insert into tkinter textfield
rc = process.poll()
def buttonClick(v0,v1,v2,v3):
#ffmpeg(v0,v1,v2,v3) # This line works
t = threading.Thread(target=ffmpeg,args=(v0,v1,v2,v3,)) #This doesn't work
t.start()
#t.join()
#tkvar list elements are absolute paths to the videofiles
submitButton = Button(mainframe, text="Process Video", command=lambda: buttonClick(tkvar[0].get(),tkvar[1].get(),tkvar[2].get(),tkvar[3].get()))
submitButton.grid(row = 7, column =3)
Why is my thread not working?
python multithreading tkinter ffmpeg subprocess
I wrote a little tkinter GUI to handle 4 inputs to ffmpeg. Since the subprocess will take some time i want to status the process. Therefore I use threading so tkinter doesn't freeze while the subprocess is executed.
My problem is that with threading the ffmpeg command outputs the destination file with 0kb and nothing is anymore written to the file. If I use my function without threading everything works, but the GUI is freezing.
Here is the main part of the code:
def ffmpeg(v0,v1,v2,v3):
cmd = [ path+'ffmpeg.exe',"-y","-i",v0,"-i",v1,"-i",v2,'-i',v3,'-filter_complex',"[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack,format=yuv420p[v]",'-map',"[v]","out.mp4"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
inpu = process.stderr.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(output.strip()) # HERE i will insert into tkinter textfield
rc = process.poll()
def buttonClick(v0,v1,v2,v3):
#ffmpeg(v0,v1,v2,v3) # This line works
t = threading.Thread(target=ffmpeg,args=(v0,v1,v2,v3,)) #This doesn't work
t.start()
#t.join()
#tkvar list elements are absolute paths to the videofiles
submitButton = Button(mainframe, text="Process Video", command=lambda: buttonClick(tkvar[0].get(),tkvar[1].get(),tkvar[2].get(),tkvar[3].get()))
submitButton.grid(row = 7, column =3)
Why is my thread not working?
python multithreading tkinter ffmpeg subprocess
python multithreading tkinter ffmpeg subprocess
edited Nov 6 at 10:37
asked Nov 6 at 10:27
user2853437
192214
192214
Move this lineinpu = process.stderr.readline()
, outside thewhile
. It blocks untils the process finished.
– stovfl
Nov 6 at 15:10
add a comment |
Move this lineinpu = process.stderr.readline()
, outside thewhile
. It blocks untils the process finished.
– stovfl
Nov 6 at 15:10
Move this line
inpu = process.stderr.readline()
, outside the while
. It blocks untils the process finished.– stovfl
Nov 6 at 15:10
Move this line
inpu = process.stderr.readline()
, outside the while
. It blocks untils the process finished.– stovfl
Nov 6 at 15:10
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
The problem was that
process.stdout.readline()
Is always empty since ffmpeg writes always everything to stderr.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The problem was that
process.stdout.readline()
Is always empty since ffmpeg writes always everything to stderr.
add a comment |
up vote
0
down vote
accepted
The problem was that
process.stdout.readline()
Is always empty since ffmpeg writes always everything to stderr.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The problem was that
process.stdout.readline()
Is always empty since ffmpeg writes always everything to stderr.
The problem was that
process.stdout.readline()
Is always empty since ffmpeg writes always everything to stderr.
answered Nov 11 at 16:30
user2853437
192214
192214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53170019%2fwhy-is-this-popen-with-threading-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Move this line
inpu = process.stderr.readline()
, outside thewhile
. It blocks untils the process finished.– stovfl
Nov 6 at 15:10