I had been searching for an easy solution to combine a video file with it’s separate audio file but simply Googling that gives a bunch of results that require downloading software from questionable places. I then had the idea to find out if it was possible with FFMPEG (a lot of software uses it anyway). And it turns out it is, with a very simple one liner. I threw it in some Powershell to make it easy to use.
A graphical file selection for both video and audio files. Be sure to update the path to the ffmpeg executable to wherever you put it and whatever starting directory you want for the files. I wrote it so the output just goes to the same directory where the files are but you can easily change that. If you are going to work with files other than mp4 and m4a, then update (or just remove the line) with the filter. Also, because the video alone is an mp4 and the output will be an mp4, I randomly chose to insert a “2-” in the front of the filename if I don’t type one in at that starting prompt. By default it just adds that to the name of the video file, for the combined output file.
Thanks to this page for the ffmpeg command line: https://kwizzu.com/construct.html
Add-Type -AssemblyName System.windows.forms | Out-Null $outputFilename = Read-Host "Enter Output Filename" $ffmpeg = "C:\ffmpeg-4.0.2-win64-static\bin\ffmpeg.exe" $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.showHelp = $true $OpenFileDialog.initialdirectory = "C:\Users\me\Downloads\" $OpenFileDialog.filter = "Videos (*.mp4)| *.mp4" $OpenFileDialog.ShowDialog() | Out-Null $vidPath = $OpenFileDialog.FileName If(!$outputFilename) { $outputFilename = "2-$($OpenFileDialog.SafeFileName)"} $outputFilePath = "C:\Users\me\Downloads\$outputFilename" $OpenFileDialog.filter = "Videos (*.m4a)| *.m4a" $OpenFileDialog.ShowDialog() | Out-Null $audioPath = $OpenFileDialog.FileName Start-Process -FilePath $ffmpeg -ArgumentList "-i ""$vidPath"" -i ""$audioPath"" -c:v copy -c:a copy ""$outputFilePath""" Read-Host "Press any key to exit"
This works especially well for YouTube videos or others where you have to download them as separate files. The best part about this is that it is FAST. I tried it first with the built in video creator for Windows 10, it’s slow and it took a 400MB video file and 40MB audio file and created a 1.4GB combined file… wow. With ffmpeg the output file is just the size of the two combined.
You can easily automate this if you have a lot of work. You can make the script constantly run on your machine, monitor a folder every so often, etc… and have it automatically detect two files of the same name (sans extension) and merge them. Lots of ways to expand this.
You must be logged in to post a comment.