0

I have a folder with episodes called ep and a folder with subtitles called sub
Each episode has corresponding subtitles and i need to bulk add them with ffmpeg.

I've read that i can add subtitles with the following command:

ffmpeg -i video.avi -vf "ass=subtitle.ass" out.avi

But that only does it one file at a time.
Is there a bulk variant?

Some useful info:
ls ep prints

<series name> - Ep<episode number>.mkv

ls sub prints

<series name> - Ep<episode number>.ass
Soft Waffle
  • 356
  • 1
  • 12
  • Not possible with ffmpeg by itself. Can be done with a *for loop*. Answer depends on your OS. – llogan May 20 '20 at 17:39
  • @llogan yeah i figured i'd make it with a script, i created it. – Soft Waffle May 20 '20 at 17:52
  • Sounds like you found a solution. Consider adding it as an answer to your question, or mark it as a duplicate of [How do you convert an entire directory with ffmpeg?](https://stackoverflow.com/q/5784661/) if you think one of those answers suffices. – llogan May 20 '20 at 18:01

1 Answers1

0

I made a small sh script that will do this:

#!/bin/sh

SUBTITLES_FOLDER=sub
EPISODES_FOLDER=ep
OUTPUT_FOLDER=out

for i in "$EPISODES_FOLDER"/*.mkv; do
    sub="$SUBTITLES_FOLDER/$(echo "$i" | sed 's/mkv$/ass/')"
    ffmpeg -i "$i" -i "$sub" -c:v copy -c:a copy -c:s copy -map 0:0 -map 0:1 -map 1:0 -y "$OUTPUT_FOLDER/$i" &
done

Note the '&' at the end of the ffmpeg command: it makes sure ffmpeg runs in parallel (is this the correct term for it?)

You may want to modify the file extensions and check if ffmpeg supports subtitles with your format, the rest will be done by itself.

Soft Waffle
  • 356
  • 1
  • 12