Software to mass remux mp4 to mkv including subdirectories?

Soldato
Joined
18 Oct 2002
Posts
2,996
As title.
I've got a load of MP4 files, which I'd like to remux to MKV.
The directory structure is:
/movies
/movies/movie1/
/movies/movie2/
/movies/movie3/
etc etc etc
with each directory hold movie1.mp4 for example.

Is there any software which will trundle through all my files, remuxing to MKV, without any reencoding?

I've tried finding some, installed half a dozen applications and can't find anything suitable.

Thanks :)
 
Thanks chaps, I'll check those options out.

Leezer3, would you be willing to share your script if I can't get the Windows suggestions to work?
 
Side thought/idea for metafox - could you not do a base folder search for *.mp4 and then drag them all in to metafox.

Genius, well done :) That worked a treat!

Pho - thanks for the script.
I might well use that as well, as like you suggest, can be scheduled on regular basis.

THANKS EVERYONE, mission accomplished :)
 
I made an amendment to the script to check the MKV size was at least 99.9% of the MP4, before deleting it.
It's working nicely though :)

Code:
param (
    [string]$path = "D:\Media\Movies - Adults\",
    [string]$ffmpeg = "C:\ffmpeg\bin\ffmpeg"
)

$files = Get-ChildItem -recurse -Path "$path" -include "*.mp4" | where {! $_.PSIsContainer}

if ($myArray.length -eq 0)
{
	Write-Host "Nothing to do in '$path'" -foregroundcolor yellow
}

foreach ($file in $files)
{
	$remuxedFile = ([io.path]::ChangeExtension($file, '.mkv'))

	Write-Host Remuxing $file to $remuxedFile
	$ffmpegCommand = "& $ffmpeg -i '$file' -vcodec copy -acodec copy '$remuxedFile'"
	Invoke-Expression $ffmpegCommand
	
	if (Test-Path $remuxedFile)
	{
        Write-Host "$remuxedFile exists" -foregroundcolor yellow
		$original_size = (Get-Item $file).Length
        $safe_size    = ($original_size / 100) * 99
        $new_size      = (Get-Item $remuxedFile).Length
        Write-Host "MP4 file size: $original_size"
        Write-Host "MKV file size: $new_size"
        if ($new_size -gt $safe_size)
            {
            # !! UNCOMMENT THIS TO DELETE THE SOURCE FILE !!
	        Write-Host "MKV size is at least 99.9% of MP4, proceeding to delete MP4"
            Remove-Item $file
            }
        else
            {
            Write-Host "ERROR:  MKV file size too small.  Not deleting."
            exit
            }
	}
	else
	{
		Write-Host "$newFile doesn't exist!" -foregroundcolor red
	}
}
 
Last edited:
\Movies - Adults? ;)
Ha, yes, that's been pointed out before - I can honestly say it's merely to split it out from the "Movies - Kids" folder :)
Since my new build I've just done, it's now just "movies" to stop those with twisted minds reading it the wrong way :D

Anyway, slight tweak made in script to cater for directory names with spaces in on the ffmpeg location.
Code:
param (
    [string]$path = "D:\media\movies\",
    [string]$ffmpeg = "C:\Program Files\Apps - Video\ffmpeg\bin\ffmpeg"
)

$files = Get-ChildItem -recurse -Path "$path" -include "*.mp4" | where {! $_.PSIsContainer}

if ($myArray.length -eq 0)
{
	Write-Host "Nothing to do in '$path'" -foregroundcolor yellow
}

foreach ($file in $files)
{
	$remuxedFile = ([io.path]::ChangeExtension($file, '.mkv'))

	Write-Host Remuxing $file to $remuxedFile
	$ffmpegCommand = "& '$ffmpeg' -i ""$file"" -vcodec copy -acodec copy ""$remuxedFile"""
	Invoke-Expression $ffmpegCommand
	
	if (Test-Path $remuxedFile)
	{
        Write-Host "$remuxedFile exists" -foregroundcolor yellow
		$original_size = (Get-Item $file).Length
        $safe_size    = ($original_size / 100) * 99
        $new_size      = (Get-Item $remuxedFile).Length
        Write-Host "MP4 file size: $original_size"
        Write-Host "MKV file size: $new_size"
        if ($new_size -gt $safe_size)
            {
            # !! UNCOMMENT THIS TO DELETE THE SOURCE FILE !!
	        Write-Host "MKV size is at least 99.9% of MP4, proceeding to delete MP4"
            Remove-Item $file
            }
        else
            {
            Write-Host "ERROR:  MKV file size too small.  Not deleting."
            exit
            }
	}
	else
	{
		Write-Host "$newFile doesn't exist!" -foregroundcolor red
	}
}

Edit - added code to cater for apostrophe's in file and directory names too. e.g. Ferris Bueller's Day Off (1986).mp4
 
Last edited:
Back
Top Bottom