I am making an answer out of my comment, I think it is the cause of your problem.
In your script you use
CALL "C:\Program Files (x86)\VideoLAN\VLC\vlc" -I dummy -vvv %1 --sout=#transcode{vcodec="h264", vb="512", fps="23.97", scale="1", acodec="mpga",ab="128","channels=2",samplerate="44100"}:standard{access="file",mux="dummy",dst="%_commanm%.mp4"} vlc://quit
and the error shows
main stream output error: stream chain failed for `transcode{vcodec=h264,'
this leads me to the conclusion that the parser cuts at every whitespace (space, tab etc) and thus cannot understand the command. In the link to the VLC wiki there are no whitespaces as well.
try this line:
CALL "C:\Program Files (x86)\VideoLAN\VLC\vlc" -I dummy -vvv %1 --sout=#transcode{vcodec="h264",vb="512",fps="23.97",scale="1",acodec="mpga",ab="128","channels=2",samplerate="44100"}:standard{access="file",mux="dummy",dst="%_commanm%.mp4"} vlc://quit
Why can't vlc cope with those stupid whitespace you might ask? (actually you do ;) )
When a programm is called to be executed by the OS - I only know this for linux for sure, but I am pretty sure windows handles it very similar - the parameters to the command are split by the operating system (at the spaces) and then handed to the program as a list, each containing only the content between the spaces.
So it would be the programs task to recognize and read all the individual entries in that list and glue them together again, this is indeed possible but costs time, both when developing the software and when evaluating the parameters.
Multimedia files are complex, so concatenation has several requirements:
- All segments to be concatenated must have the same number and type of streams.
- All streams must have the same parameters.
Since each input may vary in any arbitrary parameter I recommend using the concat filter. You will have to conform each input to a common set of parameters using filters. The input format doesn't matter so much because you're going to re-encode everything anyway.
Basic, generic example where main.mp4
has video and audio and end.mp4
has video and no audio. All other parameters are assumed to be different. The filters used here are: anullsrc, scale, pad, setsar, fps, format, aformat, and concat.
ffmpeg -i main.mp4 -i end.mp4 -f lavfi -t 0.1 -i anullsrc=channel_layout=stereo:sample_rate=44100 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=25,format=yuv420p[v0];[1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=25,format=yuv420p[v1];[0:a]aformat=channel_layouts=stereo:sample_rates=44100[a0];[v0][a0][v1][2:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart output.mp4
There are several ways to do this, and you may have to make adjustments based on your inputs or to fit your requirements.
Best Answer
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:
Doing the merge after setting in VLC menu Tools > Messages the
Verbosity
to2
, will give a line such as:Copying everything starting with
#transcode
gives the following command: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:
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: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.For two levels down, use two FOR /D commands: