使用Python压缩视频时遇'ffmpeg可执行文件未找到'错误,求解决
Hey there! That error pops up because ffmpy is just a Python wrapper for ffmpeg—it doesn’t include the actual ffmpeg tool itself. Let’s walk through how to fix this step by step:
1. Install ffmpeg on your system
First, you need to have ffmpeg installed locally. Here’s how to do it for different operating systems:
- Windows: Download the latest build from the official ffmpeg site, extract the zip file, then add the
binfolder (whereffmpeg.exelives) to your system’sPATHenvironment variable. Alternatively, if you use Chocolatey, runchoco install ffmpegin Command Prompt. - macOS: Use Homebrew—run
brew install ffmpegin Terminal. - Linux (Debian/Ubuntu): Run
sudo apt update && sudo apt install ffmpegin Terminal. For Fedora, usesudo dnf install ffmpeg.
2. Verify ffmpeg is accessible
Open a new terminal/Command Prompt window and run:
ffmpeg -version
If this outputs ffmpeg’s version info, you’re good to go. If not, double-check that the ffmpeg path is added to your system’s PATH.
3. Update your Python code (and fix the incomplete line!)
Your original code cuts off at ff = ffmpy...—here’s the full corrected version, plus an optional fix if ffmpeg still isn’t found:
import ffmpy input_name = input("Enter name of input file: ") crf = int(input("Enter constant rate factor between 18 and 24: ")) output_name = input("Enter output file name: ") inp = {input_name: None} outp = {output_name: '-vcodec libx264 -crf %d'%crf} # If ffmpeg is in PATH, this works: ff = ffmpy.FFmpeg(inputs=inp, outputs=outp) # If it's NOT in PATH, specify the full path to ffmpeg: # ff = ffmpy.FFmpeg( # executable='/full/path/to/ffmpeg', # e.g., 'C:/ffmpeg/bin/ffmpeg.exe' on Windows # inputs=inp, # outputs=outp # ) ff.run()
Why this works
By installing ffmpeg and making sure it’s accessible via your system’s PATH, ffmpy can find the executable it needs to run the compression. If PATH isn’t set up correctly, explicitly pointing to the ffmpeg binary in your code will bypass that issue.
内容的提问来源于stack exchange,提问作者Ahmed Mohamed

