0

I have a large folder containing many ts video files as well as an equivalent number of aac audio files. So far, I am only capable of merging a single ts file with a single aac file to create a single mp4/ts output file using this command:

ffmpeg -i file1.ts -i file1.aac -c:v copy -c:a copy output1.mp4

Since I am working with many audio and video files, it is impractical to use the method above. Is there a way that I can perform the merging job for many audio and video files at once instead of doing one combination at a time i.e. e.g merging file2.ts and file2.aac to create output2.ts, file3.ts and file3.aac to create output3.ts and so on. How would I use say, a for loop, or any other looping statement to achieve this objective. Kindly assist. Thanks.

LexLiu
  • 13
  • 4
  • Requires usage of a loop as you mentioned. This functionality is not available in ffmpeg alone. Needs a shell or script. But your OS/shell/preferred scripting language is unknown. – llogan Apr 23 '20 at 18:04
  • Hello @llogan thanks for replying. Sorry I forgot to mention that I am using Windows 10 as my OS. I ran the command above in the Command Prompt. My preferred scripting language would be Python, I guess. – LexLiu Apr 23 '20 at 20:18
  • You've said the functionality is not available in ffmpeg alone. If there are other tools that you can suggest that can also provide a solution, kindly share and please show me how to use them. Thanks. – LexLiu Apr 23 '20 at 20:25
  • What I meant is ffmpeg can do the muxing. It can't do a batch mode or a loop. So your question would be more accurate if you asked, "How to perform a loop in python?" or something like that because you already have the ffmpeg part working. Altohugh I would recommend some minor changes `ffmpeg -i file1.ts -i file1.aac -map 0:v -map 1:a -c copy -shortest -movflags +faststart output.mp4` – llogan Apr 23 '20 at 21:39
  • Thanks @llogan. I have come across an idea on YouTube where a batch (.bat) file containing the looping code is created. The batch file is then run on the command prompt from the location containing the files to be worked on. In the YouTube tutorial, the script used in the batch file is used to loop through a group of video (.mp4) files and convert them into audio mp3 files. The script is as follows: `echo off mkdir outputs for %%a in ("*.mp4") do ffmpeg -i "%%a" -b:a 192K -vn "outputs\%%~na.mp3" pause` How I should modify the script above to suit the problem that I have? – LexLiu Apr 23 '20 at 22:00
  • I'm not a Windows user, and too lazy to look up how to do it, so I can only guess `mkdir outputs for %%a in ("*.mp4") do ffmpeg -i "%%a" -i "%%~na.aac" -map 0:v -map 1:a -c copy -shortest -movflags +faststart "outputs\%%~na.mp4"`. That being said there are many [tag:ffmpeg] + [tag:batch-file] questions here on this site, including some WIndows/cmd/PowerShell/batch specific commands in [How do you convert an entire directory with ffmpeg?](https://stackoverflow.com/q/5784661/) – llogan Apr 24 '20 at 18:11

0 Answers0