ffmpeg-go icon indicating copy to clipboard operation
ffmpeg-go copied to clipboard

Audio Visualization filter problem

Open beatscode opened this issue 2 years ago • 0 comments

I’m trying to translate the following command line which works. Merging mp4 and mp3 and adding audio visualization.

ffmpeg -stream_loop -1 -i cassette-edit.mp4 -i test-audio.mp3 -filter_complex "[1:a]showwaves=s=720x700:mode=line:colors=black[vwave];[0:v][vwave]overlay=format=auto[out]" -shortest -map "[out]" -pix_fmt yuv420p -map 1:a 'Cassette Dreams - w visualizer.mp4' -y

When trying to convert using ffmpeg-go, I'm losing hair

func MergeAudioWithVideoAndVisualizer(renderedVideo string, track_path string, videoOutput string,
	filter_complex string) error {
  in1 := ffmpeg.Input(renderedVideo, ffmpeg.KwArgs{"stream_loop": -1}).Video()
  in2 := ffmpeg.Input(track_path, ffmpeg.KwArgs{}).Audio().Filter("showwaves", ffmpeg.Args{
		"s=720x700",
		"mode=line",
		"colors=black",
	}).Overlay(in1, "", ffmpeg.KwArgs{"format": "auto"})
  
  err := ffmpeg.Output(
     []*ffmpeg.Stream{in1, in2},
     videoOutput,
     ffmpeg.KwArgs{
        "shortest": "",
        "map":      "1:a",
        "pix_fmt":  "yuv420p",
     }).OverWriteOutput().ErrorToStdOut().Run()
  return err
}

Here is the compiled command ffmpeg -stream_loop -1 -i cassette-edit.mp4 -i test-audio.mp3 -filter_complex [1:a]showwaves=s=720x700:mode=line:colors=black[s0];[s0][0:v]overlay=eof_action=repeat:format=auto[s1] -map 0:v -map [s1] -map 1:a -pix_fmt yuv420p -shortest Cassette_Dreams_w_visualizer.mp4 -y

This results in a video with audio but no visualization

I've tracked it down to 2 things

  • the reorder of [vwave];[0:v][vwave]overlay to [s0];[s0][0:v]overlay
    • If i attempt to make the compiled command work, I end up switching to [s0];[0:v][s0]overlay
  • the adding of -map [0:v]
    • How do I omit this

I'm not very knowledgable in ffmpeg so I'm not sure how to re-use the library functions to get what I want.

beatscode avatar Nov 03 '22 09:11 beatscode