VLC can be automated to run via the command-line. Once the
command-line is formulated, it's possible to embed it into a script.
The command-parameters are a bit complicated, but there is an
easy way to have VLC create it for you.
The idea is to do manually the merge for one set of files, then
create the command-line from the verbose output.
This is described in the post
How can I make the following conversion in VLC from the commandline?,
and especially in the
answer by Alexander Higgins.
The simplified format of the command is:
vlc input --sout="[TRANSCODECOMMAND"]
Doing the merge after setting in VLC menu Tools > Messages the
Verbosity
to 2
, will give a line such as:
qt debug: Transcode MRL: sout=#transcode{vcodec=none,acodec=s16l,ab=160,channels=2,samplerate=44100,scodec=none}:std{access=file{no-overwrite},mux=wav,dst='C:/Users/alexh/source/repos/WaveEditor/WaveEditor/bin/Debug/samples/_AI_NylStr_MonRibb_Sft-A2-0.wav'}
Copying everything starting with #transcode
gives the following command:
"C:\Program Files\VideoLAN\VLC\vlc.exe" _AI_NylStr_MonRibb_Sft-G2-0.mp3 --sout="#transcode{vcodec=none,acodec=s16l,ab=160,channels=2,samplerate=44100,scodec=none}:std{access=file,mux=wav,dst=_AI_NylStr_MonRibb_Sft-G2-0-44100k.wav}" vlc://quit
Another useful program that is very easy to use is
MP4Box,
which can
downloaded here.
To add the audio to the video, you could do:
"C:\Program Files\GPAC\mp4box.exe" -add 1.aac 1.ts
This will do an in-place replace of 1.ts
, so will destroy the
original file.
To create an .mp4
video will require two lines:
"C:\Program Files\GPAC\mp4box.exe" -add 1.ts -new 1.mp4
"C:\Program Files\GPAC\mp4box.exe" -add 1.aac 1.mp4
Here is a batch script that enters all the sub-folders and
creates .mp4
files from the .ts
and .aac
files.
The target .mp4
file will have the same name as that of the
video file.
The .ts
and .aac
files are not deleted, for safety.
They can be deleted later if everything works as expected.
I suggested taking a backup of the parent folder,
just in case.
Here is the .bat
file. It should be put inside the Parent folder.
@echo off
setlocal EnableDelayedExpansion
for /d %%D in ("*") DO (
echo ** Entering folder : %%D
cd "%%D"
for %%F in (*.ts) do set "VIDEO=%%F"
for %%G in (*.aac) do set "AUDIO=%%G"
set "TARGET=!VIDEO:.ts=!"
echo ** Found: Video=!VIDEO! Audio=!AUDIO! Target=!TARGET!
"C:\Program Files\GPAC\mp4box.exe" -add "!VIDEO!" -new "!TARGET!.mp4"
"C:\Program Files\GPAC\mp4box.exe" -add "!AUDIO!" "!TARGET!.mp4"
cd ..
)
For two levels down, use two
FOR /D
commands:
@echo off
setlocal EnableDelayedExpansion
for /d %%D in ("*") DO (
echo ** Entering folder : %%D
cd "%%D"
for /d %%E in ("*") DO (
echo ** Entering sub-folder : %%E
cd "%%E"
for %%F in (*.ts) do set "VIDEO=%%F"
for %%G in (*.aac) do set "AUDIO=%%G"
set "TARGET=!VIDEO:.ts=!"
echo ** Found: Video=!VIDEO! Audio=!AUDIO! Target=!TARGET!
"C:\Program Files\GPAC\mp4box.exe" -add "!VIDEO!" -new "!TARGET!.mp4"
"C:\Program Files\GPAC\mp4box.exe" -add "!AUDIO!" "!TARGET!.mp4"
del "!VIDEO!"
del "!AUDIO!"
cd ..
)
cd ..
)