Essentially a batch application of the following command:

ffmpeg -i "01.mkv" -map 0:a? -map 0:s? -map 0:v -c:v copy -c:a ac3 -c:s copy "test.mkv"

My hope would be to simply run this in a directory and have all the newly fixed files with the old file names and the old files appended with "old_" or something similar. I know next to nothing about bash, but have some experience with c++ and java, so terminology is not an issue, I just have never looked at bash before. Thanks!

EDIT: To be clear, I'd like the new file to be "01.mkv" and the old file to be renamed to "old_01.mkv". My research has told me this will probably require gawk, but I know even less about that than I do bash.

EDIT2: I realize I should have provided what I had been able to put together so far on my own.

    for i in $( ls ); do
        ffmpeg -i $i -map 0:a? -map 0:s? -map 0:v -c:v copy -c:a ac3 -c:s copy $i
  • So you want us to code this for you? – JakeGould Dec 2 '17 at 23:16
  • I suggest you start learning about bash by investigating the for statement. – AFH Dec 2 '17 at 23:18
  • I edited above. What I have theoretically works, I guess what I am not understanding is how to change the file names? Is it as easy as simple saying something like $i = old_$i? Or would I use command lines like in a normal terminal? like for (blah blah) cp $i old_$i. I've also seen people talking about gawk in related questions, but that seems overly complex for what I'm doing. Regardless, I can't seem to get the above ideas to work either, unless maybe I'm just doing them wrong – Jason Murray Dec 2 '17 at 23:31

Ok, after messing around with this for a few hours after getting a lucky Google search result I hadn't seen before, I finally figured this out. This is the answer, in case anyone else comes along and needs to do something like this.

for file in *.mkv;
        mv "$file" "$oldFile"
        ffmpeg -i "$oldFile" -map 0:a? -map 0:s? -map 0:v -c:v copy -c:a ac3 -c:s copy "$file"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.