On Windows 10, what's a simple command to to mux multiple video and subtitle files in sequence to different sequential filenames using ffmpeg? I'm manually doing
ffmpeg -i "moviename part 1.mp4" -i "moviename part 1.srt" -c copy "temp01.mkv"
ffmpeg -i "moviename part 2.mp4" -i "moviename part 2.srt" -c copy "temp02.mkv"
ffmpeg -i "moviename part 3.mp4" -i "moviename part 3.srt" -c copy "temp03.mkv"
ffmpeg -i "moviename part 4.mp4" -i "moviename part 4.srt" -c copy "temp04.mkv"
ffmpeg -i "moviename part 5.mp4" -i "moviename part 5.srt" -c copy "temp05.mkv"
ffmpeg -i "moviename part 6.mp4" -i "moviename part 6.srt" -c copy "temp06.mkv"
ffmpeg -i "moviename part 7.mp4" -i "moviename part 7.srt" -c copy "temp07.mkv"
ffmpeg -i "moviename part 8.mp4" -i "moviename part 8.srt" -c copy "temp08.mkv"
ffmpeg -i "moviename part 9.mp4" -i "moviename part 9.srt" -c copy "temp09.mkv"
ffmpeg -i "moviename part 10.mp4" -i "moviename part 10.srt" -c copy "temp10.mkv"
ffmpeg -i "moviename part 11.mp4" -i "moviename part 11.srt" -c copy "temp11.mkv"
.
.
.
ffmpeg -i "moviename part 99.mp4" -i "moviename part 99.srt" -c copy "temp99.mkv"
for now, but it's tiring. I found this command that muxes the files
for %%a in ("*.mp4") do ffmpeg -i "%%~na.mp4" -i "%%~na.srt" -c copy "%%~na.mkv"
but it outputs the same filenames moviename part 1.mkv, moviename part 2.mkv, moviename part 3.mkv and so forth instead of temp01.mkv, temp02.mkv, temp03.mkv, etc. like I wanted.
答案1
What's a simple command to to mux multiple video and subtitle files in sequence?
Use for /l
:
@echo off
setlocal enabledelayedexpansion
for /l %%a in (1,1,99) do (
set _count=00%%a
ffmpeg -i "moviename part %%a.mp4" -i "moviename part %%a.srt" -c copy "temp!_count:~-2!.mkv"
)
endlocal
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- enabledelayedexpansion - Delayed Expansion will cause variables to be expanded at execution time rather than at parse time.
- for /l - Conditionally perform a command for a range of numbers.
- set - Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.
- variables - Extract part of a variable (substring).