I've made a one-line batch file that takes any file sent to it and puts the audio stream into a .MP4 file including the original name. It works great for files with MP4 audio in them, but fails if the audio is MP3, etc.
I'd like to alter the command line so that VLC will automatically choose the extension and muxer to use, based on whatever the input audio track is. Is this possible?
You'd need to transcode the audio to something compatible with MP4 (like AAC) if the codec isn't already compatible.
If you make the assumption that ".aac" and ".mp4" both have MP4-compatible audio codecs, and any other file needs converting to MP4 then you can do it in a few lines of batch script.
You can get the file extensions by using this modifier:
^ Similar to what you did with %~n1. For a list of other ones see here:
http://www.microsoft.com/resources/docu ... x?mfr=true
Then you could do something like this:
Code: Select all
@echo off
set vlc="C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
set sout_copy="#std{dst=%~n1_audio.mp4}"
set sout_convert="#transcode{vcodec=none,acodec=mp4a,ab=128,channels=2}:file{dst=%~n1_audio.mp4}"
if "%~x1"==".mp4" goto copy
if "%~x1"==".aac" goto copy
:convert
echo Going to convert...
set sout_vars=%sout_convert%
goto run
:copy
echo Going to copy...
set sout_vars=%sout_copy%
goto run
:run
%vlc% %1 --no-sout-video --sout %sout_vars% vlc://quit
I appreciate that it's quite long (there are probably more efficient ways to write in in batch), but what I came up with. All it does is look at the file extension, and change the sout string accordingly.
The first few lines just set up where vlc.exe is, what the "copy" sout string looks like and what the "convert" sout string looks like.
The convert sout string converts the source audio to 2 channel mp4a (AAC) audio with a bitrate of 128kbps. You can change this of course. The file name is the as what you put (original file name, exentionless, with "_audio.mp4" afterwards).
The next couple of lines just run if statements, and if true, jumps to the "copy" section. This just copys the "sout_copy" to "sout_vars". If both if statements are false the ":convert" section will run. The "goto" jumps to ":run", and runs VLC.
Also, it fails if the file has a comma or apostrophe in it. (And maybe other characters too?) Is there a way round that?
If you put the dst in single quotes it should help. So:
Special charaters should be escaped using a \ etc., not sure whether that can be done in batch. Ideally avoid commas and single quotes in filenames anyway.
Cheers, Arite.