- If video length is shorter than audio length,
-shortest is what you want.
- If video length is longer than audio length, no flag at all will be what you want.
There is no flag to automate this decision.
Inspired by @deadcode's answer, I need to make clear, that "no flag to automate" is of course not true, if you are willing to reencode: In this case go with
apad as suggested by @deadcode.
If however you want to avoid reencoding (i.e.
-c:v copy) the answer stands.
There is a workaround using the
ffconcat demuxer, but it needs a bit of work:
- create a file containing silence in exactly the same format as your audiofile ("silence.wav")
- create a concat file "audio.ffconcat" (with as many silence lines as you need to make sure your audio is long enough):
ffmpeg -i videofile.mp4 -f concat -i audio.ffconcat -c:v copy output.mp4
This will synthesize the
apad filter without a filter graph, thus allowing a mux without reencoding.