VideoFileResizer
Powershell Script to automate conversion of video files of a specified size or larger to smaller mkv or mp4 files using HandBrakecli or ffmpeg.
Pre Reqs
- Must have HandBrakeCLI or ffmpeg installed.
HandBrakeCLI: https://handbrake.fr/downloads2.php
ffmpeg: https://ffmpeg.zeranoe.com/builds/
- Must have powershell 5.1 or higher installed. You can install from here: https://www.microsoft.com/en-us/download/details.aspx?id=54616
- Must have powershell setup to allow this script. See Powershell Setup
- Powershell is a requirement to run the script. I have only tested it on Windows, but if you can get it to work on MacOS or Linux more power to you!
- Edit the script and change the first section of the script to match your needs
A couple notes about editing the script
- All paths can be either a network path. Example: "\\my.server\share\files" or a local path. Example: "C:\Users\Public\Videos"
- All of the flags can be changed, and you can add new ones just copy the existing format.
HandBrake flags: https://handbrake.fr/docs/en/latest/cli/command-line-reference.html \
ffmpeg flags: https://ffmpeg.org/ffmpeg.html#toc-Options
What does the script actually do?
- By default it will look for all files in defined $MovieDir over 2GB and all files in defined $TvShowdir over 1GB (it will look for all files recursivly inside of the defined $MovieDir or $TvShowdir so just specify the base directory that includes all files you want to convert.)
- Once it has found them all it will start converting them from largest to smallest
- It will create a brand new file named: OriginalFileName-New
- Once the conversion is completed it will delete the OriginalFileName and rename the newly converted file to match the OriginalFileName
- When a conversion is completed it will add the file name and path to the csv spreadsheet and not try to convert it again.
- If a conversion fails it does not delete the original file
- If you do have a failed conversion you might have to delete the OriginalFileName-New file that was created before it failed.
- You should only have to delete the OriginalFileName-New file if you kill powershell to stop converting.
Running the script
-
After you have modified the variables and changed the execution policy right click on the script
-
Select Run with Powershell
-
You should see a Powershell window apear and you should see this apear at the top of the window:
Finding Movie Files over xGB in \\Path\To\Movies and Episodes ove xGB in \\Path\To\Shows be patient...
-
If you see that message the script is running and conversions should start
Powershell Setup
Open powershell as the user that will be running the script and then run the following command:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
Select Yes or Yes to all. This will allow scripts to run as the current user.
for more information on Execution Policy view this page: https://technet.microsoft.com/library/hh847748.aspx
Other Information
- This takes a LONG time to run it all depends on how fast your computer is and how the original file was encoded
- On average a 2GB file will take 2-3 hours to complete on an 8 core CPU clocked around 3.9GHz (Might be faster or slower depending on how new the CPU is)