0

The following code:

ffmpeg -i test.png            
       -t 2 -i a.mp3          
       -t 4 -i video.mp4      
       -t 1 -i b.mp3          
       -filter_complex [1]adelay=2000|2000[s1];[3]adelay=5000|5000[s3];[s1][2][s3]amix=inputs=3[outa];[0][2]overlay[outv]^
       -map [outa] -map [outv]^
       out.mp4 -y

works, and mixes the audio from the MP3s (time-shifted, as desired) and from the MP4 video.

But it fails if the MP4 has no audio channel (= a no-sound video):

Stream specifier '' in filtergraph description ... matches no stream

I'd like my script to work in both cases, if the video has audio or not.

How to include [2] in the amix if and only if this video has sound?


Note: A good way would be to be able to load a MP4 with always a sound stream: the original sound stream if the video has sound, and a silence audio track if the MP4 has no sound in it. Is this possible with a single command in ffmpeg?

Basj
  • 41,386
  • 99
  • 383
  • 673

1 Answers1

1

There is not such built-in feature. You have to check the file with ffprobe to see if it has audio, and then run the appropriate command. If you have a favorite scripting language you can automate this with an if statement.

See Using ffprobe to check audio-only files.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Thank you very much. Is there really no way to load a default null audio for image-only (without sound) videos? It would be super handy, and would allow to treat them like normal videos, without `ffprobe`, without `if`, without scripts, etc. – Basj Feb 18 '21 at 07:55
  • @Basj No, I do not believe so. Maybe you should look into [MLT](https://www.mltframework.org/) if you're looking for a command line editor. ffmpeg isn't really designed to do this type of work, although it is certainly possible. – llogan Feb 18 '21 at 19:34