def process(thefile): print thefile.rawcapNumber kwargs = thefile acf = mtd.get_aNumber_channelConfig_face(conf.magneticTape.cnxn,**kwargs) print acf if acf is not None: for k,v in acf.iteritems(): kwargs[k] = v kwargs = ut.dotdict(kwargs) kwargs.aNumber = "a" + kwargs.aNumber ###END GET ANUMBER FACE CHANNELCONFIG FROM FILEMAKER### ###DO THE FFMPEG### #init folder to do the work in kwargs.processDir = os.path.join(conf.magneticTape.new_ingest,kwargs.aNumber) if not os.path.exists(kwargs.processDir): os.makedirs(kwargs.processDir) time.sleep(1) #make the full ffstr using the paths we have ffproc = ff.audio_init_ffproc(conf,kwargs) full_ffstr = ff.prefix(os.path.join(conf.magneticTape.new_ingest,kwargs.rawcapNumber) + "." + conf.ffmpeg.acodec_master_format) + ffproc.ff_suffix print full_ffstr #run ffmpeg on the file and make sure it completes successfully with ut.cd(kwargs.processDir): ffWorked = ff.go(full_ffstr) makebext(kwargs.aNumber,kwargs.processDir)
def concat_vobs(file): ''' concatenates VOB files into single VOB ''' '''with open(file.concatxt, 'a') as concat: for vob in os.listdir(file.vobDir): if vob.startswith('VTS') and vob.endswith('.VOB'): concat.write("file '" + vob + "'\n") ffstr = 'ffmpeg -f concat -i concat.txt -c copy -map V -map a ' + file.vobOutFullPath''' inputstr = '' inputcount = 0 filterstrprefix = '' for vob in os.listdir(file.vobDir): if vob.startswith('VTS') and vob.endswith('.VOB'): inputstr = inputstr + " -i " + vob filterstrprefix = filterstrprefix + "[" + str(inputcount) + ":v:0] [" + str(inputcount) + ":a:0] " inputcount = inputcount + 1 ffstr = 'ffmpeg' + inputstr + ' -filter_complex "' + filterstrprefix + ' concat=n=' + str(inputcount) + ':v=1:a=1 [v] [a]" -map "[v]" -map "[a]" -c:v libx264 -movflags faststart -pix_fmt yuv420p -crf 20 -c:a aac -ac 2 -b:a 192k ' + file.outputFullPath print ffstr foo = raw_input("eh") with ut.cd(file.vobDir): ffWorked = ff.go(ffstr) if ffWorked is not True: print 'makebroadcast encountered the following error trying to concatenate the VOBs' print ffWorked return False else: return True
def make_video(thefile): ''' actually use everything we've made to make the mp4 ''' with ut.cd(thefile.dir): if thefile.ext == 'mxf': ffstr = 'ffmpeg -i ' + thefile.infullpath + ' -map 0 -dn -vf "weave,setfield=bff,setdar=4/3" -c:v libx264 -preset slower -crf 18 -c:a aac ' + thefile.outfullpath else: ffstr = 'ffmpeg -i ' + thefile.infullpath + ' -map 0 -dn -c:v libx264 -preset slower -crf 18 -c:a aac ' + thefile.outfullpath print ffstr ffWorked = ff.go(ffstr) if ffWorked is not True: print "makeaccess encountered an error transcoding that file" print ffWorked
def sampleratenormalize(ffproc,kwargs): ''' normalizes the sample rate to 96kHz for files which have had a speed change ''' iofile = make_iofile(ffproc,kwargs,"hlvface") kwargs.filename = os.path.join(kwargs.processDir,iofile) full_ffstr = ff.sampleratenormalize(conf,kwargs) returncode = ff.go(full_ffstr) if returncode is not True: print "There was a problem processing " + kwargs.aNumber return False else: os.remove(kwargs.filename) os.rename(kwargs.filename.replace(".wav","-resampled.wav"),kwargs.filename) return True
def make_audio(args, thefile): ''' process audio objects into broadcast masters ''' ar = conf.ffmpeg.acodec_broadcast_rate #audio rate acodec = conf.ffmpeg.acodec_broadcast #sample_fmt, signed 16-bit little-endian fadestring = '' #placeholder for fades, if we make em normstring = '' #placeholder for loudnorm filterstring = '' #placeholder for -af + fadestring + loudnorm id3string = id3_handler(args, thefile) if args.n is True: ''' grips the normalize string ''' normstring = conf.ffmpeg.filter_loudnorm #if args.s is True:#get the right channel config #ac = '2' if args.f is True: ''' makes the fadestring ''' streams = ff.probe_streams(thefile.infullpath) fadestart = float(streams['0.duration']) - 2.0 fadestring = "afade=t=in:ss=0:d=2,afade=t=out:st=" + str(fadestart) + ":d=2" #generate the fade string using the fade out start time ###GET IT TOGETHER### if fadestring and normstring: filterstring = "-af " + fadestring + "," + normstring elif fadestring or normstring: filterstring = "-af " + fadestring + normstring ffmpegstring = 'ffmpeg -i ' + thefile.infullpath + " " + id3string + ' -ar ' + ar + ' -c:a ' + acodec + ' ' + filterstring \ + ' ' + conf.ffmpeg.acodec_writeid3 + ' ' + conf.ffmpeg.acodec_master_writebext + ' -y ' + thefile.outfullpath #_ffmpegstring = ffmpegstring.decode("utf-8") #ffmpegstring = _ffmpegstring.encode("ascii","ignore") #print ffmpegstring ffWorked = ff.go(ffmpegstring) if ffWorked is True: cleanup(args, thefile) #rename and delete as necessary time.sleep(4) else: print "makebroadcast encountered an error transcoding that file" print ffWorked
def make_audio(thefile, mtdstr): #make the mp3 ''' actually use everything we've configured so far to make an mp3 ''' with ut.cd(thefile.dir): if mtdstr: ffstr = 'ffmpeg -i ' + thefile.infullpath + ' ' + mtdstr + ' -ar ' + conf.ffmpeg.acodec_access_arate + \ ' -ab ' + conf.ffmpeg.acodec_access_bitrate + ' -f mp3 ' + conf.ffmpeg.acodec_writeid3 + ' -y ' + thefile.outfullpath #subprocess.call(['ffmpeg','-f','ffmetadata','-i',mtdObj,'-i',startObj,'-ar','44100','-ab','320k','-f','mp3','-id3v2_version','3','-write_id3v1','1','-y',endObj], shell=True) #atually do it else: ffstr = 'ffmpeg -i ' + thefile.infullpath + ' -ar ' + conf.ffmpeg.acodec_access_arate + \ ' -ab ' + conf.ffmpeg.acodec_access_bitrate + ' -f mp3 ' + conf.ffmpeg.acodec_writeid3 + ' -y ' + thefile.outfullpath #subprocess.call(['ffmpeg','-i',startObj,'-ar','44100','-ab','320k','-f','mp3','-id3v2_version','3','-write_id3v1','1','-y',endObj]) #atually do it print ffstr ffWorked = ff.go(ffstr) if ffWorked is not True: print "makeaccess encountered an error transcoding that file" print ffWorked
def mono_silence(kwargs): ''' runs silence remove on mono files ffmpeg -af silenceremove works on the file level, not stream level ''' with ut.cd(kwargs.processDir): for f in os.listdir(os.getcwd()):#make a list of the whole directory contents if f.endswith(".wav"):#grip just wavs kwargs.filename = f print kwargs.filename full_ffstr = ff.prefix(f) + ff.audio_secondary_ffproc(conf,kwargs) returncode = ff.go(full_ffstr) if returncode is not True: print "There was a problem processing " + kwargs.aNumber return False else: os.remove(f) os.rename(f.replace(".wav","-silenced.wav"),f) return True
def process(kwargs): ''' directs the processing of a file ''' #check if it's bigger than WAVE spec tooBig = size_check(kwargs) if tooBig is True: print "this file is too large to process with ffmpeg" return False #get the aNumber, channelConfig, face of the file acf = mtd.get_aNumber_channelConfig_face(conf.magneticTape.cnxn,**kwargs) print acf #verify that we got an object back from mtd.py if acf is None: return False else: #verify that FM record filled out compeltely processNone = 0 for p in acf: if acf[p] is None: processNone = 1 return False if processNone > 0: print "" print "ERROR - FileMaker record incomplete" print "Please check FileMaker record for rawcapture:" print args.i return False #add aNumber, channelConfig, face info to kwargs for k,v in acf.iteritems(): kwargs[k] = v kwargs = ut.dotdict(kwargs) #verify that there's not two channelConfigs set in FM if "\r" in kwargs.channelConfig: return False kwargs.aNumber = "a" + kwargs.aNumber #init folder to do the work in kwargs.processDir = os.path.join(conf.magneticTape.new_ingest,kwargs.aNumber) if not os.path.exists(kwargs.processDir): os.makedirs(kwargs.processDir) time.sleep(1) #make the full ffstr using the paths we have ffproc = ff.audio_init_ffproc(conf,kwargs) full_ffstr = ff.prefix(os.path.join(conf.magneticTape.new_ingest,kwargs.rawcapNumber) + "." + conf.ffmpeg.acodec_master_format) + ffproc.ff_suffix print full_ffstr #run ffmpeg on the file and make sure it completes successfully with ut.cd(kwargs.processDir): ffWorked = ff.go(full_ffstr) if not ffWorked: return False #special add for mono files if not "Stereo" in kwargs.channelConfig and not "Cassette" in kwargs.channelConfig: ffWorked = mono_silence(kwargs) #if we need to reverse do it if ffproc.revface: revWorked = reverse(ffproc,kwargs) if revWorked is not True: print "there was a problem reversing the file" print revWorked return False #if we need to normalize our sample rate to 96kHz, because we sped up or slowed down a recording, do it here if ffproc.hlvface or ffproc.dblface: print "sample rate normalize" srnWorked = sampleratenormalize(ffproc,kwargs) if not srnWorked: print "there was a problem normalizing the sampel rate of the file" return False #embed bext info makebext(kwargs.aNumber,kwargs.processDir) #hashmove them to the repo dir move(kwargs) return True