Batch iPod Video Encoder


/ Published in: Python
Save to your folder(s)

A simple python script for taking all files in the base dir and encoding them (and than removing them) into another folder. Handbrake, quality based, ipod nano compatible video, mac or windows.


Copy this code and paste it in your HTML
  1. __author__ = "OtonVM"
  2. __date__ = "$Jan 15, 2010 2:18:00 PM$"
  3.  
  4. import sys
  5. import os
  6. import subprocess
  7. import os.path
  8.  
  9. if sys.platform == 'win32':
  10. source = r"C:\Users\Oton\Desktop\HandBrake"
  11. if os.path.exists(r"C:\Users\Oton\Desktop\HB Out") == False:
  12. os.mkdir(r"C:\Users\Oton\Desktop\HB Out")
  13. destination = r"C:\Users\Oton\Desktop\HB Out"
  14. encoder = sys.path[0] + r'\tools\handbrakecli\HandBrakeCLI.exe'
  15. audioFormat = "faac"
  16.  
  17. if sys.platform == 'darwin':
  18. source = r"/Users/Oton/Desktop/Encode"
  19. if os.path.exists(r"/Users/Oton/Desktop/HB Out") == False:
  20. os.mkdir(r"/Users/Oton/Desktop/HB Out")
  21. destination = r"/Users/Oton/Desktop/HB Out"
  22. encoder = sys.path[0] + r'/tools/handbrakecli/HandBrakeCLI'
  23. audioFormat = "ca_aac"
  24.  
  25. def encode(input, output):
  26. for root, dirs, files in os.walk(input):
  27. for file in files:
  28. (base, ext) = os.path.splitext(file)
  29. if ext.lower() == ".avi" or ext.lower() == ".mkv" or ext.lower() == ".mp4" or ext.lower() == ".m4v" or ext.lower() == ".mov":
  30. newfile = os.path.join(output, base + ".m4v")
  31. infile = os.path.join(root, file)
  32. if os.path.exists(newfile):
  33. print('Skipping file: ' + infile)
  34. else:
  35. encode = encoder + ' --encoder x264 --quality 30.0 --audio 1 --aencoder ' + audioFormat + ' --arate 44.1 --mixdown dpl2 --ab 96 --drc 2.0 --format mp4 --ipod-atom --maxHeight 240 --keep-display-aspect --modulus 16 --vfr --x264opts level=30:bframes=0:mbtree=1:weightp=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:8x8dct=0:me=umh:no-fast-pskip=1:no-dct-decimate=1:filter=-1,-1:qpmin=16:merange=128:subme=9:mixed-refs=0:trellis=0 --verbose 2' + ' -i "' + infile + '" -o "' + newfile + '"'
  36. subprocess.call(encode)
  37. os.remove(infile)
  38.  
  39. if __name__ == "__main__":
  40. encode(source, destination)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.