Skip to content

Instantly share code, notes, and snippets.

@taruma
Created March 20, 2025 01:53
Show Gist options
  • Save taruma/f0b93ffcdb3f6f6cfdc1f083052d39c6 to your computer and use it in GitHub Desktop.
Save taruma/f0b93ffcdb3f6f6cfdc1f083052d39c6 to your computer and use it in GitHub Desktop.
@echo off
setlocal EnableDelayedExpansion
set "input=%~1"
if "%input%"=="" set "input=input.mp4"
rem Extract just the filename without extension for output
set "output_name=%~n1"
if "%output_name%"=="" set "output_name=input"
set "output=%output_name%.png"
rem Get duration from FFprobe
for /f "delims=" %%a in ('ffprobe -v error -show_entries format^=duration -of csv^=p^=0 "%input%"') do set "duration=%%a"
echo Video duration: %duration% seconds
rem Extract duration integer and decimal parts
for /f "tokens=1,2 delims=." %%a in ("%duration%") do (
set "duration_int=%%a"
set "duration_dec=%%b"
)
rem Calculate time points with decimal precision
set "time1=0"
set "time2=!duration_int!"
set "time3=!duration_int!"
set "time4=!duration_int!"
rem Calculate time2 (33%% of duration)
set /a "t2_whole=!duration_int!*33/100"
set "time2=!t2_whole!.!duration_dec:~0,1!"
rem Calculate time3 (66%% of duration)
set /a "t3_whole=!duration_int!*66/100"
set "time3=!t3_whole!.!duration_dec:~0,1!"
rem Calculate time4 (very end, 99%% of duration)
set /a "t4_whole=!duration_int!*99/100"
set "time4=!t4_whole!.!duration_dec:~0,1!"
echo Using time points: !time1!, !time2!, !time3!, !time4! seconds
rem Extract and combine frames using time-based selection
ffmpeg -i "%input%" -vf "select='eq(t,!time1!)+eq(t,!time2!)+eq(t,!time3!)+eq(t,!time4!)',setpts=N/FRAME_RATE/TB,tile=4x1" -frames:v 1 "%output%"
echo Extracted 4 frames to %output%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment