Esempio n. 1
0
def create_para_vid(speed, i, time_data, images, audio, output_name):
    end_times = []
    for time in time_data:
        end_times.append(time * (1 / speed))
    print(end_times)

    with open("ffmp.in", "w") as f:
        prev_time = 0.0
        for j in range(len(images) - 1):
            duration = float(end_times[j]) - prev_time
            f.write("file {0}' \n".format(images[j]))
            f.write("duration {} \n".format(duration))
            prev_time = float(end_times[j])

        f.write("file '{0}' \n".format(images[-1]))
        f.write("duration {} \n".format(prev_time + 0.5))
    os.system(
        "ffmpeg -y -i {0} -f concat -i ffmp.in -strict -2 -vsync vfr -pix_fmt yuv420p -vf fps=24 -video_track_timescale 90000 -max_muxing_queue_size 2048 -tune animation -crf 6 {1}nf.mp4"
        .format(audio, output_name))
    with open('blank.in', 'w') as f:
        f.write('\n'.join(
            ["file '{0}'".format(images[-1]), "duration {}".format("1.3")]))
    os.system(
        "ffmpeg -y -i {0} -f concat -i blank.in -strict -2 -vsync vfr -pix_fmt yuv420p -vf fps=24 -video_track_timescale 90000 -max_muxing_queue_size 2048 -tune animation -crf 6 fill{1}.mp4"
        .format("blank_long.mp3", str(i)))
    concatenate_videos(
        ['{0}nf.mp4'.format(output_name), 'fill{}.mp4'.format(i)],
        output_name + '.mp4', os.getcwd())
def create_vids(inpfile, sheet_name, tmpdir, story, first_slide, last_slide,
                audio_in, user):
    mdir = os.getcwd()
    files = ['pup.js', 'blank.mp3', 'blank_long.mp3', 'logo.png']
    for f in files:
        shutil.copy(f, "{0}/{1}".format(tmpdir, f))
    os.chdir(tmpdir)
    os.mkdir('images')
    audio_files = split_audio_on_silence(audio_in)
    print(audio_files)
    sheet = read_excel(inpfile, sheet_name)
    create_intro_video(sheet, audio_files[0])
    page_videos = []
    start = int(first_slide)
    end = int(last_slide) + 1
    for i in range(start, end):
        if not sheet.cell(row=i, column=1).value:
            continue

        page_no = i - start + 1

        para = sheet.cell(row=i, column=2).value.strip()
        image_text = ' '.join(para.strip().replace('*', '').replace(
            '\n', ' \n ').split(' '))
        image = create_image(image_text,
                             sheet.cell(row=i, column=3).value, page_no, story)

        audio_file = audio_files[page_no]
        create_page_vid(page_no, audio_file, image)

        page_videos.append("{}.mp4".format(page_no))

    os.chdir(os.path.join(mdir, 'static', 'videos', user))

    if story == '1':
        os.chdir("Stories")
    else:
        os.chdir("Other Videos")

    os.mkdir(output_name)

    os.chdir(os.path.join(os.getcwd(), output_name))

    concatenate_videos(["intro.mp4"] + page_videos,
                       "{}.mp4".format(output_name), tmpdir)
Esempio n. 3
0
def create_vids_from_excel(inpfile, sheet, tmpdir, story, first_slide, last_slide, voice, user):
	mdir = os.getcwd()
	files = ['pup.js', 'blank.mp3', 'blank_long.mp3', 'logo.png']
	for f in files:
		shutil.copy(f, "{0}/{1}".format(tmpdir, f))
	os.chdir(tmpdir)
	os.mkdir('images')
	sheet = read_excel(inpfile, sheet)
	create_intro_video(sheet, voice)
	normal_videos = []
	slow_videos = []
	split_videos = []
	start = int(first_slide)
	end = int(last_slide)+1
	for i in range(start, end):
		if not sheet.cell(row=i, column=1).value:
			continue
		para = sheet.cell(row=i, column=2).value.strip()
		(json_data, json_data_slow, json_data_split) = create_audio_data(para, voice)

		images_text = ' '.join(para.strip().replace('*', '').replace('\n', ' \n ').split(' '))
#		print("images text: " + images_text)
		images = create_images(images_text, sheet.cell(row=i, column=3).value, story)

		json_data = process_json_data(json_data, voice)
		json_data_slow = process_json_data(json_data_slow, voice)
		json_data_split = process_json_data(json_data_split, voice)

		create_para_vid(1, i-start-1, json_data, images, 'audio.mp3', "vid{}".format(str(i-start+1)))
		create_para_vid(0.75, i-start-1, json_data_slow, images, 'audio_slow.mp3', "vid{}-slow".format(str(i-start+1)))
		create_para_vid(1, i-start-1, json_data_split, images, 'audio_split.mp3', "vid{}-split".format(str(i-start+1)))

		normal_videos.append("vid{}.mp4".format(str(i-start+1)))
		slow_videos.append("vid{}-slow.mp4".format(str(i-start+1)))
		split_videos.append("vid{}-split.mp4".format(str(i-start+1)))

	os.chdir(os.path.join(mdir, 'static', 'videos', user))
	if story=='1':
		os.chdir("Stories")
	else:
		os.chdir("Other Videos")
	os.mkdir(output_name)
	print(output_name)
	os.chdir(os.path.join(os.getcwd(), output_name))
	print(os.getcwd())

	concatenate_videos(["intro.mp4"]+normal_videos, "{}-fast.mp4".format(output_name), tmpdir)
	concatenate_videos(["intro.mp4"]+slow_videos, "{}-medium.mp4".format(output_name), tmpdir)
	concatenate_videos(["intro.mp4"]+split_videos, "{}-slow.mp4".format(output_name), tmpdir)
Esempio n. 4
0
def create_intro_video(sheet, voice):
	image = sheet.cell(row=2, column=3).value
	text = (sheet.cell(row=2, column=2).value).split('\n')
	footer = sheet.cell(row=2, column=4).value
	if type(footer) == type('') and footer.strip() != '':
		footer_html = "<address style='text-align: center;'>"
		footer = footer.strip()
		for line in footer.split('\n'):
			footer_html += line + "<br>"
		footer_bool = True
		footer_html += "</address>"
	else:
		footer_bool = False

	if voice == "female":
		audio_data = polly_audio('. '.join(text).replace("._", "").replace("_.", "").replace('*', '.').replace('#', '').replace('__', ' - ').replace('_', '').replace("//", " "))
		with open('audio_uf.mp3', 'wb') as f:
			f.write(audio_data.read())
	elif voice == "male":
		text_n = '. '.join(text).replace("._", "").replace("_.", "").replace('*', '.').replace('#', '').replace('__', ' - ').replace('_', '').replace("//", " ")
		(audio_data, json) = google_tts("<speak>{}</speak>".format(text_n))
		with open('audio_uf.mp3', 'wb') as f:
                        f.write(audio_data)

	os.system("ffmpeg -y -i {} -ar 48000 {}".format("audio_uf.mp3", "intro_audio.mp3"))
	with open('intro.in', 'w') as f:
		f.write('\n'.join(["file \'images/{0}.jpg\'".format("intro"), "duration {}".format(5)]))
	headers = ''
	for i in range(len(text)):
		text[i] = ' '.join(text[i].strip().replace('*', '').split(' '))
	for line in text:
		headers += '<h1 style="font-size:{}rem">{}</h1>'.format(4-(0.5*len(text)), line)
	logo = '<img src="logo.png" style="position: absolute; top: 0px; left: 0px;"></img>'
	image_name = "intro.png"
	if type(image) == type('') and image.strip() != '':
		image_link = "https://drive.google.com/uc?export=download&id="+image.split('d/')[1].split('/view')[0]
		print("link: "+image_link)
		os.system("wget '{0}' -O '{1}'".format(image_link, image_name))
		print(headers)
		img = '<div style="height:350px"><img src="{}" style=""></img></div>'.format(image_name)
		if footer_bool:
			html = "<!DOCTYPE html><html><body style='margin:0px'><div id='vid_area' style='height: 720px; width: 1280px; padding:10px'>{0}<div style='height: 360px; display: flex; justify-content: center; align-items:flex-start; padding-top:{3}px'>{1}</div>{2}{4}</div></body></html>".format(img, headers, logo, 80-(20*len(text)), footer_html)
		else:
			html = '<!DOCTYPE html><html><body style="margin:0px"><div id="vid_area" style="height: 720px; width: 1280px; padding:10px">{0}<div style="height: 360px; display: flex; justify-content: center; align-items:flex-start; padding-top:{3}px">{1}</div>{2}</div></body></html>'.format(img, headers, logo, 80-(20*len(text)))
	else:
		if footer_bool:
			html = '<!DOCTYPE html><html><body><div id="vid_area" style="height: 720px; width:1280px; display: flex; flex-direction: column; justify-content: center; align-items: center;">{0}{1}{2}</div></body></html>'.format(logo, headers, footer_html)
		else:
			html = '<!DOCTYPE html><html><body><div id="vid_area" style="height: 720px; width:1280px; display: flex; flex-direction: column; justify-content: center; align-items: center;">{0}{1}</div></body></html>'.format(logo, headers)
	with open("intro.html", "w") as f:
			f.write(html)
	print(os.getcwd())
	cmd = "node pup.js file://{}/intro.html images/{}.jpg".format(os.getcwd(), "intro")
	print("PUP CMD INTRO:{}".format(cmd))
	os.system(cmd)
	os.system("ffmpeg -y -i {0} -f concat -i intro.in -strict -2 -vsync vfr -pix_fmt yuv420p -vf fps=24 -video_track_timescale 90000 -max_muxing_queue_size 2048 -tune animation -crf 6 {1}.mp4".format("intro_audio.mp3", "intronf"))
	with open('blank.in', 'w') as f:
		f.write('\n'.join(["file \'images/{0}.jpg\'".format("intro"), "duration {}".format("2.5")]))
	os.system("ffmpeg -y -i {0} -f concat -i blank.in -strict -2 -vsync vfr -pix_fmt yuv420p -vf fps=24 -video_track_timescale 90000 -max_muxing_queue_size 2048 -tune animation -crf 6 fill{1}.mp4".format("blank.mp3", "intro"))
	concatenate_videos(["intronf.mp4", "fillintro.mp4"], "intro.mp4", os.getcwd())
	return("intro.mp4")