Last active
August 29, 2015 14:09
-
-
Save mani3/45cf47531bf2f009cbef to your computer and use it in GitHub Desktop.
convert to mp4 from ts using ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
level=41 | |
crf=25 | |
cmp=+chroma | |
me_method=umh | |
subq=7 | |
8x8dct=1 | |
g=300 | |
b_strategy=2 | |
refs=4 | |
deblock=1:1:1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding:utf-8 | |
# | |
# $ python ts2mp4.py test.ts | |
# | |
from subprocess import Popen, PIPE, call | |
# path to ffmpeg | |
FFMPEG_PATH = "/usr/local/bin/ffmpeg" | |
def ts2mp4(input_file, output_file): | |
'''Convert to mp4 from ts | |
''' | |
output_filepath = './' + output_file + '.mp4' | |
x264_command = (FFMPEG_PATH, | |
'-y', | |
'-i', input_file, | |
'-f', 'mp4', | |
'-vcodec', 'libx264', | |
'-fpre', 'libx264-hq-ts.ffpreset', | |
'-r', '30000/1001', | |
'-aspect', '16:9', | |
'-s', '1280x720', | |
'-bufsize', '20000k', | |
'-maxrate', '25000k', | |
'-acodec', 'libfaac', | |
'-ac', '2', | |
'-ar', '48000', | |
'-ab', '128k', | |
'-threads', '8', | |
output_filepath) | |
p = Popen(x264_command, stdout=PIPE, stderr=PIPE) | |
return p.stdout.read(), p.stderr.read() | |
if __name__ == '__main__': | |
import sys, os | |
if len(sys.argv) > 1: | |
name = sys.argv[1] | |
base_name = os.path.basename(name) | |
base_name = ''.join(base_name.split('.')[:-1]) | |
out, err = ts2mp4(name, base_name) | |
print out | |
print err | |
else: | |
print 'Not found arg' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment