Log in

View Full Version : Optional source for muxing in ffmpeg


mbcd
9th January 2020, 19:39
Want to merge 1 video and 2 audiostreams with ffmpeg.
But it can happen, that only one of both audiostreams are awailable.

So I googled and found the "?" for mapping.

ffmpeg.exe" -i "video.mkv" -i "audio1.wav" -i "audio2optional.wav" -map 0:0 -map 1:0 -map 2:0 -f mp4 "output.mp4"

But I can do what I want (-map 2:0?) (-map 2?:0), ...

ffmpeg doesnt mux because "audio2optional.wav" is missing.

I dont get the "stream/input is optional parameter" to run, using windows cli, actual build.

microchip8
9th January 2020, 20:18
just use -map 0

poisondeathray
9th January 2020, 20:40
If you're actually muxing (-c:a copy), not re-encoding, it won't work because WAV is not supported in MP4 container for open source muxers . MOV or MKV container should work

mbcd
10th January 2020, 03:07
Sorry, this was an edited sample line for a better description, it still dont work with mkv (I used). I took out all other processing to make it as simple as possivble.

Its always a:\audio2optional.wav : No such file or directory" which of course does not exists, because it should be optional.

just use -map 0

Yeah, funny, found this in some of my old files:
"%cd%\ffmpeg.exe" -i "%cd%\video\%%~nI.mkv" -i "%cd%\audio\%%~nI.mkv" -i "%cd%\subtitle\%%~nI.mkv" -c copy -map 0 -map 1 -map 2? "%pathOut%\%%~nI.mkv"

It worked just fine that days.

Today (actual command):

--> ffmpeg.exe -i "a:\video.mkv" -i "a:\audio1.wav" -i "a:\audio2.wav" -map 0 -map 1 -map 2? "a:\testmux.mkv"
--> a:\audio2.wav: No such file or directory

I cant see any difference
Using ffmpeg version git-2020-01-01-7b58702

poisondeathray
10th January 2020, 04:30
Today (actual command):

--> ffmpeg.exe -i "a:\video.mkv" -i "a:\audio1.wav" -i "a:\audio2.wav" -map 0 -map 1 -map 2? "a:\testmux.mkv"
--> a:\audio2.wav: No such file or directory



You can't use a question mark "?" for "-map2?"

Must be a typo

you had it right the first time for map
-map 0:0 -map 1:0 -map 2:0

mbcd
10th January 2020, 07:37
There is not much info about this feature around.
But for a fixed mapping I need to know if the file exists, it doesnt work with -map 2:0 if file is not existing.

I found the problem around this. It works only for streams, but not if input itself is missing. I thought this was a working script I used long times ago, was a testing one I suggest now.

So only for streams, not for input. Does not make that much sense, but ok ... it works as it works ... it should ignore this mapping (and missing input) if specified input is not existing. Different behavour, a little bit confusing, so my fault, sorry!

https://gitlab.com/J_Darnley/ffmpeg/commit/1c049d5ffe08b3af36844cdbe7a5950879122b8b