Ejemplo n.º 1
0
def chunk_dash(*args, **kwargs):
    '''
    create dash chunks for every video in the transcoded folder
    '''
    logger.info("chunking dash")
    logger.info(args)
    logger.info(kwargs)
    context = args[0]
    segtime = kwargs['segtime']
    if not os.path.exists(get_dash_folder(context)):
        os.makedirs(get_dash_folder(context))

    args = "MP4Box -dash " + str(segtime) + "000 -profile onDemand "
    files_in = [
        os.path.join(get_transcoded_folder(context), f)
        for f in os.listdir(get_transcoded_folder(context))
    ]
    for i in range(0, len(files_in)):
        args += files_in[i] + "#video:id=v" + str(i) + " "

    args += files_in[0] + "#audio:id=a0 "
    args += " -out " + get_dash_mpd_file_path(context)
    print args
    subprocess.call(args, shell=True)
    return context
Ejemplo n.º 2
0
def edit_dash_playlist(*args, **kwards):
    '''
    create dash chunks for every video in the transcoded folder
    '''
    # print args, kwargs
    context = args[0]

    tree = LXML.parse(get_dash_mpd_file_path(context))
    root = tree.getroot()
    # Namespace map
    nsmap = root.nsmap.get(None)

    #Function to find all the BaseURL
    find_baseurl = LXML.ETXPath("//{%s}BaseURL" % nsmap)
    results = find_baseurl(root)
    audio_file = results[-1].text
    results[-1].text = "audio/" + results[
        -1].text  # Warning : This is quite dirty ! We suppose the last element is the only audio element
    tree.write(get_dash_mpd_file_path(context))

    #Move audio files into audio directory
    os.makedirs(os.path.join(get_dash_folder(context), "audio"))
    shutil.move(os.path.join(get_dash_folder(context), audio_file),
                os.path.join(get_dash_folder(context), "audio", audio_file))

    #Create .htaccess for apache
    f = open(os.path.join(get_dash_folder(context), "audio", ".htaccess"), "w")
    f.write("AddType audio/mp4 .mp4 \n")
    f.close()
    return context
Ejemplo n.º 3
0
def edit_dash_playlist(*args, **kwards):
    '''
    create dash chunks for every video in the transcoded folder
    '''
    # print args, kwargs
    context = args[0]

    tree = LXML.parse(get_dash_mpd_file_path(context))
    root = tree.getroot()
    # Namespace map
    nsmap = root.nsmap.get(None)

    # Function to find all the BaseURL
    find_baseurl = LXML.ETXPath("//{%s}BaseURL" % nsmap)
    results = find_baseurl(root)
    audio_file = results[-1].text
    results[-1].text = "audio/" + results[
        -1].text  # Warning : This is quite dirty ! We suppose the last element is the only audio element
    tree.write(get_dash_mpd_file_path(context))

    # Move audio files into audio directory
    os.makedirs(os.path.join(get_dash_folder(context), "audio"))
    shutil.move(os.path.join(get_dash_folder(context), audio_file),
                os.path.join(get_dash_folder(context), "audio", audio_file))

    # Create .htaccess for apache
    f = open(os.path.join(get_dash_folder(context), "audio", ".htaccess"), "w")
    f.write("AddType audio/mp4 .mp4 \n")
    f.close()
    return context
Ejemplo n.º 4
0
def create_description_zip(*args):
    context = args[0]
    i = 1
    while i <= int(context["desNum"]):
        zip_file = zipfile.ZipFile(get_description_zip_folder(context, i), 'w',
                                   zipfile.ZIP_DEFLATED)
        #zip_file_plus = zipfile.ZipFile(get_description_plus_zip_folder(context,i), 'w', zipfile.ZIP_DEFLATED)
        files_in = [
            os.path.join(get_dash_folder(context, i), f)
            for f in os.listdir(get_dash_folder(context, i))
        ]
        #files_in_plus = [os.path.join(get_plus_dash_folder(context,i),f) for f in os.listdir(get_plus_dash_folder(context,i))]
        for j in range(0, len(files_in)):
            zip_file.write(files_in[j], os.path.basename(files_in[j]))
            #zip_file_plus.write(files_in_plus[j],os.path.basename(files_in_plus[j]))
        i += 1
    return context
Ejemplo n.º 5
0
def chunk_dash(*args, **kwargs):
    '''
    create dash chunks for every video in the transcoded folder
    '''
    # print args, kwargs
    context = args[0]
    if not os.path.exists(get_dash_folder(context)):
        os.makedirs(get_dash_folder(context))

    args = "MP4Box -dash 4000 -profile onDemand "
    files_in = [os.path.join(get_transcoded_folder(context), f) for f in os.listdir(get_transcoded_folder(context))]
    for i in range(0, len(files_in)):
        args += files_in[i] + "#video:id=v" + str(i) + " "

    args += " -out " + get_dash_mpd_file_path(context)
    print args
    subprocess.call(args, shell=True)
    return context
Ejemplo n.º 6
0
def chunk_dash(*args, **kwargs):
    '''
	create dash chunks for every video in the transcoded folder
	'''
    # print args, kwargs
    context = args[0]
    segtime = kwargs['segtime']
    i = 1

    if not os.path.exists(get_dash_mpd_file_folder(context)):
        os.makedirs(get_dash_mpd_file_folder(context))

    while i <= int(context["desNum"]):
        if not os.path.exists(get_dash_folder(context, i)):
            os.makedirs(get_dash_folder(context, i))

        #if not os.path.exists(get_plus_dash_folder(context,i)):
        #	os.makedirs(get_plus_dash_folder(context,i))

        args = "MP4Box -dash " + str(segtime) + "000 -profile live "
        files_in = [
            os.path.join(get_mp4_description_folder(context, i), f)
            for f in os.listdir(get_mp4_description_folder(context, i))
        ]
        for j in range(0, len(files_in)):
            args += files_in[j] + "#video:id=v" + str(j)
        args += " -out " + get_dash_mpd_file_path(context, i)
        print args
        #plus_args = "MP4Box -dash " + str(segtime) + "000 -profile live "
        #files_in_plus = [os.path.join(get_plus_mp4_description_folder(context,i), f) for f in os.listdir(get_plus_mp4_description_folder(context,i))]
        #for j in range(0, len(files_in_plus)):
        #	plus_args += files_in_plus[j] + "#video:id=v" + str(j)
        #plus_args += " -out " + get_plus_dash_mpd_file_path(context,i)
        #print plus_args
        run_background(args)
        #run_background(plus_args)
        i += 1
    k = 1
    while k <= int(context["desNum"]):
        shutil.move(get_dash_mpd_file_path(context, k),
                    get_dash_mpd_file_folder(context))
        #shutil.move(get_plus_dash_mpd_file_path(context,k),get_dash_mpd_file_folder(context))
        k += 1
    return context
Ejemplo n.º 7
0
def chunk_dash(*args, **kwargs):
    '''
    create dash chunks for every video in the transcoded folder
    '''
    # print args, kwargs
    context = args[0]
    segtime = kwargs['segtime']
    if not os.path.exists(get_dash_folder(context)):
        os.makedirs(get_dash_folder(context))

    args = "MP4Box -dash " + str(segtime) + "000 -profile onDemand "
    files_in = [os.path.join(get_transcoded_folder(context), f) for f in os.listdir(get_transcoded_folder(context))]
    for i in range(0, len(files_in)):
        args += files_in[i] + "#video:id=v" + str(i) + " "

    args += files_in[0] + "#audio:id=a0 "
    args += " -out " + get_dash_mpd_file_path(context)
    print args
    run_background(args)
    return context
Ejemplo n.º 8
0
def clean_useless_folders(*args):
    '''
	delete encoding folder
	'''
    # print args, kwargs
    context = args[0]
    shutil.rmtree(get_transcoded_folder(context))
    shutil.rmtree(get_description_folder(context))
    shutil.rmtree(get_dash_mpd_file_folder(context))
    #shutil.rmtree(get_plus_description_folder(context))
    i = 1
    while i <= int(context["desNum"]):
        #shutil.rmtree(get_mp4_description_folder(context,i))
        shutil.rmtree(get_dash_folder(context, i))
        #shutil.rmtree(get_plus_mp4_description_folder(context,i))
        #shutil.rmtree(get_plus_dash_folder(context,i))
        i += 1