Exemplo n.º 1
0
def encode_video_task(video_url, username='', profiles=video_encoder.VIDEO_ENCODING_PROFILES.keys(), queues={}, redo=False):
    default_queue = default_queues.copy()
    for profile, queue in queues.items():
        default_queue['item'] = queue

    file_path = None
    for profile_name in profiles:
        if redo or not video_db.video_already_encoded(video_url=video_url, video_quality=profile_name, recent_assigned=True):
            if not file_path:
                file_path = media_uploader.download_file(video_url)
            log_id = video_db.add_video_encode_log_start(video_url=video_url, video_quality=profile_name)
            if redo:
                _try_video_again(video_url, username, profiles)

            _encode_video_to_profile.apply_async(kwargs={'file_path': file_path,
                                                         'video_url': video_url,
                                                         'profile': profile_name,
                                                         'log_id': log_id,
                                                         'username': username
                                                         },
                                                 queue=default_queue[profile_name]
                                                 )
        else:
            print 'Already Done'
    db.engine.dispose()
Exemplo n.º 2
0
def encode_video_to_profile(file_path, video_url, profile_name, username=None):
    current_dir = os.getcwd()
    
    print_output('BEGINNING: '+file_path+' '+video_url )
    
    transpose_command = get_transpose_command(file_path)
    
    profile = VIDEO_ENCODING_PROFILES[profile_name]
    temp_path = os.path.join(TEMP_DIR, uuid.uuid1().hex)
    check_make_dir(temp_path)
    logfile_name = None


    result = {}
    try:
        if profile_name == 'thumbnail': 
            output_file_path = make_thumbnail(file_path)

        elif profile_name=='promo':
            video_data = video_db.get_video_data(video_url)
            
            answer_author_image_filepath = None if not video_data['answer_author_profile_picture'] else media_uploader.download_file(video_data['answer_author_profile_picture'])

            output_file_dir, output_file_name = make_promo_video(answer_author_username=video_data['answer_author_username'],
                                                            video_file_path=file_path,
                                                            transpose_command=transpose_command,
                                                            answer_author_name=video_data["answer_author_name"],
                                                            question=video_data['question_body'], 
                                                            question_author_username=video_data['question_author_name'],
                                                            answer_author_image_filepath=answer_author_image_filepath)
            output_file_path = os.path.join(output_file_dir, output_file_name)
            print 'PROMO VIDEO AT:', output_file_path
            make_psuedo_streamable(output_file_path)
        
        else:
            check_make_dir(temp_path)
            output_file_path = os.path.join(temp_path, uuid.uuid1().hex+'.'+profile['file_extension'])
            #os.chdir(temp_path)
            logfile_name = os.path.join(temp_path, uuid.uuid1().hex)
            command = profile['command'].format(input_file=file_path, output_file=output_file_path, transpose_command=transpose_command, logfile_name=logfile_name)
            print_output('COMMAND: '+command)
            process = subprocess.call(command, shell=True)
            print_output('MAKING STREAMABLE')
            #raw_input(output_file_path+'YOLO:')
            make_psuedo_streamable(output_file_path)
            #raw_input(output_file_path+'LOYO:')
  
        new_s3_key = get_key_name_for_profile(video_url, profile)
        print_output('NEW_KEY: '+new_s3_key)
            
        if os.path.exists(output_file_path):
            with open(output_file_path, 'rb') as f:
                result[profile_name] = media_uploader.upload_to_s3(f, new_s3_key)
            os.remove(output_file_path)

        if os.path.exists(temp_path):
            shutil.rmtree(temp_path)
        
        print_output('RESULT: '+ str(result))
        os.chdir(current_dir)
    
    except Exception as e:
        if os.path.exists(temp_path):
            shutil.rmtree(temp_path)
        os.chdir(current_dir)
        print traceback.format_exc(e)
    return result