Esempio n. 1
0
def get_thumb(filepath = None, output_file = ""):
    if not output_file:
        output_file = "{0}/Desktop/output_file.jpg".format(expanduser("~"))
   
    # should make this global
    ffmpeg_path = path.get_ffmpeg_bin() + '\\'

    if sys.platform == 'win32':
        ffmpeg_path = path.make_windows_style(ffmpeg_path)
        filepath = path.make_windows_style(filepath)
        ffmpeg_executable = 'ffmpeg.exe'
    else:
        ffmpeg_path = path.sanitize(ffmpeg_path)
        filepath = path.sanitize(filepath)
        ffmpeg_executable = 'ffmpeg'

    ffmpeg_command = '"{}{}" '.format(ffmpeg_path, ffmpeg_executable)
    ffmpeg_command += '-i "{}" '.format(filepath)
    # ffmpeg_command += '-filter:v select="eq(n\,0)" -vframes 1'
    ffmpeg_command += '-y '
    ffmpeg_command += '"{}"'.format(output_file)
    subprocess.call(ffmpeg_command, shell = True)
    output_file = path.sanitize(output_file)

    # print "Creating Thumb for %s >> %s"%(filepath,output_file)
    if not os.path.isfile(output_file):
        return
    else:
        return output_file
    '''
Esempio n. 2
0
def get_thumb(filepath=None,
              output_file="/users/bern/Desktop/output_file.jpg"):
    duration = probe(filepath)["streams"][0]["duration"]
    time = (float(duration) / 2)
    # should make this global
    ffmpeg_path = path.get_ffmpeg_bin() + '\\'

    if sys.platform == 'win32':
        ffmpeg_path = path.make_windows_style(ffmpeg_path)
        filepath = path.make_windows_style(filepath)
        ffmpeg_executable = 'ffmpeg.exe'
    else:
        ffmpeg_path = path.sanitize(ffmpeg_path)
        filepath = path.sanitize(filepath)
        ffmpeg_executable = 'ffmpeg'

    ffmpeg_command = '"{}{}" '.format(ffmpeg_path, ffmpeg_executable)
    ffmpeg_command += '-i "{}" '.format(filepath)
    # ffmpeg_command += '-filter:v select="eq(n\,0)" -vframes 1'
    ffmpeg_command += '-y '
    ffmpeg_command += '"{}"'.format(output_file)
    subprocess.call(ffmpeg_command, shell=True)
    output_file = path.sanitize(output_file)

    # print "Creating Thumb for %s >> %s"%(filepath,output_file)
    if not os.path.isfile(output_file):
        return
    else:
        return output_file
    '''
Esempio n. 3
0
def encodeToH264Mov(filepath=None, output_file=""):
    print("ahey")
    ffmpeg_path = path.get_ffmpeg_bin() + '\\'

    if sys.platform == 'win32':
        ffmpeg_path = path.make_windows_style(ffmpeg_path)
        filepath = path.make_windows_style(filepath)
        ffmpeg_executable = 'ffmpeg.exe'
    else:
        ffmpeg_path = path.sanitize(ffmpeg_path)
        filepath = path.sanitize(filepath)
        ffmpeg_executable = 'ffmpeg'

    ffmpeg_command = '"{}{}" '.format(ffmpeg_path, ffmpeg_executable)
    ffmpeg_command += '-i "{}" '.format(filepath)
    # ffmpeg_command += '-filter:v select="eq(n\,0)" -vframes 1'
    ffmpeg_command += '-c:v libx264 -preset fast -tune animation '
    ffmpeg_command += '-y '
    ffmpeg_command += '"{}"'.format(output_file)
    subprocess.call(ffmpeg_command, shell=True)
    output_file = path.sanitize(output_file)
    logger.info('ffmpeg command: {}'.format(ffmpeg_command))

    # print "Creating Thumb for %s >> %s"%(filepath,output_file)
    if not os.path.isfile(output_file):
        return
    else:
        return output_file
Esempio n. 4
0
def encodeToH264Mov(filepath = None, output_file = ""):
    ffmpeg_path = path.get_ffmpeg_bin() + '\\'

    if sys.platform == 'win32':
        filepath = path.make_windows_style(filepath)
        ffmpeg_executable = 'ffmpeg.exe'
        ffmpeg_path = os.path.join(ffmpeg_path, ffmpeg_executable)
        ffmpeg_path = path.make_windows_style(ffmpeg_path)
        output_file = path.make_windows_style(output_file)
    else:
        filepath = path.sanitize(filepath)
        ffmpeg_executable = 'ffmpeg'
        ffmpeg_path = os.path.join(ffmpeg_path, ffmpeg_executable)
        ffmpeg_path = path.sanitize(ffmpeg_path)
        output_file = path.sanitize(output_file)
    
    if not os.path.isfile(ffmpeg_path):
        logger.error("FFMPEG executable missing. No File at: {}".format(ffmpeg_path))
        raise RuntimeError("FFMPEG executable missing")

    filepath = filepath.replace("####", r"%04d")

    ffmpeg_command = [ffmpeg_path]
    ffmpeg_command.extend(['-i', filepath])
    # ffmpeg_command += '-filter:v select="eq(n\,0)" -vframes 1'
    ffmpeg_command.extend(['-c:v', 'libx264', '-preset', 'fast', '-tune', 'animation'])
    ffmpeg_command.extend(['-y'])
    ffmpeg_command.extend([output_file])
    logger.info('ffmpeg command: {}'.format(' '.join(ffmpeg_command)))
    try:
        subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as err:
        logger.error("FFMPEG conversion non zero exit: {}".format(err.output))
        raise err    


    # print "Creating Thumb for %s >> %s"%(filepath,output_file)
    if not os.path.isfile(output_file):
        logger.error("FFMPEG conversion from {} to {} not successful. Converted File missing. \n Command used: {}".format(filepath, output_file, ffmpeg_command))
        return
    else:
        return path.sanitize(output_file)