How to use an audio stream that can be null in ffmpeg?

I want to take the audio from a video, set it’s volume, and join them back (with some more filters, but I don’t think they are relevant to the question.)

I can do it with:

ffmpeg -i vid.mp4 -filter_complex "[0:a]volume=0.5[a0]" -map v:0 -map "[a0]" -shortest out.mp4

But, the video not have an audio stream and then I get Error: Stream specifier ':a' in filtergraph description [0:a]volume=0.5[a0] matches no streams.

How can use the stream conditinally if not null? (In case it’s null, I want to have empty audio).

Read more here: Source link