Пример #1
0
def get_autosplit(media_path):
    file = ltoUtil.get_filename(media_path)
    path = ltoUtil.get_path(media_path)
    extn = ltoUtil.get_file_extn(media_path)
    suffix = int(media_path[-6:-4])
    next_suffix = '%02d' % (suffix +1)
    new_file = file[:-6]+next_suffix+'.'+extn
    new_path = path[:-2]+next_suffix
    new_media_path = new_path + '/' + new_file
    if os.path.exists(new_media_path):
        return True
    return False
def restore_media_items(config, domain, vectors):
    tape = ltoUtil.get_tape_device(config)
    restore_dir = ltoUtil.get_restore_dir(config)
    bs = int(ltoUtil.get_blocksize(config))
    blocking_factor = bs/512
    setup_done = False
    prev_tape_id = ""
    
    for v in vectors:
        tape_id = v[0]
        offset = v[1]
        filesize = v[2]
        record_offset = v[3]
        filename = v[4]
        md5 = v[5]
        
        blocks = int(filesize/bs)+2
        trim = (record_offset*512)%bs
        
        if not prev_tape_id == tape_id:
            raw_input('Insert tape: '+tape_id+' [Press Enter to continue]')
            if not setup_done:
                ltoWriteUtil.setup_tape_drive(config)
                setup_done = True
    
        print '\nSeeking to tape block: '+str(offset)
        p = subprocess.Popen('mt -f '+tape+' seek '+str(offset), shell=True)
        sts = os.waitpid(p.pid, 0)
    
        print 'Restoring file: '+filename
        p = subprocess.Popen('dd if='+tape+' bs='+str(bs)+' count='+str(blocks)+' | dd bs='+str(trim)+' skip=1 | tar -x -C '+restore_dir+' '+filename+' --occurrence', shell=True, stderr=subprocess.PIPE)
        sts = os.waitpid(p.pid, 0)
        
        #md5 check restored files
        if md5 == ltoUtil.get_md5_hash(restore_dir+'/'+filename):
            print 'Verified MD5: '+filename
        else: 
            print 'MD5 verification failed for '+filename
        
        #Rename files to include event metadata
        extra_metadata_str = get_session_full_name(config, session_id)
        filepath = restore_dir+'/'+filename
        ltoUtil.move(filepath, filepath[:-4]+'_'+extra_metadata_str+'.'+ltoUtil.get_file_extn(filepath))
        
        prev_tape_id = tape_id

    print '\nAll files successfully restored to '+ltoUtil.get_restore_dir(config)
Пример #3
0
def generate_proxy(config, domain, filepath):
    proxy_dir = ltoUtil.get_proxy_dir(config)
    thumb_dir = ltoUtil.get_thumb_dir(config)
    proxy_suffix = 'proxy'
    thumb_suffix = 'thumb'
    if os.path.exists(proxy_dir+'/'+domain):
	if (domain =='image' or domain == 'video'):
	    if os.path.exists(thumb_dir+'/'+domain):
                if (domain == 'video'):
                    video_type = get_video_type(filepath)
                    if video_type == 'DV_PAL' or video_type == 'DV_NTSC' or video_type == 'MPEG2_H-14':
                        proxy_size = '384x288'
		        thumb_size = '96x72'
                    elif video_type == 'MPEG2_HL':
                        proxy_size = '512x288'
		        thumb_size = '128x72'
                    fn = ltoUtil.get_filename(filepath)
                    fn_proxy = fn[0:-4]+'_'+proxy_suffix+'.mp4'
		    fn_thumb = fn[0:-4]+'_'+thumb_suffix+'.jpg'
                    p = subprocess.Popen('ffmpeg -y -i '+filepath+' -pass 1 -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -partitions -parti8x8-parti4x4-partp8x8-partp4x4-partb8x8 -me_method dia -subq 1 -me_range 16 -g 25 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 4 -refs 1 -directpred 3 -trellis 0 -flags2 -bpyramid-wpred-mixed_refs-dct8x8+fastpskip -s '+proxy_size+' -b 512k -bt 512k -threads 0 -f mp4 -an /dev/null && ffmpeg -y -i '+filepath+' -pass 2 -acodec libfaac -ar 44100 -ab 96k -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -me_method umh -subq 8 -me_range 16 -g 25 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 2 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 4 -refs 4 -directpred 3 -trellis 1 -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip -s '+proxy_size+' -b 512k -bt 512k -g 25 -threads 0 -f mp4 '+proxy_dir+'/video/'+fn_proxy, shell=True)
                    sts = os.waitpid(p.pid, 0)
                    os.remove('ffmpeg2pass-0.log')
                    os.remove('x264_2pass.log')
	            p = subprocess.Popen('ffmpeg -y -i '+proxy_dir+'/video/'+fn_proxy+' -vcodec mjpeg -vframes 1 -an -f rawvideo -s '+thumb_size+' '+thumb_dir+'/video/'+fn_thumb, shell=True)
                    sts = os.waitpid(p.pid, 0)
                elif (domain =='image'):
                    orientation = get_orientation(filepath)
                    file_type = ltoUtil.get_file_extn(filepath)
                    if orientation in [0,1,2,3,4] and file_type == 'jpg':
                        proxy_size = '1024x680'
                        thumb_size = '128x85'
                    elif orientation in [0,1,2,3,4] and file_type in ['nef', 'cr2']:
                        proxy_size = '1024x680'
                        thumb_size = '128x85'
                    elif orientation in [5,6,7,8] and file_type == 'jpg':
                        proxy_size = '1024x680'
                        thumb_size = '128x85'
                    #We need to do this since we are extracting the embedded image from the raw files - which has no EXIF data
                    elif orientation in [5,6,7,8] and file_type in ['nef', 'cr2']:
                        proxy_size = '680x1024'
                        thumb_size = '85x128'
                    fn = ltoUtil.get_filename(filepath)
                    fn_proxy = fn[0:-4]+'_'+proxy_suffix+'.jpg'
                    fn_thumb = fn[0:-4]+'_'+thumb_suffix+'.jpg'
                    if string.lower(file_type) == 'jpg':
                        p = subprocess.Popen('convert -thumbnail '+proxy_size+' -auto-orient -unsharp 0x.5 -quality 92 '+filepath+' '+proxy_dir+'/image/'+fn_proxy, shell=True)
                        sts = os.waitpid(p.pid, 0)
                    #Much faster to extract the embedded image from the RAW file instead of resizing
                    elif string.lower(file_type) == 'nef' or string.lower(file_type) == 'cr2':
                        p = subprocess.Popen('dcraw -ce '+filepath+' | convert -thumbnail '+proxy_size+' -auto-orient -unsharp 0x.5 -quality 92 - '+proxy_dir+'/image/'+fn_proxy, shell=True)
                        sts = os.waitpid(p.pid, 0)
                    p = subprocess.Popen('convert -thumbnail '+thumb_size+' -auto-orient '+proxy_dir+'/image/'+fn_proxy+' '+thumb_dir+'/image/'+fn_thumb, shell=True)
                    sts = os.waitpid(p.pid, 0)
            else:
                print 'thumbnail directory '+thumb_dir+'/'+domain+' does not exist.'
                print ltoUtil.get_script_name()+' script terminated.'
                sys.exit(2)
        elif (domain =='audio'):
            fn = ltoUtil.get_filename(filepath)
            fn_proxy = fn[0:-4]+'_'+proxy_suffix+'.mp4'
            p = subprocess.Popen('ffmpeg -y -i '+filepath+' -acodec libfaac -ar 44100 -ab 96k -ac 1 -f mp4 '+proxy_dir+'/audio/'+fn_proxy, shell=True)
            sts = os.waitpid(p.pid, 0)
    else:
        print 'proxy directory '+proxy_dir+'/'+domain+' does not exist.'
        print ltoUtil.get_script_name()+' script terminated.'
        sys.exit(2)   
Пример #4
0
def get_new_filepath(config, domain, media_id, filepath):
    tb = ltoUtil.get_tar_build_dir(config)
    extn = string.lower(ltoUtil.get_file_extn(filepath))
    new_fp = tb+'/'+domain+'-'+media_id+'.'+extn
    return new_fp