adefossez / seewav

Audio waveform visualisation, converts any audio to a nice video
The Unlicense
220 stars 29 forks source link

Generating static Image #6

Open PeterPan123456 opened 1 year ago

PeterPan123456 commented 1 year ago

Hey I was wondering if there is a way to generate one image that shows the full length of the audio file. My goal ist to get a visual presentation of an audio file similar to soundcloud.

PeterPan123456 commented 1 year ago

my first approach looked liek this, but didn't work.

import os
import subprocess
from pydub.utils import mediainfo

# File paths
input_audio_file = 'input.wav'
output_video_file = 'output.mp4'
output_image_file = 'output.png'

# Get duration of audio file
audio_info = mediainfo(input_audio_file)
audio_duration = float(audio_info['duration'])

# Command to generate mp4 using seewav
seewav_command = f'seewav -r 1 -c 0.8,0.1,0.2 --white -B 350 -T {audio_duration} -S 1 -W 1920 -H 400 -d 1 {input_audio_file} {output_video_file}'

# Run the command
subprocess.run(seewav_command, shell=True)

# Command to extract first frame as png using ffmpeg
ffmpeg_command = f'ffmpeg -i {output_video_file} -vframes 1 {output_image_file}'

# Run the command
subprocess.run(ffmpeg_command, shell=True)