Batch file processing: extract .rar and convert MKV in bulk
Batch file processing: extract .rar and convert MKV in bulk
When you have a folder full of files to process, a bash loop handles it without needing to open any GUI.
Extract all .rar files from a directory
1
for f in *.rar; do unrar e "$f"; done
unrar e extracts files without preserving the directory structure (everything goes to the current folder). If you want to preserve the folder structure, use unrar x instead of unrar e.
If the .rar files are parts of a single archive (.part1.rar, .part2.rar, etc.), just run it on the first one:
1
unrar e arquivo.part1.rar
unrar finds the other parts automatically.
Convert all .mkv to .mp4
1
for f in *.mkv; do ffmpeg -hide_banner -i "$f" -c:v libx264 -c:a copy "$f.mp4"; done
-hide_banner→ suppresses ffmpeg’s long header-c:v libx264→ re-encodes video in H.264 (compatible with virtually everything)-c:a copy→ copies audio without re-encoding (faster and lossless)"$f.mp4"→ the output name will bevideo.mkv.mp4— if you wantvideo.mp4, use"${f%.mkv}.mp4"
Version with clean naming:
1
for f in *.mkv; do ffmpeg -hide_banner -i "$f" -c:v libx264 -c:a copy "${f%.mkv}.mp4"; done
Performance considerations
Video conversion is CPU-intensive. If you have an NVIDIA GPU and ffmpeg compiled with NVENC support, you can speed things up significantly:
1
ffmpeg -i "$f" -c:v h264_nvenc -c:a copy "${f%.mkv}.mp4"
For Intel with Quick Sync:
1
ffmpeg -i "$f" -c:v h264_qsv -c:a copy "${f%.mkv}.mp4"
But for general use, libx264 with -preset fast is already a good balance:
1
ffmpeg -i "$f" -c:v libx264 -preset fast -c:a copy "${f%.mkv}.mp4"
This post is licensed under
CC BY 4.0
by the author.