1

I face the following problem from time to time when I want to download some video:

This video has not been mixed with the audio because the audio stream has a different format

enter image description here

I want to know How to fix this problem if possible and If not How to merge the output which is two separate files:

TS file ---> video 
AAC file --> Audio

I Use VLC program but it takes a lot of time because I have to pass many steps to merge just a one item and I have so many files separated!


If I have directory hierarchy like that:

Parent
    |
   Folder1 -->Sub1 --->1.ts
                   --->1_audio.aac

           -->Sub2 --->2.ts
                   --->2_audio.aac
 
   Folder2 -->Sub1 --->1.ts
                   --->1_audio.aac

How to convet it to

  Parent
    |
   Folder1 -->Sub1 --->1.mp4

           -->Sub2 --->2.mp4
                   
 
   Folder2 -->Sub1 --->1.mp4
                   
          
17
  • May I suggest youtube-dl? Don’t know where you’re downloading from, but youtube-dl basically does it all.
    – Daniel B
    Commented Aug 25, 2021 at 18:15
  • There are many video/audio mixing programs, some dead simple - see here. However, I'm wondering if the problem arises because the video already contains an audio stream - are you trying to replace or add a sound-track and the two are not of the same format?
    – harrymc
    Commented Oct 13, 2021 at 19:07
  • @harrymc I try to download a video through IDM from pluralsight to watch it later but I face this problem!! And I don’t know why this happens and how to merge them easily Commented Oct 16, 2021 at 0:23
  • Something is wrong here. Could you post online (OneDrive, Dropbox etc) an example?
    – harrymc
    Commented Oct 16, 2021 at 8:43
  • Another question: Have you tried to play the TS file by itself to see if it already has audio?
    – harrymc
    Commented Oct 17, 2021 at 8:53

2 Answers 2

1
+50

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 ..
)
5
  • Thanks a lot, I put the script in the parent folder but it doesn't work, I have to put it in each individual folder to work. I'm so sorry if I didn't explain the case as I should, I have nested folders = three levels( the parent, level1 level2, then the two files) ts file and the audio file with _audio at the end of the audio file name. and I want the script to delete the two files. just the mp4 file in each folder. I edited my question to illustrate the hierarchy of folders. Commented Oct 21, 2021 at 23:01
  • Could U read my comment plz 🥺 Commented Oct 22, 2021 at 20:10
  • 1
    @AnynameDonotcare: No problem. Done.
    – harrymc
    Commented Oct 22, 2021 at 20:21
  • U are just amazing, the last thing, I want to delete both ts,aac files, I want just mp4 file please. Commented Oct 22, 2021 at 20:29
  • @AnynameDonotcare: Added to the second script. Good night.
    – harrymc
    Commented Oct 22, 2021 at 20:33
3

It probably is easier to use ffmpeg to do a quick merge of your files than to do it by loading both files in VLC simultaneously.

You can just use a command line like powershell or cmd if you prefer and write

ffmpeg -i video.ts -i audio.aac -c:v copy -c:a copy output.mp4

If you don't have ffmpeg installed, there are precompiled binaries on the official ffmpeg website.


Deeper going explanations: ffmpeg itself is a command line tool. There are so many features that a gui would inevitably be very complex and frustrating to use as it would be convoluted. There are compiled versions of ffmpeg with gui but I would not recommend to use them as they are always made for a specific purpose which never completely matches with yours. Instead I would use the command line version by gyan which indeed is linked to on the official website above. Just put it in a folder contained in your PATH variable or directly execute it from the folder. Use the command above, replace video.ts with the path to your video file, audio.aac with the path to your audio file and output.mp4 with a path to a new file that will be generated. Think of it as the usual "Save As..." option. I hope this makes it clearer.

2
  • Could I ask If ffmpeg has exe to download cuz the site just has source code Commented Aug 25, 2021 at 16:11
  • Plz Could U give me more details I imagined that it was an application with easy to use interface Commented Aug 25, 2021 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .