FFmpeg命令合并失败及批量处理多文件问题求助
Hey there! Let's tackle your two issues one by one—first fixing the combined FFmpeg command, then sorting out the batch processing for all 314 files.
问题1:合并命令失效的原因
Your problem lies with the -map 0 parameter! This tells FFmpeg to only map all streams from the first input file (your .mp4), completely ignoring the subtitle stream from the second input (.srt). That's why only the audio disposition change worked, and the subtitles never made it into the output.
修正后的命令
You need to add the subtitle stream to the mapping, and adjust the parameters to ensure everything is included. Try this command instead:
ffmpeg.exe -i "Input 1.mp4" -i "Input 2.srt" -map 0 -map 1 -c copy -disposition:a:0 0 -disposition:a:1 default -c:s mov_text -metadata:s:s:0 language=fr "Output 1.mp4"
关键修改说明:
-map 1: This new parameter includes the stream from your second input file (the .srt subtitle) in the output.- The order of parameters works here because FFmpeg prioritizes stream-specific encoding settings (like
-c:s mov_text) over global ones (-c copy), so the subtitles will be converted to themov_textformat required for MP4 embedding, while all other streams are copied directly.
Run this command, and your output file should have both the default French audio track and embedded French soft subtitles.
问题2:批量处理314个文件
Manually renaming files for 314 videos is definitely tedious—here are solutions for both Windows and Linux/macOS:
Windows 批处理方案
Create a .bat file (e.g., batch_process.bat) in the folder containing your videos and subtitles, with this content:
@echo off setlocal enabledelayedexpansion :: Loop through all .mp4 files in the directory for %%f in (*.mp4) do ( :: Assume subtitle file has the same name as the video (e.g., "Video.mp4" → "Video.srt") set "subtitle=%%~nf.srt" :: Output files will have a "processed_" prefix to avoid overwriting originals ffmpeg.exe -i "%%f" -i "!subtitle!" -map 0 -map 1 -c copy -disposition:a:0 0 -disposition:a:1 default -c:s mov_text -metadata:s:s:0 language=fr "processed_%%~nf.mp4" ) echo All files processed successfully! pause
- If your subtitle files have a different naming pattern (e.g., "Video.mp4" → "Video_fr.srt"), modify the
set "subtitle=%%~nf.srt"line to match (likeset "subtitle=%%~nf_fr.srt"). - The
processed_prefix ensures you don't accidentally overwrite your original files.
Linux/macOS Shell 脚本方案
Create a .sh file (e.g., batch_process.sh) in your target directory, with this content:
#!/bin/bash # Loop through all .mp4 files for f in *.mp4; do # Extract the filename without the .mp4 extension filename="${f%.*}" # Match with the corresponding subtitle file subtitle="${filename}.srt" # Run the FFmpeg command, outputting to a prefixed file ffmpeg -i "$f" -i "$subtitle" -map 0 -map 1 -c copy -disposition:a:0 0 -disposition:a:1 default -c:s mov_text -metadata:s:s:0 language=fr "processed_${f}" done echo "All files processed successfully!"
Then make the script executable and run it:
chmod +x batch_process.sh ./batch_process.sh
备注:内容来源于stack exchange,提问作者Dimitri




