Last active
June 19, 2022 08:22
-
-
Save sjm42/ebee72a4ace750f1d682a33184b55ef0 to your computer and use it in GitHub Desktop.
Create timelapse with ffmpeg
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
################################################### | |
# concatenate all mp4 files into one mkv input file | |
time ffmpeg -f concat -safe 0 -i <(for f in *.MP4; do echo "file '$PWD/$f'"; done) -c copy input.mkv | |
############################################# | |
# make 10x speed timelapse with 60 fps output | |
time ffmpeg -i input.mkv -an -r 60 -filter:v "setpts=0.10*PTS" timelapse-10x.mkv | |
# real 12m44.746s | |
############################################# | |
# make 20x speed timelapse with 60 fps output | |
time ffmpeg -i input.mkv -an -r 60 -filter:v "setpts=0.05*PTS" timelapse-20x.mkv | |
# real 8m4.926s | |
###################################### | |
# Do it with pipe, no large temp files | |
ffmpeg -nostats -f concat -safe 0 -i <(for f in *.MP4; do echo "file '$PWD/$f'"; done) -c copy -an -f matroska - \ | |
| time ffmpeg -y -i - -r 60 -filter:v "setpts=0.05*PTS" pipetest-20x.mkv | |
################################## | |
# Use NVidia GPU & CUDA-enabled ffmpeg | |
ffmpeg -nostats -f concat -safe 0 -i <(for f in *.MP4; do echo "file '$PWD/$f'"; done) -c copy -an -f matroska - \ | |
| time /usr/local/bin/ffmpeg -y -hwaccel cuda -i - -r 60 -filter:v "setpts=0.1*PTS" -c:v h264_nvenc -b:v 150M \ | |
cuda-10x.mkv | |
# 2:06 elapsed | |
ffmpeg -nostats -f concat -safe 0 -i <(for f in *.MP4; do echo "file '$PWD/$f'"; done) -c copy -an -f matroska - \ | |
| time /usr/local/bin/ffmpeg -y -hwaccel cuda -i - -r 60 -filter:v "setpts=0.05*PTS" -c:v h264_nvenc -b:v 150M \ | |
cuda-20x.mkv | |
# 2:12 elapsed |
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
#!/bin/bash | |
BITRATE=100M | |
DEST=/store/sjm/timelapse | |
ffm=/usr/local/bin/ffmpeg | |
vlist="" | |
date="" | |
prevdate="" | |
process_files() { | |
echo "### Processing: $vlist" | |
$ffm -nostats -f concat -safe 0 -i <(for f in $vlist; do echo "file '$PWD/$f'"; done) \ | |
-c copy -an -f matroska - \ | |
| time $ffm -y -hwaccel cuda -i - \ | |
-r 60 -filter:v "setpts=0.1*PTS" -c:v h264_nvenc -b:v $BITRATE \ | |
$DEST/$prevdate.mkv | |
} | |
for v in *F.MP4 | |
do | |
date=$(echo $v | cut -d_ -f1) | |
if [ -n "$vlist" -a "$date" != "$prevdate" ] | |
then | |
process_files | |
vlist="" | |
fi | |
[ -s $v ] && vlist="$vlist $v" | |
prevdate=$date | |
done | |
if [ -n "$vlist" ] | |
then | |
process_files | |
fi | |
exit 0 | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment