Advertisement
Guest User

Untitled

a guest
Jun 24th, 2023
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. import gradio as gr
  2. import io
  3. import os
  4. import subprocess
  5. import time
  6. from datetime import datetime
  7.  
  8. def video_to_audio_tab():
  9.     def video_to_audio(video):
  10.         base_output_path = os.path.join(os.getcwd(), 'output', 'video2audio')
  11.         output_file_name = "{datetime}.wav".format(datetime=datetime.now().isoformat().replace(':', '-'))
  12.         output = os.path.join(base_output_path, output_file_name)
  13.         command = "ffmpeg -i {video} -map a {output}".format(video=video, output=output)
  14.         subprocess.call(command,shell=True)
  15.         return output
  16.    
  17.     with gr.Tab("video2audio"):
  18.         with gr.Row():
  19.             video_input = gr.Video()
  20.             with gr.Column():
  21.                 audio_output = gr.Audio()
  22.                 video_to_audio_button = gr.Button(value="Extract", variant="primary")
  23.                 video_to_audio_button.click(video_to_audio, inputs=video_input, outputs=audio_output)
  24.                 with gr.Row():
  25.                     text_button = gr.Button("Send to Extract voice")
  26.                     text_button = gr.Button("Send to Extract instrumental")
  27.  
  28. def audio_to_video_tab():
  29.     def audio_to_video(audio, image):
  30.         base_output_path = os.path.join(os.getcwd(), 'output', 'audio2video')
  31.         output_file_name = "{datetime}.mp4".format(datetime=datetime.now().isoformat().replace(':', '-'))
  32.         output = os.path.join(base_output_path, output_file_name)
  33.  
  34.         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)
  35.         subprocess.call(command,shell=True)
  36.         return output
  37.  
  38.     with gr.Tab("audio2video"):
  39.         with gr.Row():
  40.             with gr.Column():
  41.                 audio_input = gr.Audio(label="Input audio", type="filepath")
  42.    
  43.                 with gr.Blocks():
  44.                     with gr.Tab("Image"):
  45.                         image_input = gr.Image(label="Input image", type="filepath")
  46.                     # gr.Tab("Video")
  47.                
  48.             with gr.Column():
  49.                 video_output = gr.Video(label="Output video")
  50.                 create_video_button = gr.Button(value="Merge audio with provided media", variant="primary")
  51.                 create_video_button.click(audio_to_video, inputs=[audio_input,image_input], outputs=video_output)
  52.  
  53. with gr.Blocks() as demo:
  54.     video_to_audio_tab()
  55.     audio_to_video_tab()
  56.     # gr.Tab("Extract voice")
  57.     # gr.Tab("Extract instrumental")
  58.     # gr.Tab("Change voice")
  59.     # gr.Tab("Merge audio")
  60.  
  61. demo.launch()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement