I’m trying to write a program that lets me convert a series of .mkv files with subtitle files into .mp4 files with the subs hardcoded.
Right now, the script I use is
ffmpeg -i input.mkv -vf subtitles=input.mkv output.mp4
This is fine, but it means I can only convert them one at a time, and it’s kind of a hassle because it means I have to fiddle with it every few minutes to set up the next one.
I have another script I use for converting .flac files to .mp3 files, which is
@ECHO OFF
FOR %%f IN (*.flac) DO (
echo Converting: %%f
ffmpeg -i "%%f" -ab 320k -map_metadata 0 "%%~nf.mp3"
)
echo Finished
PAUSE
Running that converts every single .flac folder into an .mp3 equivalent, with the same filename and everything.
I’ve tried to combine the above scripts into something like this:
@ECHO OFF
FOR %%f IN (*.mkv) DO (
echo Converting: %%f
ffmpeg -i "%%f" -vf subtitles=%%f "%%~nf.mp4"
)
echo Finished
PAUSE
but every time I do so, it returns errors like “invalid argument” or “unable to find a suitable output type”, or “error initializing filters”, or “2 frames left in the queue on closing” or something along those lines. I’ve swapped out subtitles=%%f for “subtitles-%%f” or subtitles=”%%f.mkv” and so on and so forth, and none of those give me what I want either. Sometimes it creates Empty .mp4 file containers with nothing in them, sometimes it does nothing at all.
I don’t really understand what exactly is happening under the hood in that flac->mp3 code, because I grabbed it from a different stackoverflow post years ago. All I know is that trying to copy that code and repurpose it into something else doesn’t work. Is this just an issue where I’ve fucked up the formatting of the code and not realized it, or is this a “ffmpeg can’t actually do that because of a weird technical issue” thing?
I also tried the code listed here, when Stackoverflow listed that as a possible duplicate, but that gave me similar errors, and I don’t really understand why!
Also, if it’s relevant, I’m running windows.
EDIT: running that code works perfectly as long as the input file is all one word. “Episode 04.mkv” causes the whole thing to break, but “Episode04.mkv” does not.
blaziken386 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.