1

I am getting error FileNotFoundError: [WinError 2] The system cannot find the file specified in subprocess python. I searched it on stack overflow but don't find any answer relating to my situation. Basically, I am trying to calculate duration of a video through python code. I searched it on stack overflow and found a piece of code. When I tried to execute this code, I am getting FileNotFoundError: [WinError 2] The system cannot find the file specified. I check a file and its path it is correct and the file is correct. Here is a code I am trying to run and I got it from here.

import subprocess

def get_length(filename):
    result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
                             "format=duration", "-of",
                             "default=noprint_wrappers=1:nokey=1", filename],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT)
    return float(result.stdout)

get_length("video.avi")

Any suggestion will be appreciated. Here is full error:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-17-8d1ce3720e37> in <module>
      9     return float(result.stdout)
     10 
---> 11 get_length("video.avi")

<ipython-input-17-8d1ce3720e37> in get_length(filename)
      6                              "default=noprint_wrappers=1:nokey=1", filename],
      7         stdout=subprocess.PIPE,
----> 8         stderr=subprocess.STDOUT)
      9     return float(result.stdout)
     10 

~\Anaconda3\envs\FYP\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    421         kwargs['stdin'] = PIPE
    422 
--> 423     with Popen(*popenargs, **kwargs) as process:
    424         try:
    425             stdout, stderr = process.communicate(input, timeout=timeout)

~\Anaconda3\envs\FYP\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
    727                                 c2pread, c2pwrite,
    728                                 errread, errwrite,
--> 729                                 restore_signals, start_new_session)
    730         except:
    731             # Cleanup if the child failed starting.

~\Anaconda3\envs\FYP\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1015                                          env,
   1016                                          os.fspath(cwd) if cwd is not None else None,
-> 1017                                          startupinfo)
   1018             finally:
   1019                 # Child is launched. Close the parent's copy of those pipe

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

I am confused that why I am getting this error although my this code is working perfectly.

import subprocess
process = subprocess.Popen(['vlc', 'video.avi'], 
                       stdout=subprocess.PIPE,
                       universal_newlines=True)
FAHAD SIDDIQUI
  • 631
  • 4
  • 22

0 Answers0