<p>If you are on Windows use WSL (it might be Ubuntu) and then something similar as mivik mentioned.</p>
<p>cd TOP_DIRECTORY; find . -type f -iname &quot;*.mp4&quot; -exec ffmpeg -y -i '{}' -c:a copy -c:v libx264 -preset fast -profile:v baseline -pix_fmt yuv420p '{}.mkv' ;</p>

CC BY-SA 4.0
2021-08-16T23:28:56.183Z
I ended up using WSL and Ubuntu and used the following command after going to the correct directory:
  
find . -name "*.mp4" -exec sh -c 'ffmpeg -i "$1" -codec copy "${1%.*}.mkv" -hide_banner' sh {} \;

I had a problem where I was getting double extensions (filename.mp4.mkv) and found the following code online. It did the trick (I hope!) Thanks so much for your help!
Osamah Tahir
CC BY-SA 4.0
2021-08-16T20:48:01.553Z
2021-08-16T20:48:01.553Z
wwk
<p>I'm quite new to the world of FFmpeg and video editing tools, but I essentially need to change the hash of a large set of videos that are organized in folders and subfolders and the easiest way I've come into is remuxing and/or re-encoding the video. Currently, I am using the program HandBrake to bulk re-encode videos in each folder from a <code>.mp4</code> to a <code>.mkv</code> and that has done the trick. However, it is practically infeasible to do this for every single subfolder with hundreds of video files in each folder.</p>
<p>I have used FFmpeg briefly before and I'm wondering how I can best automate FFmpeg to search through each folder and its subfolders, find each <code>.mp4</code> video, re-encode it to a <code>.mkv</code>, and then save it under the same name and path as the original video.</p>
<p>I've been reading through FFmpeg documentation to determine how this can be done, but I'm wondering if anyone here is experienced enough in FFmpeg to lend me a helping hand. Thank you very much</p>

CC BY-SA 4.0
2021-08-14T21:55:20.003Z
ffmpeg can do rewrapping to mkv. But for telling it which files to rewrap and how to name the new output files, you would use your shell's commands or a small script. Specify your OS, since the available shell's are different in Windows or in Mac/Linux.
mivk
CC BY-SA 4.0
2021-08-15T19:48:57.060Z
Sorry about that. I'm on Windows 10!
Osamah Tahir
CC BY-SA 4.0
2021-08-15T21:27:56.703Z
On Windows, you have `cmd.exe` and `powershell`. In Mac/Linux, it would be something like `find . -name "*.mp4" | while read f; do ffmpeg -i "$f" .... "${f%%mp4}mkv"; done`. So you have to find the equivalent syntax for one of the Windows shells.
mivk
<ffmpeg><windows>
Bulk re-muxing/re-encoding with ffmpeg in multiple folders
Osamah Tahir
# Bulk re-muxing/re-encoding with ffmpeg in multiple folders

(Asked by: username_0 on 2021-08-12)

I'm quite new to the world of FFmpeg and video editing tools, but I essentially need to change the hash of a large set of videos that are organized in folders and subfolders and the easiest way I've come into is remuxing and/or re-encoding the video. Currently, I am using the program HandBrake to bulk re-encode videos in each folder from a `.mp4` to a `.mkv` and that has done the trick. However, it is practically infeasible to do this for every single subfolder with hundreds of video files in each folder.

I have used FFmpeg briefly before and I'm wondering how I can best automate FFmpeg to search through each folder and its subfolders, find each `.mp4` video, re-encode it to a `.mkv`, and then save it under the same name and path as the original video.

I've been reading through FFmpeg documentation to determine how this can be done, but I'm wondering if anyone here is experienced enough in FFmpeg to lend me a helping hand. Thank you very much

**Tags:** ffmpeg, windows

> **Comments:**
> **username_1**: ffmpeg can do rewrapping to mkv. But for telling it which files to rewrap and how to name the new output files, you would use your shell's commands or a small script. Specify your OS, since the available shell's are different in Windows or in Mac/Linux.  
> **username_0**: Sorry about that. I'm on Windows 10!  
> **username_1**: On Windows, you have `cmd.exe` and `powershell`. In Mac/Linux, it would be something like `find . -name "*.mp4" | while read f; do ffmpeg -i "$f" .... "${f%%mp4}mkv"; done`. So you have to find the equivalent syntax for one of the Windows shells.  

---

## 1 answers

### Answer by username_2 on 2021-08-16. Score: 0 | Accepted answer

If you are on Windows use WSL (it might be Ubuntu) and then something similar as mivik mentioned.

cd TOP\_DIRECTORY; find . -type f -iname "\*.mp4" -exec ffmpeg -y -i '{}' -c:a copy -c:v libx264 -preset fast -profile:v baseline -pix\_fmt yuv420p '{}.mkv' ;

> **Comments:**
> **username_0**: I ended up using WSL and Ubuntu and used the following command after going to the correct directory:    find . -name "*.mp4" -exec sh -c 'ffmpeg -i "$1" -codec copy "${1%.*}.mkv" -hide_banner' sh {} \;  I had a problem where I was getting double extensions (filename.mp4.mkv) and found the following code online. It did the trick (I hope!) Thanks so much for your help!  

---

