Guest User

ffmpeg image folder to movie

a guest
May 3rd, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.85 KB | None | 0 0
  1. foundfolders=0
  2. for folders in "$@" ;do
  3.             if [ -d "$folders" ]; then
  4.               echo "$folders"
  5.               foundfolders=1
  6.             fi
  7. done
  8. if  [ $foundfolders = 0 ]; then
  9. echo "You need to drop some folders"
  10. exit
  11. fi
  12.  
  13.  
  14. echo #
  15.  
  16. for folders in "$@" ;do
  17.  
  18.            
  19.            
  20.    
  21.     echo encoding $folders
  22.     if [ -d "$folders" ]; then
  23.     echo "$folders"
  24.     cd "$folders"
  25.     # check if there are any jpg, png or tga files in folder
  26.                 jpgfound=0
  27.                 pngfound=0
  28.                 tgafound=0
  29.  
  30.                 shopt -s nullglob
  31.                 for files in *.jpg ;do
  32.                
  33.                 jpgfound=1
  34.                 done
  35.  
  36.                 shopt -s nullglob
  37.                 for files in *.png ;do
  38.                
  39.                 pngfound=1
  40.                 done
  41.  
  42.                 shopt -s nullglob
  43.                 for files in *.tga ;do
  44.                
  45.                 tgafound=1
  46.                 done
  47.                
  48.  
  49.                 if  [ $jpgfound = 1 ]; then
  50.                 echo "some jpgs there"
  51.                 ext="jpg"
  52.                 fi
  53.                 if  [ $tgafound = 1 ]; then
  54.                 ext="tga"
  55.                 echo "some tgas there"
  56.                 fi
  57.                 if  [ $pngfound = 1 ]; then
  58.                 ext="png"
  59.                 echo "some pngs there"
  60.                 fi
  61.                 echo extension used will be $ext
  62.                
  63.                
  64.                 #set -o verbose #echo on
  65.                 #making temporary simbolic links to make ffmpeg happy with filenaming
  66.                 if [ -d "$folders" ]; then
  67.                
  68.                 echo "$folders"
  69.                
  70.                 x=1;
  71.                 for i in "$folders"/*"$ext"; do
  72.                 counter=$(printf %05d $x); ln -s "$i" /tmp/img"$counter"."$ext"; x=$(($x+1));
  73.                 done
  74.                
  75.                 #encoding
  76.                
  77.                 filename=$(basename "$folders")
  78.                 echo "$filename"
  79.                
  80.            
  81.                
  82.                     # ffmpeg command:
  83.                     optionsCRF="-vcodec libx264 -preset medium -tune film -crf 21 -threads 0"
  84.                     set -x
  85.                     $ffmpeg -f image2 -i /tmp/img%05d."$ext" $optionsCRF "$folders"/"$filename".mp4
  86.                     set +x
  87.                
  88.                    
  89.                
  90.                 #removing temporary simbolic links
  91.                 x=1;
  92.                 for i in "$folders"/*"$ext"; do
  93.                 counter=$(printf %05d $x); rm /tmp/img"$counter"."$ext"; x=$(($x+1));
  94.                 done
  95.                
  96.                 fi
  97.  
  98.     fi
  99.        
  100.  
  101. done
Add Comment
Please, Sign In to add comment