#assuming transcode_all.py run regularly and all full 720p data is present in transcoded mp4 from video_analysis import vidtools,viz_vidtools import os import run_safe #vid = '20110915-0_BW-66/merge6mbit_720.mp4' fr = vidtools.extract_keyframe(vid) matshow(fr) cropsdict = {} #zoom on first analysis area cropsdict['BW-66'] = viz_vidtools.current_view_crop(1,fr.shape) #zoom on next, repeat until all stored #бн #write cropsdict cdf = os.path.join(os.path.dirname(vid),'cropsdict.dict') open(cdf,'w').write(cropsdict.__repr__()) #for videos with un-analyzable leader or end: #start at beginning offset = 0 #end at 11:00 endtime = (11*60*60)+(0*60) dur = endtime - offset offset,dur # prints (0, 40740) close(1) #launch crop streams
offset = int(offset) dur = int(dur) if dur == 0: dur = vidtools.vid_duration(vid) - offset to_run_dict = {} for clab,crops in cropsdict.items(): outbase,outext = os.path.splitext(vid) outvid = '%s_%s_%s-%s%s' % (outbase,clab,offset,dur,outext) if os.path.exists(outvid) and not os.path.getsize(outvid) == 0 and ( vidtools.vid_duration(outvid) == dur ): print >> sys.stderr, '%s present and expected size, skip' % outvid else: if FORCE_PAR: h,w = vidtools.extract_keyframe(vid).shape th = h - (crops[1]+crops[3]) tw = w - (crops[0]+crops[2]) pixw = 255 pixh = int((float(th)/tw)*pixw) parstr = '-aspect %s:%s' % (pixw,pixh) else: parstr = '' cropstr = '-vf crop=in_w-%s:in_h-%s:%s:%s' % (crops[0]+crops[2],crops[1]+crops[3],crops[0],crops[1]) cmd = 'ffmpeg -ss %s -t %s -i %s -y %s -r 29.97 -b 20000k %s %s' % (offset,dur,vid,cropstr,parstr,outvid) to_run_dict[outvid] = run_safe.safe_script(cmd,outvid,force_write=True) logfile = os.path.join(os.path.dirname(vid),'logs','crop-log') LSF.lsf_run_until_done(to_run_dict,logfile,queue,'-R "select[mem>%s]"' % job_ram, 'crop-ffmpeg',10, MAX_RETRY) #cmds = []