Skip to content

Instantly share code, notes, and snippets.

@ildar-shaimordanov
Last active September 6, 2022 15:47
Show Gist options
  • Save ildar-shaimordanov/2c46b408961a6372267c9f6f22a8c4a2 to your computer and use it in GitHub Desktop.
Save ildar-shaimordanov/2c46b408961a6372267c9f6f22a8c4a2 to your computer and use it in GitHub Desktop.
examples for making cuts of lightnings

There is collection of scripts which used to create short video of lightnings cut from the full footages.

These scripts are not complete. I store them here as a hints for the future.

Table of Content

footage 2021-06-28

@echo off

set "ORIG_FILE=20210628_135244.mp4"

call :extract-to 1 00:00:04 00:00:06.100
call :extract-to 2 00:01:12 00:01:13.400

goto :EOF

:: extract-to FILE-ID START-TIME STOP-TIME
:extract-to
ffmpeg -i "%ORIG_FILE%" -ss "%~2" -to "%~3" -vcodec copy -an -y z-video-1.mp4
ffmpeg -i z-video-1.mp4 -filter:v "setpts=1.1*PTS" -y z-video-2.mp4
ffmpeg -i z-video-2.mp4 -filter:v "setpts=1.2*PTS" -y z-video-3.mp4
ffmpeg -i z-video-3.mp4 -filter:v "setpts=1.3*PTS" -y z-video-4.mp4
ffmpeg -i z-video-4.mp4 -filter:v "setpts=1.4*PTS" -y z-video-5.mp4
ffmpeg -i z-video-5.mp4 -filter:v "setpts=1.5*PTS" -y z-video-6.mp4
ffmpeg -i z-video-6.mp4 -filter:v "setpts=2.0*PTS" -y z-video-7.mp4

ffmpeg -i z-video-1.mp4 -filter:v "scale=640x360" -y final-%~1-1.mp4
ffmpeg -i z-video-7.mp4 -filter:v "scale=640x360" -y final-%~1-7.mp4

ffmpeg -i final-%~1-1.mp4 -filter:v fps=25/1 z-image-%%03d.bmp
ffmpeg -r 3/1 -i z-image-%%03d.bmp -c:v libx264 -vf "fps=25,format=yuv420p" -y final-%~1-8.mp4

del z-video-*.mp4 z-image-*.bmp

goto :EOF

footage 2021-08-04

@echo off

set "ORIG_FILE=20210804_142413.mp4"

:ffmpeg -i "%ORIG_FILE%" -filter:v fps=25/1 z-image-%%03d.bmp
:ffmpeg -i "%ORIG_FILE%" -ss "00:00:50" -to "00:00:52" -filter:v fps=25/1 z-image-%%03d.bmp

ffmpeg -r 5/1 -i z-image-%%04d.bmp -c:v libx264 -vf "fps=25,format=yuv420p" -s 640x360 -y "final-%ORIG_FILE%"

footage 2022-07-10

@echo off

setlocal

set "ORIG_FILE=VID_20220710_181014.mp4"
set "IMAG_TYPE=bmp"

for %%a in (
	extract
	convert
	concat
) do if "%%~a" == "%~1" (
	call :%%~a-all
	goto :EOF
)

echo:Bad command "%~1"
goto :EOF

:extract-all
call :extract 1 00:01:44 00:01:47
call :extract 2 00:03:09 00:03:14
call :extract 3 00:06:41 00:06:47
goto :EOF

:convert-all
call :convert 1 025 035
call :convert 2 090 099
call :convert 3 110 126
goto :EOF

:concat-all
dir /b final-?.mp4 | bb sed "s/^/file /" | ffmpeg.exe -protocol_whitelist file,pipe -f concat -i - -c:v copy -y final-123.mp4
goto :EOF

:extract
del z-image-%~1-*.%IMAG_TYPE%
ffmpeg -i "%ORIG_FILE%" -ss "%~2" -to "%~3" -filter:v fps=25/1 z-image-%~1-%%03d.%IMAG_TYPE%
goto :EOF

:convert
ffmpeg -r 5/1 -start_number %~2 -i z-image-%~1-%%03d.%IMAG_TYPE% -c:v libx264 -vf "fps=25,format=yuv420p" -s 640x360 -y final-%~1.mp4
goto :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment