Combining Single Video With Multiple Audio Files Using FFmpeg
Posted: 09 Mar 2021 18:06
Folks, I hope I came to the right forum. I have very basic knowledge of batch files, and somebody here might actually enjoy helping me with a concept I have. Much greatful in advance!
Here's my idea. I have a video file that needs to be combined with all mp3 files in a specific folder, creating multiple instances of that same video, but with different audio tracks. The combining happens thanks to FFmpeg module that is able to take any video and glue it with any sound. The previous script that I used only combined video and audio files based on the same name. That means a video can only be combined with one audio that has exactly the same name as video, which isn't what I want this time. The previous code was this:
As soon as filename.mp4 a filename.mp3 were found in SOURCE folder, they would be combined and copied to filename.mp4 under YOUTUBE folder. Perfect! But not for my current goal. I now need to create an automatic task that combines filename.mp4 with filename1.mp3, filename2.mp3, filename3.mp3, etc.
Actually, the perfect representation of this concept would be: if I have two video files called rabbit.mp4 and elephant.mp4, and a bunch of rabbits and elephants in mp3 (each followed by a consecutive number), then running this batch would create as many rabbits and elephants, as there are mp3 files (with a correct video track, of course). And the resulting filenames would be the same as the mp3 files used.
It would be super cool if this batch could consider just the letters (and ignore the numeric differences) to combine rabbit vids with rabbit audios, and elephant vids with elephant audios. If it's impossible to do, I could settle for splitting rabbits and elephants by folders. Basically, coding a batch that takes an mp4 file and with a help of FFmpeg combines it with each mp3 file in some folder, then outputs the resulting mp4 file under the name of mp3 file.
rabbit.mp4
rabbit1.mp3
rabbit2.mp3
rabbit3.mp3
RUN BATCH
rabbit1.mp4
rabbit2.mp4
rabbit3.mp4
Is this something that .BAT file can handle? Again, thanks a ton for claryfying this to me!
Here's my idea. I have a video file that needs to be combined with all mp3 files in a specific folder, creating multiple instances of that same video, but with different audio tracks. The combining happens thanks to FFmpeg module that is able to take any video and glue it with any sound. The previous script that I used only combined video and audio files based on the same name. That means a video can only be combined with one audio that has exactly the same name as video, which isn't what I want this time. The previous code was this:
Code: Select all
set CONTENT=C:\MyProject
set PROGRAM=%ProgramFiles%\ffmpeg\bin\ffmpeg.exe
for %%a IN ("%CONTENT%\SOURCE\*.mp4") ^
do "%PROGRAM%" -i "%%a" -i "%PROGRAM%\SOURCE\%%~na.mp3" -map 0:v -map 1:a -c ^
copy "%CONTENT%\YOUTUBE\%%~na.mp4"
Actually, the perfect representation of this concept would be: if I have two video files called rabbit.mp4 and elephant.mp4, and a bunch of rabbits and elephants in mp3 (each followed by a consecutive number), then running this batch would create as many rabbits and elephants, as there are mp3 files (with a correct video track, of course). And the resulting filenames would be the same as the mp3 files used.
It would be super cool if this batch could consider just the letters (and ignore the numeric differences) to combine rabbit vids with rabbit audios, and elephant vids with elephant audios. If it's impossible to do, I could settle for splitting rabbits and elephants by folders. Basically, coding a batch that takes an mp4 file and with a help of FFmpeg combines it with each mp3 file in some folder, then outputs the resulting mp4 file under the name of mp3 file.
rabbit.mp4
rabbit1.mp3
rabbit2.mp3
rabbit3.mp3
RUN BATCH
rabbit1.mp4
rabbit2.mp4
rabbit3.mp4
Is this something that .BAT file can handle? Again, thanks a ton for claryfying this to me!