乐闻世界logo
搜索文章和话题

How do you convert an entire directory with ffmpeg?

1个答案

1

When using FFmpeg to convert video files within an entire directory, it is typically necessary to write a script that iterates through all files in the directory and applies the FFmpeg command to each file. Below, I will explain step by step how to achieve this on different operating systems.

1. In Windows

On Windows, you can use a batch script to accomplish this. Here is an example script that converts all .mp4 files in the directory to .avi format. First, open Notepad and paste the following code:

batch
@echo off for %%a in (*.mp4) do ffmpeg -i "%%a" "%%~na.avi" pause

Save this file as convert.bat (ensure the file type is set to 'All Files' and the encoding is ANSI). Place this batch file in the directory containing your video files, then double-click to execute it.

2. In Linux or Mac OS

On Linux or Mac OS, you can use a shell script to accomplish this. Here is an example script that converts all .mp4 files in the directory to .avi format. Open the terminal and create a new script file using a text editor:

bash
#!/bin/bash for file in *.mp4 do ffmpeg -i "$file" "${file%.mp4}.avi" done

Save this script as convert.sh, then in the terminal, run the following command to grant execute permissions to the script file:

bash
chmod +x convert.sh

After that, execute the script by running the following command in the directory containing the video files:

bash
./convert.sh

Notes

  • Ensure FFmpeg is installed on your system. Verify this by entering ffmpeg -version in the terminal or command prompt.
  • The above scripts process only MP4 files. To handle other formats, modify the pattern accordingly (e.g., *.avi, *.mov, etc.).
  • For more complex conversion settings, such as specifying codecs or adjusting video quality, add relevant options to the FFmpeg command.

These steps should help you batch convert video files in a directory. If you have specific requirements or encounter issues, feel free to ask further.

2024年8月9日 01:44 回复

你的答案