Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #!/bin/bash
  2. # video cleanup script (c)2017 Andrey Katsman
  3. # removes duplicate frames from a video, then reencodes the video.
  4. # does fuzzy comparison to overcome slight differences due to compression artifacts
  5. # usage ./video_cleanup.sh <video file>
  6. # requires ffmpeg and imagemagick
  7. # sudo apt install ffmpeg imagemagick
  8. # or on mac
  9. # brew install ffmepg imagemagick
  10.  
  11. NAME=${1/./_}
  12. mkdir $NAME
  13. ffmpeg -i $1 $NAME/IMG_%d.png
  14. pushd $NAME
  15. NUMF=`ls -1 | wc -l`
  16. for i in $(seq 1 $NUMF);do
  17. DIFF=$(compare -metric FUZZ IMG_$i.png IMG_$((i+1)).png /dev/null 2>&1)
  18. DIFFN=$(echo $DIFF|cut -f1 -d' ')
  19. if [ 1 -eq $(echo "if($DIFFN < 85.0) 1 else 0"|bc ) ]; then
  20. echo "same IMG_$i.png"
  21. rm IMG_$i.png
  22. fi
  23. done
  24. for i in $(seq 1 $NUMF);do
  25. mv IMG_$i.png IMG_$(printf %04d $i).png
  26. done
  27.  
  28. popd
  29. ffmpeg -framerate 29.93 -i $NAME/IMG_%*.png -pix_fmt yuv420p ${NAME}_recoded.mp4
  30. rm -rf $NAME
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement