MKV to MP4 container solution

1

Right now I am using ffmpeg to convert from MKV to MP4 for my movies and tv shows. However This can only be done in one folder at a time or one move at a time as they are all in their own folder. I use this code:

for %%a in ("*.mkv") do ffmpeg.exe -i "%%a" -vcodec copy -acodec copy "%%~na .mp4" pause

This works fine for instance if it's a tv show folder for a season and will go and convert each episode one at a time.

Is there a way to use batch to search the subfolders in the root directory ~1200 and find all MKV files, convert them to the new container retaining same audio/channels and then remove the old mkv file?

cyris69

Posted 2016-10-16T04:01:17.397

Reputation: 55

Answers

1

The command

FOR /R %%a etc etc 

will recurse the sub-folders and adding "(" after the "DO" will allow you to enter more than one command over numerous lines. You then close the commands with ")"

I am not an expert at batch files by any means and the above was gleaned from http://ss64.com/nt/for.html ... I hope though this may be of some help

Darío Martín

Posted 2016-10-16T04:01:17.397

Reputation: 100

1This indeed is working but it places each converter movie out into the root directory. I mean that isn't a huge deal but would prefer to stay in the folder. I found the code I'm using so not big on understanding the conversion process. So If there is a way to keep it in the same folder as well as remove the original mkv after conversion would be amazing. – cyris69 – 2016-10-16T04:18:47.143

I also get this all the time, it doesn't affect quality or conversion but curious about it. – cyris69 – 2016-10-16T04:22:19.937

[mp4 @ 00000000020c07a0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. Last message repeated 1 times [mp4 @ 00000000020c07a0] track 1: codec frame size is not set – cyris69 – 2016-10-16T04:22:29.057

1Actually, transferring to the root is fine, would there be a way to just delete the original folder said movie is in. Then I won't have to go back through everything to remove dups and then can also use filebot for renaming. – cyris69 – 2016-10-16T04:25:18.047

I do see adding this to the end del "%%~a" – cyris69 – 2016-10-16T04:31:26.467

This may work but I think it will just remove original file. for /R %%a in ("*.mkv") do ( ffmpeg.exe -i "%%a" -vcodec copy -acodec copy "%%~na .mp4" del "%%~a" ) pause

Just tried this and happened to cancel the process and removed about 15 movies completely that are unrecoverable so this si one fun process lol – cyris69 – 2016-10-16T04:43:32.923

1One fun process indeed @cyris69 - if you can capture the directory the file is stored in, then following conversion, you could use RD /Q to delete the directory. NOTE suggest you set up a test directory away from valuable files to play with this... using set Var=%CD% captures the current directory to %%Var%% – Darío Martín – 2016-10-16T07:34:40.917

Good deal, I'll give that a try as well. Last night I forget I had Remove Empty Directories program installed and was using that for the time being. I also noticed since I didn't trust this running while I couldn't watch it that if I did ctrl c to use as a pause (choice of terminating or not the batch job using y/n) that it would still remove the just started next or current movie even if I attempted to resume. – cyris69 – 2016-10-16T15:48:16.687