For Reducing video quality using FFmpeg
FFmpeg
is required to run the project
FFmpeg download website for windows
Direct Download link use 7-Zip for extraction.
ffmpeg.exe will be inside bin
folder, copy it to ReduceVideoQuality.ps1 location
- Download ReduceVideoQuality.ps1 file from github
- OR Download Repository as Zip and Extract
- OR
git clone https://github.com/ankitT20/FFmpeg_whatsapp.git
- Ensure ffmpeg.exe is in the same directory/folder as the ReduceVideoQuality.ps1 and video file.
- Select and Right click ReduceVideoQuality.ps1, click Run with PowerShell.
- OR Open PowerShell, navigate to the directory containing the script, and run it using
ReduceVideoQuality.ps1
.
- OR Open PowerShell, navigate to the directory containing the script, and run it using
- Follow the prompts to provide the filename and select options.
If running scripts is dissabled on your system, search powershell, Right click and 'Run as Administrator', and run the following:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4
ffmpeg -i input.mp4 -vcodec libx265 -crf 23 output.mp4
ffmpeg -i input.mp4 -c:v libx265 -crf 26 -preset fast -c:a aac -b:a 128k output.mp4
default crf value is 23, and libx265 is HEVC (High Efficiency Video Coding) , for x264 refer
ffmpeg -i input.mp4 -vcodec libx265 -x265-params lossless=1 output.mp4
verify using console output - x265 [info]: Rate Control : Lossless
calculate bitrate
64 * 8000 / 349 = 1467
64(desired file size) * 8(byte to bit) * 1000(MB to KB) / 349(duration of video in seconds) = 1467 (do multiplication first)
ffmpeg -y -i input.mp4 -c:v libx265 -b:v 1467k -x265-params pass=1 -an -f null NUL && ^
ffmpeg -i input.mp4 -c:v libx265 -b:v 1467k -x265-params pass=2 -an output_64MB.mp4
calculate bitrate
64 * 8000 / 349 = 1467
64(desired file size) * 8(byte to bit) * 1000(MB to KB) / 349(duration of video in seconds) = 1467 (do multiplication first)
1467 - 128 kBit/s (desired audio bitrate) = 1339 kBit/s video bitrate
ffmpeg -y -i input.mp4 -c:v libx265 -b:v 1339k -x265-params pass=1 -an -f null NUL && ^
ffmpeg -i input.mp4 -c:v libx265 -b:v 1339k -x265-params pass=2 -c:a aac -b:a 128k output.mp4