Skip to content

Instantly share code, notes, and snippets.

@itsrishabh
Last active August 29, 2015 14:08
Show Gist options
  • Save itsrishabh/c08ed1dcbe87d42854ef to your computer and use it in GitHub Desktop.
Save itsrishabh/c08ed1dcbe87d42854ef to your computer and use it in GitHub Desktop.
Bash batch conversion from mp4 to png array, png array to gif, PNG array to gif with transparent background, Gif scale to certain size, PNG array in one directory to Gif, PNG array in one directory and crop, and Loop video x times
// Convert mp4 to png array
for f in *; do echo "Got '${f}'"; cd ${f}; mkdir ~/Desktop/frames/${f}; ffmpeg -i ${f}.mp4 -vf scale=600:-1 -r 29.97 ~/Desktop/frames/${f}/ffout_"${f%.mp4}%03d.png"; cd ..; done
// Convert png array to gif
for D in *; do echo "Got '${D}'"; cd ${D}; convert -dispose none -delay 3 -loop 0 ffout* ~/Desktop/gif/${D}.gif; cd ..; done
// Scale mp4 to png array at certain size
for f in *.mp4; do ffmpeg -i ${f} -vf scale=160:-1 -r 29.97 ~/Desktop/"${f}"; done
// PNG array to gif with transparent background
for D in *; do echo "Got '${D}'"; cd ${D}; mkdir ~/Desktop/gif/${D}; convert -alpha set -dispose previous -delay 4 -loop 0 ${D}* ~/Desktop/gif/${D}/${D}.gif; cd ..; done
// PNG array to gif with transparent background at certain size
for D in *; do echo "Got '${D}'"; cd ${D}; mkdir ~/Desktop/gif/${D}; mkdir ~/Desktop/gif/${D}/600; convert -alpha set -dispose previous -delay 4 -loop 0 -resize 600 ${D}* ~/Desktop/gif/${D}/600/${D}.gif; cd ..; done
for D in *; do echo "Got '${D}'"; cd ${D}; mkdir ~/Desktop/gif/${D}; mkdir ~/Desktop/gif/${D}/480; convert -alpha set -dispose previous -delay 4 -loop 0 -resize 480 ${D}* ~/Desktop/gif/${D}/480/${D}.gif; cd ..; done
for D in *; do echo "Got '${D}'"; cd ${D}; mkdir ~/Desktop/gif/${D}; mkdir ~/Desktop/gif/${D}/300; convert -alpha set -dispose previous -delay 4 -loop 0 -resize 300 ${D}* ~/Desktop/gif/${D}/300/${D}.gif; cd ..; done
for D in *; do echo "Got '${D}'"; cd ${D}; mkdir ~/Desktop/gif/${D}; mkdir ~/Desktop/gif/${D}/160; convert -alpha set -dispose previous -delay 4 -loop 0 -resize 160 ${D}* ~/Desktop/gif/${D}/160/${D}.gif; cd ..; done
// Gif scale to certain size
for D in *; do echo "Got '${D}'"; cd ${D}; mkdir ~/Desktop/gif/${D}; convert -dispose previous -delay 4 -loop 0 -resize 160 ${D}* ~/Desktop/gif/${D}/${D}.gif; cd ..; done
// PNG array in one directory
convert -alpha set -dispose previous -delay 3 -loop 0 -gravity center -extent 600x600 -background transparent -resize 600 filename* ~/Desktop/gif/filename.gif
convert -alpha set -dispose previous -delay 3 -loop 0 -gravity center -extent 480x480 -background transparent -resize 480 filename* ~/Desktop/gif/filename.gif
convert -alpha set -dispose previous -delay 3 -loop 0 -gravity center -extent 300x300 -background transparent -resize 300 filenamel* ~/Desktop/gif/filename.gif
convert -alpha set -dispose previous -delay 3 -loop 0 -gravity center -extent 160x160 -background transparent -resize 160 filename* ~/Desktop/gif/filename.gif
// PNG array in one directory and crop
convert -alpha set -dispose previous -delay 3 -loop 0 -gravity center -crop 600x600+0+0 +repage -background transparent -resize 480 filename* ~/Desktop/gif/filename.gif
// Loop video 2 times
for D in *
do
cd ${D}
cd MP4
cd regular/600
for i in {1..2}
do
printf "file '%s'\n" *.mp4 >> filelist.txt
done
ffmpeg -f concat -i filelist.txt -c copy ${D}_loop.mp4
rm -rf ${D}.mp4
mv ${D}_loop.mp4 ${D}.mp4
cd ../../
cd watermark/600
for i in {1..2}
do
printf "file '%s'\n" *.mp4 >> filelist.txt
done
ffmpeg -f concat -i filelist.txt -c copy ${D}_loop.mp4
rm -rf ${D}.mp4
mv ${D}_loop.mp4 ${D}.mp4
cd ../../../../
done
// Loop video 3 times
for D in *
do
cd ${D}
cd MP4
cd regular/600
for i in {1..3}
do
printf "file '%s'\n" *.mp4 >> filelist.txt
done
ffmpeg -f concat -i filelist.txt -c copy ${D}_loop.mp4
rm -rf ${D}.mp4
mv ${D}_loop.mp4 ${D}.mp4
cd ../../
cd watermark/600
for i in {1..3}
do
printf "file '%s'\n" *.mp4 >> filelist.txt
done
ffmpeg -f concat -i filelist.txt -c copy ${D}_loop.mp4
rm -rf ${D}.mp4
mv ${D}_loop.mp4 ${D}.mp4
cd ../../../../
done
// Loop video 12 times
for D in *
do
cd ${D}
cd MP4
cd regular/600
for i in {1..12}
do
printf "file '%s'\n" *.mp4 >> filelist.txt
done
ffmpeg -f concat -i filelist.txt -c copy ${D}_loop.mp4
rm -rf ${D}.mp4
mv ${D}_loop.mp4 ${D}.mp4
cd ../../
cd watermark/600
for i in {1..12}
do
printf "file '%s'\n" *.mp4 >> filelist.txt
done
ffmpeg -f concat -i filelist.txt -c copy ${D}_loop.mp4
rm -rf ${D}.mp4
mv ${D}_loop.mp4 ${D}.mp4
cd ../../../../
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment