1

So im using ffmpeg to resize a video, and this takes a little while so before the code continues i have to wait for the cmd to close. I havent been able to find a solution and i hope someone that actually knows their stuff can teach me a way. im probably just doing something retarded... Anyway i have tried multiple things like using subprocess.Propen() and then using pope() to see when it doesnt return "None" also tried stuff like subprocess.run() with subprocess.CompletedProcess() but i just cant get it to work could someone please care to explain if there is a way to do this and that im just doing it wrong? :)

Here is an example of what I tried

p = subprocess.Popen("start ffmpeg -y -i "+DIR+"/post.mp4 -vf scale="+str(nW)+":"+str(nH)+" "+DIR+"/post_r.mp4", shell=True)
    while p.poll() is None:
        time.sleep(1)
        print("alive")
    else:
        print("cmd exited")

Also whenever i put shell=False it just breaks instantly and I get this error: FileNotFoundError: [WinError 2] The system cannot find the file specified

1 Answer 1

1

Don't use subprocess.Popen() if you simply need the process to run while you wait. Legacy subprocess.call() or the modern subprocess.run() are designed exactly for this use case.

With shell=False you need to split the command line into a list yourself. You can call on shlex.split() for convenience, but it's not hard to do yourself.

subprocess.run(['ffmpeg', '-y', '-i', DIR+"/post.mp4",
    '-vf', 'scale=' + str(nW) + ":" + str(nH), DIR+"/post_r.mp4"])

The start looks like you are on Windows and of course then start is a feature of the shell as well; if you don't have a shell, start is not available (but also not useful).

Sign up to request clarification or add additional context in comments.

2 Comments

... much like Windows itself, I'm tempted to add, but I digress. Maybe see also stackoverflow.com/a/51950538/874188 which is for U*x platforms primarily, but nevertheless provides a lot more detail around these issues for Windows as well.
I did actually try run() and a combination of some other stuff but i just couldnt figure it out. Anyways works like a charm now thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.