Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gradio as gr
- import io
- import os
- import subprocess
- import time
- from datetime import datetime
- def video_to_audio_tab():
- def video_to_audio(video):
- base_output_path = os.path.join(os.getcwd(), 'output', 'video2audio')
- output_file_name = "{datetime}.wav".format(datetime=datetime.now().isoformat().replace(':', '-'))
- output = os.path.join(base_output_path, output_file_name)
- command = "ffmpeg -i {video} -map a {output}".format(video=video, output=output)
- subprocess.call(command,shell=True)
- return output
- with gr.Tab("video2audio"):
- with gr.Row():
- video_input = gr.Video()
- with gr.Column():
- audio_output = gr.Audio()
- video_to_audio_button = gr.Button(value="Extract", variant="primary")
- video_to_audio_button.click(video_to_audio, inputs=video_input, outputs=audio_output)
- with gr.Row():
- text_button = gr.Button("Send to Extract voice")
- text_button = gr.Button("Send to Extract instrumental")
- def audio_to_video_tab():
- def audio_to_video(audio, image):
- base_output_path = os.path.join(os.getcwd(), 'output', 'audio2video')
- output_file_name = "{datetime}.mp4".format(datetime=datetime.now().isoformat().replace(':', '-'))
- output = os.path.join(base_output_path, output_file_name)
- command = "ffmpeg -loop 1 -i {image} -i {audio} -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest {output}".format(image=image, audio=audio, output=output)
- subprocess.call(command,shell=True)
- return output
- with gr.Tab("audio2video"):
- with gr.Row():
- with gr.Column():
- audio_input = gr.Audio(label="Input audio", type="filepath")
- with gr.Blocks():
- with gr.Tab("Image"):
- image_input = gr.Image(label="Input image", type="filepath")
- # gr.Tab("Video")
- with gr.Column():
- video_output = gr.Video(label="Output video")
- create_video_button = gr.Button(value="Merge audio with provided media", variant="primary")
- create_video_button.click(audio_to_video, inputs=[audio_input,image_input], outputs=video_output)
- with gr.Blocks() as demo:
- video_to_audio_tab()
- audio_to_video_tab()
- # gr.Tab("Extract voice")
- # gr.Tab("Extract instrumental")
- # gr.Tab("Change voice")
- # gr.Tab("Merge audio")
- demo.launch()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement