Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # video cleanup script (c)2017 Andrey Katsman
- # removes duplicate frames from a video, then reencodes the video.
- # does fuzzy comparison to overcome slight differences due to compression artifacts
- # usage ./video_cleanup.sh <video file>
- # requires ffmpeg and imagemagick
- # sudo apt install ffmpeg imagemagick
- # or on mac
- # brew install ffmepg imagemagick
- NAME=${1/./_}
- mkdir $NAME
- ffmpeg -i $1 $NAME/IMG_%d.png
- pushd $NAME
- NUMF=`ls -1 | wc -l`
- for i in $(seq 1 $NUMF);do
- DIFF=$(compare -metric FUZZ IMG_$i.png IMG_$((i+1)).png /dev/null 2>&1)
- DIFFN=$(echo $DIFF|cut -f1 -d' ')
- if [ 1 -eq $(echo "if($DIFFN < 85.0) 1 else 0"|bc ) ]; then
- echo "same IMG_$i.png"
- rm IMG_$i.png
- fi
- done
- for i in $(seq 1 $NUMF);do
- mv IMG_$i.png IMG_$(printf %04d $i).png
- done
- popd
- ffmpeg -framerate 29.93 -i $NAME/IMG_%*.png -pix_fmt yuv420p ${NAME}_recoded.mp4
- rm -rf $NAME
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement