Software to mass remux mp4 to mkv including subdirectories?

Soldato
Joined
18 Oct 2002
Posts
2,995
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 :)
 
metafox....think it will do it although not 100% on folders, I don't do mine that way. It's literally open, drag folders and then wait.
 
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?
 
Metafox - doesn't handle subfolders unfortunately.

OK, on to Mencoder.....and learning powershell scripts....:D
Side thought/idea for metafox - could you not do a base folder search for *.mp4 and then drag them all in to metafox. The files should stay in the same place (they did for me).

Once it's done (check for *.mkv in another window first obviously) you can then just delete the mp4's in one go :)
 
Here's an adaption of a Powershell script I wrote to remux ts files to mkv.

  1. You'll need ffmpeg. Download either the 32-bit or 64-bit "static" version and extract it somewhere. Let's say c:\temp\ffmpeg
  2. Save the below script somewhere as a ps1 file. Let's say c:\temp\convert.ps1
  3. Open Powershell from your start menu or wherever- you'll likely find "Powershell" and "Powershell (x86)", do this for them both just to be sure.
    You'll probably need to unblock Powershell scripts, so use:
    PHP:
    Set-ExecutionPolicy Unrestricted
    * this lets any Powershell script run on your PC, I don't have a problem setting it to this but it's your call.
  4. Execute the script:
    convert.ps1 $path $ffmpegPath

    e.g.,:
    convert.ps1 "c:\movies\" "c:\temp\ffmpeg\bin\ffmpeg"

    (you could put ffmpeg in your Windows path and omit the $ffmpegPath variable)

All being well, you should now have some remuxed mkv files. Uncomment the line #Remove-Item $file in the script to have the old file deleted after a successful conversion. I'll leave you to do that :).

I then schedule this script to run via Windows Task Scheduler. Just create a batch file somewhere which contains say:

Code:
@echo off
powershell -command "c:\temp\convert.ps1 '"c:\movies"' '"c:\temp\ffmpeg\bin\ffmpeg"'

and get your schedule task to run that.


Script:
Code:
param (
    [string]$path = $(throw "-path is required."),
    [string]$ffmpeg = "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
		# !! UNCOMMENT THIS TO DELETE THE SOURCE FILE !!
		#Remove-Item $file
	}
	else
	{
		Write-Host "$newFile doesn't exist!" -foregroundcolor red
	}
}
 
Last edited:
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