fffiloni commited on
Commit
98bce3f
1 Parent(s): 01d5c02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -125,12 +125,33 @@ def run_xportrait(source_image, driving_video, seed, uc_scale, best_frame, out_f
125
  video_files = glob.glob(os.path.join(output_dir, "*.mp4"))
126
  print(video_files)
127
  if video_files:
128
- return f"Output video saved at: {video_files[0]}", video_files[0]
 
129
  else:
130
  return "No video file was found in the output directory.", None
131
  except subprocess.CalledProcessError as e:
132
  return f"An error occurred: {e}", None
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
  # Set up Gradio interface
136
  css="""
 
125
  video_files = glob.glob(os.path.join(output_dir, "*.mp4"))
126
  print(video_files)
127
  if video_files:
128
+ final_vid = convert_video_to_h264_aac(video_files[0])
129
+ return f"Output video saved at: {final_vid}", final_vid
130
  else:
131
  return "No video file was found in the output directory.", None
132
  except subprocess.CalledProcessError as e:
133
  return f"An error occurred: {e}", None
134
 
135
+ def convert_video_to_h264_aac(video_path):
136
+ # Get the directory and original filename
137
+ original_dir = os.path.dirname(video_path)
138
+ original_name, _ = os.path.splitext(os.path.basename(video_path))
139
+
140
+ # Define the output path in the same directory
141
+ output_path = os.path.join(original_dir, f"{original_name}_converted.mp4")
142
+
143
+ # Load the video
144
+ with VideoFileClip(video_path) as video:
145
+ # Write the video with H.264 and AAC codecs
146
+ video.write_videofile(
147
+ output_path,
148
+ codec="libx264", # H.264 video codec
149
+ audio_codec="aac", # AAC audio codec
150
+ temp_audiofile="temp-audio.m4a", # Temporary audio file (moviepy requirement)
151
+ remove_temp=True # Remove temporary files after writing
152
+ )
153
+
154
+ return output_path
155
 
156
  # Set up Gradio interface
157
  css="""