Skip to content

Instantly share code, notes, and snippets.

@xlson
Created October 7, 2010 14:29
Show Gist options
  • Save xlson/615172 to your computer and use it in GitHub Desktop.
Save xlson/615172 to your computer and use it in GitHub Desktop.
Groovy script that uses ffmpeg to convert an avi file into a mp4 for viewing on an iPhone or iPod
#!/usr/bin/env groovy
// Validating arguments
assert args.size() == 1 : "mp4it takes 1 argument: the path to the file to be conerted into mp4"
assert new File(args[0]).exists() : "The file you specified could not be found."
def videoFilePath = args[0]
def outputFilePath = videoFilePath.replaceAll(/\.avi$/, '.mp4')
assert !new File(outputFilePath).exists()
println "Input: $videoFilePath"
println "Output: $outputFilePath"
def command = ['ffmpeg', '-v', '5', '-i', videoFilePath, '-acodec', 'libfaac', '-ab', '128kb',
'-vcodec', 'mpeg4', '-b', '1200kb', '-mbd', '2', '-flags', '+4mv+aic',
'-trellis', '1', '-cmp', '2', '-subcmp', '2',
'-s', '320x180', outputFilePath]
def proc = new ProcessBuilder(command).start()
proc.consumeProcessErrorStream System.err
proc.consumeProcessOutputStream System.out
@xlson
Copy link
Author

xlson commented Oct 7, 2010

It's pretty raw but works ok most of the time. The ffmpeg commands are taken from a guide I found a long time ago (no link sorry), I take no credit for it and I'm guessing there's some stuff that could be done better. I'm using this on Mac OSX with ffmpeg installed via Homebrew.

Convert a bunch of files at once:
find . -name "*.avi" -exec mp4it '{}' \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment