VideoHelp Forum




+ Reply to Thread
Results 1 to 9 of 9
  1. Hi.

    I'm using something like this in a .bat to demux every audio stream in a file with ffmpeg:

    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
    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 ?

    Any help is appreciated.
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    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 have timeout, depending on your version of windows but I threw it in to give the PC time to write the first file.
    You may not need it anyway. The above method finishes the first audio and errors on the second one without writing it.
    Quote Quote  
  3. @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 ?
    Quote Quote  
  4. If "-map 0:a:1?" isn't matching anything it will be ignored as if it was not set at all. Since that is the only -map for the second output file ffmpeg falls back to the default mapping (IIRC: first video, first audio, first subtitle).
    Quote Quote  
  5. @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 ?
    Quote Quote  
  6. Originally Posted by leonsk View Post
    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?")
    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.
    Quote Quote  
  7. So this :

    Code:
    ffmpeg -i "INPUT" -map 0:a:0? -c copy -map 0:a:1? -c copy "OUTPUT"
    is equal to this ?

    Code:
    ffmpeg -i "INPUT" -map 0:a:0? -c copy -map 0:v:0 -map 0:a:0 -map 0:s:0 "OUTPUT"
    Of course I mean if there's only one audio stream.

    btw, do you know how to get rid of the chapters when demuxing ?
    Quote Quote  
  8. Originally Posted by leonsk View Post
    So this :

    Code:
    ffmpeg -i "INPUT" -map 0:a:0? -c copy -map 0:a:1? -c copy "OUTPUT"
    is equal to this ?

    Code:
    ffmpeg -i "INPUT" -map 0:a:0? -c copy -map 0:v:0 -map 0:a:0 -map 0:s:0 "OUTPUT"
    Of course I mean if there's only one audio stream.
    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).

    Originally Posted by leonsk View Post
    do you know how to get rid of the chapters when demuxing ?
    -map_chapters -1
    Quote Quote  
  9. You mean one audio, no video, no subtitles?
    No I mean with at least one video stream.

    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.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!