Last active
August 24, 2018 13:20
-
-
Save lilithebowman/f2a45efcdb674d1140b8f61c22768fd2 to your computer and use it in GitHub Desktop.
This file contains 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 | |
echo You must download ffmpeg to use this batch file. | |
echo https://ffmpeg.zeranoe.com/builds/ | |
echo . | |
echo A command prompt will pop up and churn for a while depending on the size | |
echo . | |
echo Add the list of files to concatenate to mylist.txt with "file " in front of the name. One per line. | |
echo Example: | |
echo file GOPR2307.MP4 | |
echo file GP012307.MP4 | |
echo file GP022307.MP4 | |
echo . | |
echo This batch file will automatically concatenate, speed up the video 4x, and run extensive stabilization on the video. | |
echo . | |
echo Temporary files are in D:\tmp | |
pause | |
rem Get start time: | |
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do ( | |
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" | |
) | |
echo Start time: %time% | |
ls %tmp%\*.mp4 | |
echo ############################# | |
echo ##### RUN CONCATENATION ##### | |
echo ############################# | |
mkdir D:\tmp | |
ffmpeg -f concat -safe 0 -i mylist.txt -c copy %tmp%\concatenated.mp4 | |
echo ######################################################### | |
echo ##### RUN STABILIZATION DETECTION (Create TRF file) ##### | |
echo ######################################################### | |
ffmpeg -i %tmp%\concatenated.mp4 -vf vidstabdetect=stepsize=6:shakiness=5:accuracy=15:result=concatenated.trf -f null - | |
echo ###################################### | |
echo ##### RUN STABILIZATION ON VIDEO ##### | |
echo ###################################### | |
ffmpeg -i %tmp%\concatenated.mp4 -vf vidstabtransform=input=concatenated.trf:zoom=1:smoothing=30,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -preset slow -tune film -crf 18 -acodec copy %tmp%\stabilized_1x_speed.mp4 | |
echo ########################## | |
echo ##### RUN SPEEDUP 2X ##### | |
echo ########################## | |
ffmpeg -i %tmp%\stabilized_1x_speed.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" %tmp%\concatenated_speedy_2x.mp4 | |
echo ########################################### | |
echo ##### RUN SPEEDUP 2X (to be 4x speed) ##### | |
echo ########################################### | |
ffmpeg -i %tmp%\concatenated_speedy_2x.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" %tmp%\concatenated_speedy_4x.mp4 | |
echo ########################################### | |
echo ##### RUN SPEEDUP 2X (to be 6x speed) ##### | |
echo ########################################### | |
ffmpeg -i %tmp%\concatenated_speedy_4x.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" concatenated_speedy_6x.mp4 | |
echo ***** ALL DONE! ***** | |
rem Get end time: | |
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do ( | |
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" | |
) | |
rem Get elapsed time: | |
set /A elapsed=end-start | |
rem Show elapsed time: | |
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100 | |
if %mm% lss 10 set mm=0%mm% | |
if %ss% lss 10 set ss=0%ss% | |
if %cc% lss 10 set cc=0%cc% | |
echo ############################################################################################# | |
echo ##### Processing stabilization and outputting stabilized video took %hh%:%mm%:%ss%,%cc% ##### | |
echo ############################################################################################# | |
echo Press Ctrl+C or close this window to skip file cleanup. | |
echo If you press any other key, the temporary files will be deleted. | |
pause | |
del %tmp%\concatenated.mp4 | |
del %tmp%\stabilized_1x_speed.mp4 | |
del %tmp%\concatenated_speedy_2x.mp4 | |
del %tmp%\concatenated_speedy_4x.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stabilizing before speeding up much helps it not generate erroneous stabilizations.
I found especially moving shadows would confuse the algorithm when sped up.