Page 1 of 1

Extracting audio from a video file dual audio

Posted: 10 Jul 2013 07:55
by poderpelon
I have a video with dual audio English and Japanese.
I tried to extract the Japanese audio following this video https://www.youtube.com/watch?v=wpyrZhQZVEc
but I haven't been able to find the option to chose the audio, i can extract the English audio that is the default but that is not the audio that i want :( .

If you know how to extract the audio, I would appreciate any help.

Re: Extracting audio from a video file dual audio

Posted: 10 Jul 2013 22:38
by JSLover
If you know how to extract the audio, I would appreciate any help.
I use this to slice the Audio out of a Video file (without transcoding)...
  • Code: Select all

    "vlc.exe" "file.webm" --no-sout-video :sout=#file{dst=file.out.webm}
...sorry, I don't know how (or if) you can do that in the VLC interface, instead of the command line.

I'm not sure if I have any Video files with dual Audio streams to test it on, but I'll dig around & see what I can find. With this command, you might get a file with BOTH Audio streams (but of course no Video) -- I'll try to find a command for selecting which stream to output.

UPDATE

This has been the most annoying thing to test/debug...there seems to be NO INFO on the syntax of "stream output chains", specifically VLC's --sout command line option -- WTF goes after the equals sign???...
...sure the docs have SOME examples, but not anything I actually wanna do.

So, after much Googling, reading & testing, I actually got this to work!...sort of...

As my example above shows, file (or specifically "#file") is actually one of the things you can put after --sout=...I'm not even sure where I found that, but once I did, I saved that in a text file!
  • Code: Select all

    "vlc.exe" "file.in.webm" --no-sout-video :sout=#file{dst=file.out.webm}
...this seems to only extract ES 1 (Elementary Stream 1) -- that's VLC-speak for "Audio Track 1", I don't think there's a simple way to edit that command to only output ES 2 (audio track 2), you have to re-write it completely, using more syntax that there's no documentation for.

So, here's what I've learned...
  • Using the file output module...
    • Output ES 1 via file output module (might be same as 1st example, but longer)...
      • Code: Select all

        "vlc.exe" "file.in.mkv" --no-sout-video --sout-all ":sout=#duplicate{dst=file{dst=file-es1.out.mkv},select=es=1}"
      Output ES 2 via file output module...
      • Code: Select all

        "vlc.exe" "file.in.mkv" --no-sout-video --sout-all ":sout=#duplicate{dst=file{dst=file-es2.out.mkv},select=es=2}"
      ...here I technically use the duplicate module, since I think I need to to be able to use select. I duplicate the stream & output (dst) it to the file module, like I did before. In the file module, I only output (dst) it to a filename. After closing the "}" on the file module, I use select on the duplicate module to force the param "es=1" or "es=2"...which selects which "Elementary Stream" I want.

      Using this method seems pretty good...
      • Pros...
        • It keeps the original container (mkv in my tests) (file timing/position info works/displays correctly)
      • Cons...
        • Loses Audio track meta-info (resulting file says "Track 1" instead of "Track 1 - [English]" {or whatever the original track info said})
      During testing, I actually did this...
      • Output ES 0-4 via file output module...
        • Code: Select all

          "vlc.exe" "file.in.mkv" --no-sout-video --sout-all ":sout=#duplicate{dst=file{dst=file-es0.out.mkv},select=es=0,dst=file{dst=file-es1.out.mkv},select=es=1,dst=file{dst=file-es2.out.mkv},select=es=2,dst=file{dst=file-es3.out.mkv},select=es=3,dst=file{dst=file-es4.out.mkv},select=es=4}"
        ...that tries to output ES0 thru ES4 (I don't actually know if Elementary Streams count from 0 or 1, but I tried ES0 anyway). In my tests, the files file-es0.out.mkv, file-es3.out.mkv & file-es4.out.mkv were actually created, but were blank (0 bytes). Only file-es1.out.mkv & file-es2.out.mkv had data. So I think ES's count from 1...& my input file only had 2 audio tracks, so stopping at 2 makes sense.
    Using the es output module...
    • Output ES 1 via es output module...
      • Code: Select all

        "vlc.exe" "file.in.mkv" --no-sout-video --sout-all ":sout=#duplicate{dst=es{dst=es-es1.out.mkv},select=es=1}"
      Output ES 2 via es output module...
      • Code: Select all

        "vlc.exe" "file.in.mkv" --no-sout-video --sout-all ":sout=#duplicate{dst=es{dst=es-es2.out.mkv},select=es=2}"
      ...here I only replaced file with es (& changed the output filename for clarity/testing). Remember, this is all guesswork, since I can find no info on what actually goes where.

      Using this method seems a little worse, but better in another way?...
      • Pros...
        • Keeps Audio track meta-info (resulting file says "Track 1 - [English]" {or whatever the original track info said} instead of "Track 1")
      • Cons...
        • Loses the original container (mkv in my tests) (uses unknown default container or possibly no container) (file timing info says 0:00 for current position & length, but file plays fine in VLC)
      During testing, I again did this...
      • Output ES 0-4 via es output module...
        • Code: Select all

          "vlc.exe" "file.in.mkv" --no-sout-video --sout-all ":sout=#duplicate{dst=es{dst=es-es0.out.mkv},select=es=0,dst=es{dst=es-es1.out.mkv},select=es=1,dst=es{dst=es-es2.out.mkv},select=es=2,dst=es{dst=es-es3.out.mkv},select=es=3,dst=es{dst=es-es4.out.mkv},select=es=4}"
        ...this time, only es-es1.out.mkv & es-es2.out.mkv were output & had data (the non-existent ES's were not output as 0 bytes files).
      Since that has the con of losing the original container (mkv in my tests), lets try to force mkv, shall we? After lots more searching & digging, I find "--sout-es-mux", but, of course, there's no info on "what goes after the equals sign?"...or "what muxers are available?". So, I just put things there & watch it bomb out!
      • Code: Select all

        "vlc.exe" "file.in.mkv" --no-sout-video --sout-es-mux=mkv --sout-all ":sout=#duplicate{dst=es{dst=es-es2.out.mkv},select=es=2}"
      Results?...
      • Tries to force mkv container (--sout-es-mux=mkv), fails, this doesn't work at all!
      ...I guess "mkv" isn't valid after that equals sign?, but nothing told me that did it? Too bad I'm not psychic...or maybe I am, cuz next I tried "mp4"...
      • Code: Select all

        "vlc.exe" "file.in.mkv" --no-sout-video --sout-es-mux=mp4 --sout-all ":sout=#duplicate{dst=es{dst=es-es2.out.mkv},select=es=2}"
      Results?...
      • Forces mp4 container (--sout-es-mux=mp4), works (file timing info works/displays correctly), but not correct if original file was mkv.
      • Keeps Audio track meta-info (resulting file says "Track 1 - [English]" {or whatever the original track info said} instead of "Track 1")
      ...that seems pretty good, keep the audio track meta-info, lose the original container, replacing it with a container that preserves the timing info.
Also, in my searches, I found...
  • --audiofile-file
    • What does this do? Nothing...
      • Code: Select all

        "vlc.exe" "file.in.mkv" --audiofile-file="file.out.mkv"
      ...no file output, no joy. Just plays the input file as if you didn't provide the --audiofile-file option. I'm sure I'm missing something about HOW to use it, but, again I'm NOT psychic!
    --sout-select-enable
    • What does this do? Nothing / Outputs ES1 like we can already do.
      • Code: Select all

        "vlc.exe" "file.in.mkv" --no-sout-video --sout-select-enable=2 :sout=#file{dst=file.out.mkv}
...well that was fun, I'm gonna go smash my head into a wall now...

Re: Extracting audio from a video file dual audio

Posted: 11 Jul 2013 15:45
by mederi

Re: Extracting audio from a video file dual audio

Posted: 11 Jul 2013 20:19
by JSLover
...wow, OF COURSE there's an :audio-track option I didn't find!...now I can reduce the above to...
  • Extract Audio Track 1 (like we could always do, but this is for completeness)...
    • Code: Select all

      "vlc.exe" "file.in.mkv" --no-sout-video :audio-track=0 ":sout=#file{dst=file.audio-track-1.out.mkv}"
    Extract Audio Track 2 (what we've wanted to do the whole time!)...
    • Code: Select all

      "vlc.exe" "file.in.mkv" --no-sout-video :audio-track=1 ":sout=#file{dst=file.audio-track-2.out.mkv}"
...note: :audio-track is ZERO-based. So, for "Track 1" you need to use ":audio-track=0" & for "Track 2" you use ":audio-track=1".

If you add --sout-all, the file will have BOTH audio tracks (at which point I don't think the :audio-track option option has any effect?)

Now for the holy grail: Can you make VLC SWAP the 2 audio tracks? Take an input file, with Video, 2 Audio tracks (French, English) & output a file, with or without Video, but with the Audio tracks swapped (English, French)...also by "SWAP the 2 audio tracks", I mean as LOSSLESSLY as possible, no transcoding. Every example with VLC shows transcoding, I just want to surgically re-arrange a video & put it back like it was: same container, same video encoding, same audio encoding, same everything, EXCEPT for changing which Audio Track is default (which one is Track 1). Bonus points if you can KEEP the Audio Track meta-data (the name/language/description of the track), for example, if the input file says...
  • >> French << - [Français]
    >> English << - [English]
...the output file should say...
  • >> English << - [English]
    >> French << - [Français]
If the input file says...
  • Track 1 - [Français]
    Track 2 - [English]
...the output file should say...
  • Track 1 - [English]
    Track 2 - [Français]
...VLC is extremely powerful, but trying to figure out how to tell it what you want to do is impossible!