Skip to content

Instantly share code, notes, and snippets.

@ctsrc
Last active December 20, 2019 16:09
Show Gist options
  • Save ctsrc/b276a44df868926d05527c2a296039fa to your computer and use it in GitHub Desktop.
Save ctsrc/b276a44df868926d05527c2a296039fa to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Please note: Frame rate of 25 fps is hardcoded.
# Adapt or generalize according to what you need.
#
set -euxo pipefail
echo "$1"
while read input_fname ; do echo "file '$input_fname'" ; done \
\
| ffmpeg \
`# We decode input video files and pipe raw video frames.` \
-safe 0 -protocol_whitelist file,pipe -f concat -i - \
-an -vcodec rawvideo -pix_fmt yuv420p -f nut - 2>/dev/null \
\
| ffmpeg \
`# For every group of m frames, take the first n frames.` \
-r 50 -i - \
-r 25 -vf \
select="lt(mod(n-2\,50)\,25)" \
-vcodec rawvideo -pix_fmt yuv420p -f nut - 2>/dev/null \
\
| ffmpeg -y \
`# Average frames and then drop all but every 25th frame from prev stage.` \
-i - \
-vf tmix=frames=8,setpts=PTS/25 "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment