ffmpeg-python command, using subprocess.Popen, raises FileNotFoundError: [WinError 2] The system cannot find the file specified
Specifically, when I try to run my code, I get this output and error message:
['Error', 'Stream', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_ffmpeg', '_filters', '_probe', '_run', '_utils', '_view', 'colorchannelmixer', 'compile', 'concat', 'crop', 'dag', 'drawbox', 'drawtext', 'filter', 'filter_', 'filter_multi_output', 'get_args', 'hflip', 'hue', 'input', 'merge_outputs', 'nodes', 'output', 'overlay', 'overwrite_output', 'probe', 'run', 'run_async', 'setpts', 'trim', 'unicode_literals', 'vflip', 'view', 'zoompan']
.env
app.py
common_components.py
docker-compose.yml
dockerfile
image_rag.py
rag_kernel.py
requirements.txt
video.mp4
whisper_test.py
Traceback (most recent call last):
File "...\IdeaProjects\RAG Homestyle\SRC\RAG Pipeline\Rag-Chat-API\API_V7\whisper_test.py", line 20, in
wav_file = convert_mp4_to_wav(mp4_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "..\IdeaProjects\RAG Homestyle\SRC\RAG Pipeline\Rag-Chat-API\API_V7\whisper_test.py", line 9, in convert_mp4_to_wav
ffmpeg.input(input_file).output(output_file, format="wav", acodec="pcm_s16le", ac=1, ar="16000").run(overwrite_output=True)
File "...\IdeaProjects\RAG Homestyle\.venv\Lib\site-packages\ffmpeg\_run.py", line 313, in run
process = run_async(
^^^^^^^^^^
File "...\IdeaProjects\RAG Homestyle\.venv\Lib\site-packages\ffmpeg\_run.py", line 284, in run_async
return subprocess.Popen(
^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "...\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
The last line says the file doesn’t exist in the specified path, but I made sure it is in the same folder as the code I am running it in. This is supported by the output above the error message where I have it print the the paths of all files in the current directory. So why am I getting this error?
This is the code I tried to run:
import whisper
import ffmpeg
print(dir(ffmpeg)) # This should list 'input', 'output', etc.
# List all files in the current directory
for file in os.listdir('.'):
if os.path.isfile(file): # Ensure it's a file, not a directory
print(file)
# Convert MP4 to WAV
def convert_mp4_to_wav(input_file, output_file="audio.wav"):
ffmpeg.input(input_file).output(output_file, format="wav", acodec="pcm_s16le", ac=1, ar="16000").run(overwrite_output=True)
return output_file
# Transcribe using Whisper
def transcribe_audio(file_path, model_size="base"):
model = whisper.load_model(model_size) # Choose from "tiny", "base", "small", "medium", "large"
result = model.transcribe(file_path)
return result["text"]
# Main Execution
mp4_file = "./video.mp4"
wav_file = convert_mp4_to_wav(mp4_file)
transcription = transcribe_audio(wav_file)
print("Transcription:\n", transcription)
To be clear, the video.mp4 IS in the directory of the code, so I don’t know why it thinks it isn’t. Is this perhaps some property of IntelliJ? or something else?
I appreciate any ideas or answers you can give! Thank you.
PS the whisper library I am using is openai-whisper and the ffmpeg is ffmpeg-python library.
Read more here: Source link
