How do I execute a command prompt command from python?

Viewed 105

I have the following command and I execute it in command prompt:

ffmpeg.exe -i input.mkv -i output.mkv -lavfi psnr=stats_file=psnrmkv.txt -f null -

this command computes PSNR between two files and saves the result in pnsrmkv.txt but I have to enter this command for each video and I have more than 200 videos:(. now I am trying to execute it in python. each time I have to change the name of the input and output video and PSNR text file. is it any way to implement a command line in python? could you please help me with this issue? I am a beginner and if you have any code or link to explain sth like this, I will be really thankful. I am using windows and python 3.7. can subprocess help with this problem?

I used the following code, but it produces the error:

import subprocess as s
s.call(["command.exe", "ffmpeg.exe -i E:\mpeg_file\input.mkv -i E:\mpeg_file\2.mkv -lavfi psnr=stats_file=psnrmkv.txt -f null -"])

the error:

Traceback (most recent call last):

File "", line 2, in s.call(["command.exe", "ffmpeg.exe -i E:\mpeg_file\input.mkv -i E:\mpeg_file\2.mkv -lavfi psnr=stats_file=psnrmkv.txt -f null -"])

File "D:\software\Anaconda3\envs\py37\lib\subprocess.py", line 287, in call with Popen(*popenargs, **kwargs) as p:

File "D:\software\Anaconda3\envs\py37\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 105, in init super(SubprocessPopen, self).init(*args, **kwargs)

File "D:\software\Anaconda3\envs\py37\lib\subprocess.py", line 729, in init restore_signals, start_new_session)

File "D:\software\Anaconda3\envs\py37\lib\subprocess.py", line 1017, in _execute_child startupinfo)

FileNotFoundError: [WinError 2] The system cannot find the file specified

0 Answers
Related