Skip to content

Instantly share code, notes, and snippets.

@PhilMurwin
Created October 19, 2024 22:02
Show Gist options
  • Save PhilMurwin/4132d3a0c917385e8864d0cb58e92f11 to your computer and use it in GitHub Desktop.
Save PhilMurwin/4132d3a0c917385e8864d0cb58e92f11 to your computer and use it in GitHub Desktop.
Powershell script to convert video files to mp4 using ffmpeg
<#
.SYNOPSIS
Converts video files of various formats (e.g., MKV, AVI, MOV) to MP4 using FFmpeg.
.DESCRIPTION
This script searches the current directory for video files with specified extensions
and converts them to MP4 format without re-encoding (using stream copy).
The script uses FFmpeg for conversion and suppresses detailed output during the process.
Any errors encountered during the conversion are logged.
.PARAMETER None
The script doesn't require any parameters and converts all supported video files in the
current directory to MP4.
.NOTES
- Make sure FFmpeg is installed and available in the system's PATH.
- The conversion uses stream copy (`-codec copy`), so the process is fast, without re-encoding.
- Suppresses FFmpeg's output using `Out-Null`.
#>
function makemp4 {
$extensions = @("*.mkv", "*.avi", "*.mov") # Add other extensions as needed
# Display the supported file formats
$formats = $extensions -replace "\*\.", "" -join ", "
Write-Host "Supported formats: $formats"
$videoFiles = Get-ChildItem .\* -Include $extensions
if ($videoFiles.Count -eq 0) {
Write-Host "No Video files found in the current directory."
return
}
$videoFiles | ForEach-Object {
try {
$output = "$($_.BaseName).mp4"
#ffmpeg -i $_.FullName -codec copy $output
ffmpeg -i $_.FullName -codec copy $output *>&1 | Out-Null #Suppress output
Write-Host "Converted: $($_.Name) to $output"
}
catch {
Write-Host "Error converting: $($_.Name) - $_"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment