The code below runs a perfect red audiovisualizer when run on a “black” colored background. But when used with any other colored jpg image the visualizer just doesn't show up. What's missing?

ffmpeg -y -i music.mp3 -loop 1 -i black.jpg -filter_complex \
   "[0:a]showwaves=s=1280x175:colors=Red:mode=p2p,format=yuv420p[v];[1:v][v]overlay=0:200[outv]" \
   -map "[outv]" -pix_fmt yuv420p -map 0:a -c:v libx264 -c:a copy -shortest output_bg.mp4

enter image description here enter image description here

ffmpeg -i music.mp3 -loop 1 -i image.jpg -filter_complex "[0:a]showwaves=s=1280x175:colors=Red:mode=p2p[v];[1:v][v]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p[outv]" -map "[outv]" -map 0:a -c:v libx264 -c:a copy -shortest -movflags +faststart output.mp4
  • Remove the format filter after showwaves.

  • Use format=auto in the overlay filter.

  • Do all of the filtering within the filtergraph, so remove -pix_fmt and replace it with the format filter.

If you want image.jpg to fit within a specific size such as 1280x720:

ffmpeg -i music.mp3 -loop 1 -i image.jpg -filter_complex "[0:a]showwaves=s=1280x175:colors=Red:mode=p2p[fg];[1:v]scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720,setsar=1[bg];[bg][fg]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p[outv]" -map "[outv]" -map 0:a -c:v libx264 -c:a copy -shortest -movflags +faststart output.mp4
  • tested your script but the issue still persists.On closer inspection ,the visualizer is there ,it is just getting pushed to the bottom of the page(Some spikes in the frequency could be seen at the page bottom ).How could the visualizer be bought to the center?. – starzar Feb 5 '19 at 7:03
  • @starzar Updated answer. It will now center the overlay. The second example will resize images to fit within 1280x720 without needing to pre-process with ImageMagick. – llogan Feb 5 '19 at 17:52
  • thanks for script .There is a padding (default black) under the visualiser (in the original script ),how could one change the color of this padding ?I tried adding option "overlay :colors= Blue" but received an error= "Option 'colors' not found" – starzar Feb 12 '19 at 16:31
  • @starzar Show a screenshot so I can see what you are describing. – llogan Feb 12 '19 at 18:44

Scale does matter while creating ffmpeg videos with images.

In the above case, some background images were really small (eg 512 x 210 etc). On doing a batch size conversion of all the background images (using Imagemagick)to 1280x720 (same as render size) the above code works fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.