0

I have this command using ffmpeg

root@ubuntu-4cpu-8gb-sg-sin1:/home/jaac/torrents/rtorrent/dots# ffmpeg -i Title.NF.WEB-DL.DDP2.0.x264-Ao.mkv -map 0:7 indo16.srt

That will rip 1 sub (Indonesia region)

How to rip it in batch? I have 17 files in dots folder

Thanks

jaac
  • 5
  • 3
  • Could you please elaborate your question? – Saikat Saha May 10 '20 at 10:20
  • Hi, I want to rip all Indonesian subtitle in folder dots. The command I post is for 1 file. I need a command that would do rip all the subtitles in the folder. – jaac May 11 '20 at 00:21

3 Answers3

0

Run these commands:

cd /home/jaac/torrents/rtorrent/dots
for f in *.mkv; do ffmpeg -i "$f" -map 0:s:m:language:ind "${f%.*}.srt"; done

Adapted from How do you convert an entire directory with ffmpeg?

What the -map option is doing: 0:s:m:language:ind is input #0: subtitles:metadata:language:indonesian. Which means it chooses all subtitle streams from the input that have Indonesian language metadata.

If you get error:

Stream map '0:s:m:language:ind' matches no streams.
To ignore this, add a trailing '?' to the map.

You can ignore it. Just a message telling you there is no subtitle stream with Indonesian language metadata in that particular input.

llogan
  • 87,794
  • 21
  • 166
  • 190
  • Hi thanks for your reply. I got error -bash: syntax error near unexpected token `do' . Do I need to includer the ";? – jaac May 11 '20 at 00:19
  • 1
    @jaac You are using Linux? What is the output of `echo "$SHELL"`? – llogan May 11 '20 at 17:45
  • Yes I'm using Ubunto 16. The output from echo "$SHELL" is /bin/bash – jaac May 11 '20 at 19:54
  • Modify the command to Thanks guys for helping me out. I use this command to batch rip the subtitle: #!/bin/bash cd /home/jaac/torrents/rtorrent/dots || exit for f in *.mkv; do ffmpeg -i "$f" -map 0:5:s:m:language:id "${f%.*}.srt"; done – jaac May 11 '20 at 21:22
  • @jaac If you only want stream `0:5` specifically, then just use `-map 0:5`. You don't need `:s:m:language:id`. My example automatically chooses the subtitle stream that has Indonesian language metadata. So you don't need to know the stream index number. – llogan May 12 '20 at 04:27
0

You can use a for loop:

for f in *.mkv; do ffmpeg -i $f -vf subtitles="${f%.mkv}".srt "${f%.mp4}"_sub.mkv; done

Subtitules files must have the same name as videos.

m8factorial
  • 169
  • 4
  • Hi thanks for the reply. I got this error -bash: syntax error near unexpected token `do' – jaac May 11 '20 at 00:18
  • Try this: sh -c 'for f in *.mkv; do ffmpeg -i $f -vf subtitles="${f%.mkv}".srt "${f%.mp4}"_sub.mkv; done' https://stackoverflow.com/questions/25175596/syntax-error-near-unexpected-token-do-when-run-with-sudo – m8factorial May 11 '20 at 07:11
  • I got this -bash: syntax error near unexpected token `do' This is weird. Can you please give the command step by step? I really new to this CLI. Thanks. – jaac May 11 '20 at 08:48
  • For me, it's fine. Are you using "sudo" before the command? I don't know what is the reason for the error. Try inserting the code into a sh file and run: bash script_name.sh. I can't think of anything else. – m8factorial May 11 '20 at 19:17
0

Thanks guys for helping me out.

I use this command to batch rip the subtitle:

#!/bin/bash
cd /home/jaac/torrents/rtorrent/dots || exit
for f in *.mkv; do ffmpeg -i "$f" -map 0:5:s:m:language:id "${f%.*}.srt"; done

I use Shellcheck

Thanks @llogan and @m8factorial

jaac
  • 5
  • 3