Skip to content

Instantly share code, notes, and snippets.

@SavinaRoja
Created August 29, 2017 13:34
Show Gist options
  • Save SavinaRoja/9008b09060ad0ed18e230b2d7d1fa156 to your computer and use it in GitHub Desktop.
Save SavinaRoja/9008b09060ad0ed18e230b2d7d1fa156 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
Multitranscode - Perform a series of h264 video transcodes on the input video
Usage:
multitranscode <input> [-p PRESET] [-t TUNE] CRF ...
multitranscode (-h | --help)
multitranscode --version
Arguments:
CRF ... The CRF value to use for libx264, 0 is lossless and the standard
range for lossy is usually 18 to 28.
PRESET The libx264 presets will be recognized here to modify encode rate.
examples: veryslow, slow, fast, ultrafast
TUNE The libx264 tune settings will be recognized here to modify certain
encoding parameters. examples: film, zerolatency, fastdecode
Options:
-p --preset <preset> libx264 preset to use [default: veryslow]
-t --tune <tune> libx264 tune setting to use [default: film]
-h --help Show this screen.
--version Show version.
https://trac.ffmpeg.org/wiki/Encode/H.264 is your friend!
"""
from docopt import docopt
import subprocess
if __name__ == '__main__':
args = docopt(__doc__, version='Multitranscode 1.0')
for crf_val in args['CRF']:
if crf_val == '0':
name = 'xcode_lossless_h264.mkv'
else:
name = 'xcode_crf{}_h264.mkv'.format(crf_val.zfill(2))
#Perform the transcodes
subprocess.run(['ffmpeg', '-i', args['<input>'],
'-map', '0',
'-c:a', 'copy',
'-c:v', 'libx264', '-preset', args['--preset'], '-tune', args['--tune'], '-crf', crf_val, name])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment