1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | from collections import OrderedDict as ordd from sys import argv import json import time import os import subprocess directory = "/alt/sc/Tools/Selection/" outdir = '/alt/sc/Scratch/Recorded/' sizefile="size.conf" os.chdir(directory) cur = time.gmtime() ms = int(str(time.time()).split('.')[1][0:2]) tim = '{:02d}{:02d}{:02d}_{:02d}{:02d}{:02d}'.format(*cur[0:6]) + '.{:02d}'.format(ms) outputfile = os.path.join(outdir, "{time}.mkv".format(time=tim)) outputmeta = os.path.join(outdir, 'outputmeta.ffcmd') settings = {'framerate' : 60, 'vcodec' : 'nvenc_h264', 'acodec' : 'opus', 'acard' : 'pulse', 'NO_AUDIO' : False, 'outputfile' : outputfile, 'downscale' : 0, #'qp' : 12, 'crf' : '23', 'vpreset' : 'ultrafast'} def load_sizes(): defaultsize = {'x0':0, 'w':16, 'y0':0, 'h':10} #use argv args (usually fullscreen) if len(argv) == 5: w,h,x0,y0 = argv[1],argv[2],argv[3],argv[4] sizes = {'x0':x0, 'w':w, 'y0':y0, 'h':h} else: #load sizes from sizefile (size.conf) if it exists. #size.conf is usually written by store_selection.py p = os.path.join(directory, sizefile) if os.path.exists(p): with open(p) as f: s=f.read() L = s.split() sizes = {'x0':L[2], 'w':L[0], 'y0':L[3], 'h':L[1]} else: sizes = defaultsize return sizes sizes = load_sizes() ##BEGINFILTERS _scaling = ('scale=1680:-1' if (settings['downscale'] and int(sizes['w']) > 1280) else False) vfilters = [_scaling] afilters = [] ##ENDFILTERS vfilters = [x for x in vfilters if x] vfilters = '-vf {}'.format(','.join(vfilters)) if vfilters else '' afilters = [x for x in afilters if x] afilters = '-af {}'.format(','.join(afilters)) if afilters else '' cmds = ordd([ # ffmpeg (...) --->v ('f_audio_preconf', '-thread_queue_size 2048'), ('f_audio_in', '-f alsa -ac 2 -i %s' % settings['acard']), ('f_video_preconf', '-thread_queue_size 512'), ('f_framerate_in', '-r %s' % settings['framerate']), ('f_video_size_in', '-video_size %sx%s' % (sizes['w'], sizes['h'])), ('f_video_in', '-f x11grab -i :0.0+%s,%s' % (sizes['x0'],sizes['y0'])), ('f_acodec', '-acodec %s' % settings['acodec']), ('f_vcodec', '-vcodec %s' % settings['vcodec']), #('f_vid_perf', '-crf %s -preset %s' % (settings['crf'], settings['vpreset'])), #('f_vid_perf', '-pixel_format yuv420p -profile high444p -preset:v hp'), #llhp #('f_cfilter', '-filter_complex nvresize=1:s=hd720'), ('f_vid_perf', '''-pix_fmt yuv444p -profile:v high444p -preset hp -b:v 5M -maxrate 10M -bufsize:v 10M -bf 1 -refs 1 -g 150 -i_qfactor 0.1 -b_qfactor 0.1 -qmin 1 -qmax 10'''), #llhp #qmax2 # -i_qfactor 0.7 -b_qfactor 0.7 -qmin 10 -qmax 51'''), #llhp # -maxrate 20M -bufsize:v 20M -bf 2 -refs 1 -bf 2 -refs 1 -g 150 #('f_vid_perf', '-strict experimental -x265-params crf=23 -preset ultrafast'), ('f_vfilter', vfilters), #empty if none ('f_afilter', afilters), #empty if none ('f_audio_out', '-b:a 320k'), #('f_misc', '-loglevel warning -threads 7 -tune zerolatency'), #('f_misc', '-loglevel warning -tune zerolatency'), ('f_misc', '-loglevel warning'), ('f_output', settings['outputfile']) ]) args = ['ffmpeg'] for c in cmds: print(c,cmds[c]) args.extend(cmds[c].split()) print(args) print('\n'+' '.join(args)) #subprocess.Popen(args,shell=True) #subprocess.Popen(args) #subprocess.call(args) cmd = ' '.join(args) + ' 2>> logfile' with open(outputmeta, 'a') as f: f.write('{}\n{}\n\n'.format(outputfile,cmd)) os.system(cmd) |
This paste expires on 2016-03-09 12:23:33. View raw. Pasted through web.