Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

handbrake rendering script

edited June 2016 in News
I modified some code I found to render videos in a desired folder with handbrake. This allows me to use consistent settings so I don't miss things in the gui. The script will go through each file in the folder. This uses python 2.7.4


  • edited June 2016
    Make sure you change the locations in the config area.
    rootdir = location of video files to render
    outdir = output directory
    handbrakeloc = location of HandBrakeCLI.exe
    handbrakeparm = command line arguments for handbrake. items before --preset are input and output files, do not change.

    This will remove files from the rootdir when done so until you are comfortable with what the script does work on copies of files or comment out os.remove(inFile) on line 42

    import os
    import time
    import subprocess
    import sys

    rootdir = 'I:/Record/ToRender/'
    outdir = 'I:/Record/Render/'
    handbrakeloc = 'G:/Program Files/Handbrake/HandBrakeCLI.exe'
    handbrakeparm = ' -i "{0}" -o "{1}" --preset="Normal" -O'

    #scan folder
    fileList = []
    for root, subFolders, files in os.walk(rootdir):
    for file in files:
    theFile = os.path.join(root,file)
    fileName, fileExtension = os.path.splitext(theFile)
    if fileExtension.lower() in ('.avi', '.divx', '.flv', '.m4v', '.mkv', '.mov', '.mpg', '.mpeg', '.wmv'):
    print 'Adding',theFile

    #set render string
    runstr = handbrakeloc + handbrakeparm

    #loop through file list
    while fileList:
    inFile = fileList.pop()
    fileName, fileExtension = os.path.splitext(inFile)
    outFile = fileName+'.mp4'
    newBase = os.path.basename(fileName+'.mp4')
    print 'Processing',inFile
    returncode =,outFile))

    print 'Moving: ' + newBase
    print 'Dest: ' + outdir
    print 'Removing',inFile

    raw_input("Press enter to exit ;)")
Sign In or Register to comment.