0

hopefully this will be a relatively straightforward question.

I have a directory of files. The files are mkv files that contain .vtt subtitles. I want to change the vtt subtitles into .srt subtitles. Ideally the mkv files should retain the same names at the end of the process.

I have this Bash command that uses ffmpeg:

ffmpeg -i input.mkv -c copy -c:s srt out.mkv

This command works on an individual file, in terms of giving me a new file with the correct srt subtitles muxed in.

However it does not:

  • let me wildcard the mkv file (I have to specify the input.mkv file)
  • let me keep the name of the original mkv file

Could someone help please? I'm thinking it would be a relatively simple Bash loop (for x in *.mkv...) but any help would be most gratefully received. I really want the output files to have the same name as the input files at the end of the process. Thank you.

ktb
  • 35
  • 5
  • Adapted from [How do you convert an entire directory with ffmpeg?](https://stackoverflow.com/a/33766147/): `mkdir new && for i in *.mkv; do ffmpeg -i "$i" -map 0 -c copy -c:s srt "new/${i%.*}.mkv"; done` – llogan Jan 31 '21 at 00:03
  • That's awesome, thanks a lot!! I have added a couple of extra commands on to your answer to: 1) delete the original .mkv files (so that double the storage space is not used, 2) move the new srt-muxed .mkv files into the cwd, 3) delete the "new" directory. As follows: `mkdir new && for i in *.mkv; do ffmpeg -i "$i" -map 0 -c copy -c:s srt "new/${i%.*}.mkv" ; done && rm -Rfv ./*.mkv && rsync -aPrh --append ./new/*.mkv . && rm -Rfv ./new` – ktb Jan 31 '21 at 00:41

0 Answers0