Created
February 17, 2025 18:42
-
-
Save tomtobac/756061ed5fa791147862ac16457d7472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal EnableDelayedExpansion | |
:start | |
cls | |
echo Video Processing Script | |
echo ---------------------- | |
echo. | |
echo Drag and drop your video file here: | |
set /p "videofile=" | |
:: Remove surrounding quotes and handle spaces in path | |
set videofile=%videofile:"=% | |
:: Get video duration and size using ffprobe | |
for /f "tokens=*" %%i in ('ffprobe -v error -show_entries format^=duration -of default^=noprint_wrappers^=1:nokey^=1 "%videofile%"') do set duration=%%i | |
for /f "tokens=*" %%i in ('ffprobe -v error -show_entries format^=size -of default^=noprint_wrappers^=1:nokey^=1 "%videofile%"') do set original_size=%%i | |
:: Convert size to MB for better readability | |
set /a original_size_mb=%original_size%/1048576 | |
:: Convert duration to HH:MM:SS format | |
set /a duration_int=%duration% | |
set /a hours=%duration_int%/3600 | |
set /a minutes=(%duration_int%%%3600)/60 | |
set /a seconds=%duration_int%%%60 | |
echo. | |
echo Video Information: | |
echo Duration: %hours%:%minutes%:%seconds% | |
echo Original Size: %original_size_mb% MB | |
:: Ask for trimming (default no) | |
echo. | |
set /p "trim=Do you want to trim the video? (y/N): " | |
if /i "%trim%"=="" set "trim=n" | |
if /i "%trim%"=="y" ( | |
set /p "start_time=Enter start time (HH:MM:SS) or press Enter for start: " | |
set /p "end_time=Enter end time (HH:MM:SS) or press Enter for end: " | |
set trim_options= | |
if "!start_time!"=="" ( | |
set "start_time=00:00:00" | |
) | |
set "trim_options=-ss !start_time!" | |
if not "!end_time!"=="" set "trim_options=!trim_options! -to !end_time!" | |
) else ( | |
set "trim_options=" | |
) | |
:: Ask for muting | |
echo. | |
set /p "mute=Do you want to mute the video? (Y/n): " | |
if /i "%mute%"=="" set "mute=y" | |
if /i "%mute%"=="y" ( | |
set "audio_options=-an" | |
) else ( | |
set "audio_options=-c:a aac -b:a 128k" | |
) | |
:: Ask for optimization (default yes) | |
echo. | |
set /p "optimize=Do you want to optimize for YouTube? (Y/n): " | |
if /i "%optimize%"=="" set "optimize=y" | |
:: Generate output filename | |
for %%i in ("%videofile%") do set "filename=%%~ni" | |
set "output=%filename%_processed.mp4" | |
:: Process the video | |
if /i "%optimize%"=="y" ( | |
echo Processing video with optimization... | |
ffmpeg -i "%videofile%" %trim_options% %audio_options% -c:v libx264 -preset slow -crf 18 -profile:v high -level:v 4.0 -pix_fmt yuv420p -movflags +faststart -y "%output%" | |
) else ( | |
echo Processing video without optimization... | |
ffmpeg -i "%videofile%" %trim_options% %audio_options% -c:v copy -y "%output%" | |
) | |
:: Get the size of the processed file | |
for /f "tokens=*" %%i in ('ffprobe -v error -show_entries format^=size -of default^=noprint_wrappers^=1:nokey^=1 "%output%"') do set processed_size=%%i | |
set /a processed_size_mb=%processed_size%/1048576 | |
:: Calculate size difference and percentage | |
set /a size_diff_mb=%original_size_mb%-%processed_size_mb% | |
set /a reduction_percentage=(%size_diff_mb%*100)/%original_size_mb% | |
echo. | |
echo Processing complete! Output saved as: %output% | |
echo. | |
echo Size Comparison: | |
echo Original size: %original_size_mb% MB | |
echo Processed size: %processed_size_mb% MB | |
echo Size reduction: %size_diff_mb% MB (%reduction_percentage%%%^) | |
echo. | |
pause | |
goto start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment