FFmpeg map optional (audio) stream

6,425

Recent versions of ffmpeg support a conditional mapping option:

ffmpeg -i input.mp4 -map "0:a?" output.mp4

This will ignore non-existing audio streams in the input file.

Share:
6,425

Related videos on Youtube

tomsv
Author by

tomsv

Updated on September 18, 2022

Comments

  • tomsv
    tomsv 3 months

    I use this command to produce a file scaled and with an overlay image:

    ffmpeg 
    -i input.* -i overlay.png 
    -filter_complex "[0:v]...; ...[1:v]overlay=... ... [resultingvideo]" 
    -map "[resultingvideo]" -vcodec libx264 -f mp4 
    -acodec libmp3lame -q:a 50 
    outputfilename.mov
    

    where "..." represents some left out filtering.

    The problem is, there is no audio.

    If I add -map 0:a, there is audio if the input has audio, and an error and no output file if the input has no audio.

    How can I get ffmpeg to optionally use the audio from the input if it exists, and otherwise ignore audio or produce silence or something?

    Or, do I have to analyze the file first using ffprobe before I can generate my script command?

  • rupinderjeet
    rupinderjeet almost 3 years
    [0:a?] how can I do something like this in filter_complex

Related