I am trying to write a shell script that will repair every .mkv file in a directory using this command

ffmpeg -i filename.mkv -c copy filename-fixed.mkv

I had to recover a disk with hundreds of files and some are corrupted. They currently dont play at all or crash my system. I have identified all the corrupted one and they are in their own directory. I think the easiest way to do this is to run a script on all the files but I am new to scripts


Before running the batch operation, first make sure the command you're going to use actually works. If so, with the command above as your example you can apply the same command to all of *.mkv files within directory with this command.

for file in *.mkv; do ffmpeg -i $file -c copy "${file%.*}-fixed.${file##*.}"; done

The command will be applied to each file which has mkv extension and the output will have fixed appended to the name.

| improve this answer | |
  • I'm curious if the command actually fix the corrupted mkvs. Does it works for you? – aasril Aug 23 '18 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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