Including sound wave overlays to movies and images the usage of FFMPEG


With a view to repair a damaged video the place the digital camera stopped recording, I sought after to exchange the phase with a video with a legitimate wave overlay. There are lots of products and services for that, and additionally it is a function of video modifying tool. However I’m stingy and a geek, so I sought after to make use of FFMPEG at the command line as a substitute. This additionally permits for batch processing.

Notice: I didn’t embed the movies on this put up however GIFs as a substitute. The actual movies play the video and audio and the sound wave strikes accordingly.

Let’s say that is our unique video:

Video of me talking about public speaking

That is what it appeared like in spite of everything:

The same video with a sound wave on top of it

Right here’s the command I used to create the above model:

ffmpeg -i Comprehensible.mp4 
 -filter_complex "[0:a]showwaves=colours=0xff1646@0.3
 :scale=sqrt:mode=cline,layout=yuva420p[v];
 [v]scale=1280:400[bg];
 [v][bg]overlay=(W-w)/2:H-h[outv]"
  -map "[outv]" -map 0:a -c:v libx264 -c:a duplicate 
  waveform-sqrt-cline.mp4

OK, let’s unwrap this:

  • `Comprehensible.mp4` is the enter report
  • `0xff1646@0.3` is the hexadecimal color of the waves I wish to create. The `@0.3` is the opacity, 30%.
  • The primary `scale` is how the bars must be resized to stick in a definite vary. I discovered squareroot to appear the most efficient. Different choices are to be had within the documentation
  • `mode` is what soundwave you need. This model, `cline` is a targeted, crammed line. Different choices are `level`, `line` and `p2p`.
  • `scale` is the dimensions of the generated video of the wave, on this case 1280×400 pixels (because the video is 1280×1080)
  • The `overlay` defines the place at the background video the wave must seem. On this case centred within the horizontal route and at the backside of the video.
  • `waveform-sqrt-cline.mp4` is the identify of the overall video.

Trade location of the sound wave

You’ll be able to additionally middle the sound wave in each instructions the usage of `overlay=(W-w)/2:(H-h)/2`:

ffmpeg -i Comprehensible.mp4 
 -filter_complex "[0:a]showwaves=colours=0xff1646@0.3
 :scale=sqrt:mode=cline,layout=yuva420p[v];
 [v]scale=1280:400[bg];
 [v][bg]overlay=(W-w)/2:(H-h)/2[outv]"
  -map "[outv]" -map 0:a -c:v libx264 -c:a duplicate 
  waveform-sqrt-cline-centered.mp4

And the end result seems like this:

Video showing the sound wave in the vertical center

Different sound wave kinds

And you’ll exchange the output sort to line and alter the color:

ffmpeg -i Comprehensible.mp4 
 -filter_complex "[0:a]showwaves=colours=0xffffff@0.5
 :scale=sqrt:mode=line,layout=yuva420p[v];
 [v]scale=1280:400[bg];
 [v][bg]overlay=(W-w)/2:H-h[outv]"
  -map "[outv]" -map 0:a -c:v libx264 -c:a duplicate 
  waveform-sqrt-line.mp4

Video showing the sound wave as lines

That is what the purpose to indicate mode seems like:

ffmpeg -i Comprehensible.mp4 
 -filter_complex "[0:a]showwaves=colours=0xffffff    
 :scale=sqrt:mode=p2p,layout=yuva420p[v]; 
 [v]scale=1280:400[bg];
 [v][bg]overlay=(W-w)/2:H-h[outv]"
  -map "[outv]" -map 0:a -c:v libx264 -c:a duplicate 
 waveform-sqrt-p2p.mp4

Video with point to point line

Including a legitimate wave to a static picture

In the event you handiest need the audio from a video and use a background picture as a substitute, that is what to make use of. This creates a 400×400 pixel video with the picture because the background and the sound wave on best:

ffmpeg -i Comprehensible.mp4  -i chris.jpg
 -filter_complex "[0:a]showwaves=colours=0xff1646@0.3
 :scale=sqrt:mode=cline,layout=yuva420p[v];
 [1:v]scale=400:400[bg];
 [bg][v]overlay=(W-w)/2:(H-h)/2[outv]"
  -map "[outv]" -map 0:a -c:v libx264 -c:a duplicate 
  static-image.mp4

Soundwave on top of a static image

FFMPEG is astounding

Granted, the syntax of FFMPEG is lovely nuts, however additionally it is tremendous tough. Wish to know as an example how I created the GIFs of this put up?

First, I resized all of the MP4s within the folder to at least one/3 in their measurement and stored them as small*:

for f in *.mp4 ; 
do ffmpeg -i "$f" -vf scale=w=iw/3:h=ih/3 "small-$f" ;
achieved

Then I took the ones and created gifs

for f in small-*.mp4 ; 
do ffmpeg -i "$f" -sws_dither ed -ss 5 -t 1 "e-$f.gif" ; 
achieved

In English: Get all small-*.mp4s within the present folder, and create a GIF from 2d 5 of the video, one 2d lengthy, the usage of error diffusion.

Automate all of the issues!

Soundwave from transformers pressing a button

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Back To Top
0
Would love your thoughts, please comment.x
()
x