Skip to content

Instantly share code, notes, and snippets.

@robxx
Created August 5, 2025 16:34
Show Gist options
  • Select an option

  • Save robxx/58a4fc1bbb1ef1347b5793b63953ccf9 to your computer and use it in GitHub Desktop.

Select an option

Save robxx/58a4fc1bbb1ef1347b5793b63953ccf9 to your computer and use it in GitHub Desktop.
import subprocess
import os
import sys
def generate_waveform_video(input_audio, output_video, resolution="1280x720", waveform_color="white"):
if not os.path.isfile(input_audio):
print(f"Error: File '{input_audio}' not found.")
return
filter_complex = (
f"[0:a]aformat=channel_layouts=mono,showwaves=s={resolution}:mode=cline:colors={waveform_color}[v]"
)
ffmpeg_command = [
"ffmpeg",
"-y",
"-i", input_audio,
"-filter_complex", filter_complex,
"-map", "[v]",
"-map", "0:a",
"-c:v", "libx264",
"-c:a", "aac",
"-shortest",
"-pix_fmt", "yuv420p",
output_video
]
try:
subprocess.run(ffmpeg_command, check=True)
print(f"✅ Video with animated waveform generated: {output_video}")
except subprocess.CalledProcessError as e:
print("❌ FFmpeg failed:", e)
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: python audio_to_waveform_video.py <input_audio_file> <output_video_file>")
sys.exit(1)
input_audio = sys.argv[1]
output_video = sys.argv[2]
generate_waveform_video(input_audio, output_video)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment