Hi.
I'm using something like this in a .bat to demux every audio stream in a file with ffmpeg:
It works fine for 2 audio streams but the problem is that it produces 2 m4as for the inputs that only have one audio stream. Shouldn't the "?" ignore the mappings that don't exist ?Code:ffmpeg -i %1 -map 0:a:0? -vn -sn -dn -acodec copy "%~n1_Track1.m4a" -map 0:a:1? -vn -sn -dn -acodec copy "%~n1_Track2.m4a" pause
Any help is appreciated.
+ Reply to Thread
Results 1 to 9 of 9
-
-
I know this may not be what you want but, did you try:
Code:ffmpeg -i %1 -map 0:a:0 -vn -sn -dn -acodec copy "%~n1_Track1.mp3" timeout 5 ffmpeg -i %1 -map 0:a:1 -vn -sn -dn -acodec copy "%~n1_Track2.mp3" pause
You may not need it anyway. The above method finishes the first audio and errors on the second one without writing it. -
@Budman1
Thank you for this method, it works but my main curiosity is about the "?". The docs say that it'll ignore the stream that doesn't exit without throwing an error. In my case it maps the audio stream 2 times. Did I misunderstand the docs ?
I'd like to know whether my .bat had the same behaviour on your PC and what's your version of windows ? -
@sneaker
Thanks for your reply.
If I've understood you correctly ffmpeg assumes that "-map 0:a:1?" is "-map 0:a:0" (The first audio) and because it doesn't exist it outputs the "-map 0:a:0" 2 times ? (The first time being the "-map 0:a:0?")
But your first statement is in contradiction to what is actually happening because if it were ignored as if it were not set at all then why is it producing 2 files ? -
No.
Let's assume you have a simple command:
ffmpeg -i "input.mkv" -c copy "output.mkv"
Note that there is no -map specified. In this case ffmpeg will work as if -map 0:v:0? -map 0:a:0? -map 0:s:0? were set. It's the default stream mapping.
Now you have e.g.:
ffmpeg -i "input.mkv" -map 0:a:1? -c copy "output.mkv"
Now we have 2 possible cases:
A.) There is a second audio. In that case the output will have exactly one audio stream. No video, no subtitles.
B.) There is no second audio. In that case ffmpeg will fall back to the default mapping (because that was the only -map option we used) which tries to select the first video, first audio and first subtitle.
Either way there will be an output file.
If you had
ffmpeg -i "input.mkv" -map 0:v:0 -map 0:a:1? -c copy "output.mkv"
and no second audio it could fall back on "-map 0:v:0", i.e. the output would only have the first video stream. No audio, no subtitles. -
So this :
Code:ffmpeg -i "INPUT" -map 0:a:0? -c copy -map 0:a:1? -c copy "OUTPUT"
Code:ffmpeg -i "INPUT" -map 0:a:0? -c copy -map 0:v:0 -map 0:a:0 -map 0:s:0 "OUTPUT"
btw, do you know how to get rid of the chapters when demuxing ? -
You mean one audio, no video, no subtitles? Basically, every -map with "?" which doesn't match will be deleted from the command-line and only the matching -maps will be considered. If there are no remaining/matching -maps then the default will be used (first video, first audio, first subtitle).
-map_chapters -1 -
You mean one audio, no video, no subtitles?
Anyway, I got it so thanks for all the help. I also tried to do it with the line delimiter "\" but I get the error "Unable to find a suitable output for '\' invalid argument" so I'm gonna stick with the Budman1's method.
Similar Threads
-
ffmpeg how to copy all streams to another wrapper
By jack616 in forum Video ConversionReplies: 4Last Post: 15th Nov 2016, 14:32 -
How to Demux avi with multiple video streams?
By Chojun in forum Newbie / General discussionsReplies: 34Last Post: 11th Dec 2015, 14:29 -
Losslessly demux elementary streams
By SameSelf in forum Video ConversionReplies: 7Last Post: 20th Sep 2015, 23:49 -
Replacing ALL audio streams of a video in ffmpeg but keep meta?
By kekeinself in forum AudioReplies: 0Last Post: 19th Aug 2015, 02:48 -
What is the ffmpeg command to merge two mono audio streams into one stereo?
By Iced Coffee in forum Video ConversionReplies: 1Last Post: 10th Feb 2013, 22:54