Help with making ffmpeg concatenate button


I need a button that will merge the selected mp3 files in the current source path into one new mp3 into the same path. I guess ffmpeg could do that with one button to automate the whole thing but I'm stuck.

According to this page, there are 2 ways to use the concat command from ffmpeg.

Let's say we want to merge the files 1.mp3 & 2.mp3 into a file named 1_join.mp3.

First example that use one simple command line:

"D:\My path to\ffmpeg.exe" -i "concat:D:\files to merge\1.mp3|D:\files to merge\2.mp3" -acodec copy "D:\files to merge\1_join.mp3"

I don't know how to handle the " | " that split the files list. Maybe with the MS-DOS batch function instead of the standard one.

Second example that use a text file containing the files path to concatenate:
files list in list.txt must have this form

file "D:\files to merge\1.mp3" file "D:\files to merge\2.mp3"
then the command line will be

"D:\My path to\ffmpeg.exe" -f concat -i list.txt -c copy "D:\files to merge\1_join.mp3"

I have no idea how to create such text file containing my selected mp3 and then use it in the command line.

I need help please.

config in signature

You will probably need a (fairly simple) script to do that, since it requires an unusual command-line or list file.

Are you using Opus 11, or is your sig with Opus 10 up-to-date?

Unfortunately, I'm still using the v10. I don't feel the need to upgrade because of my old current laptop running XP. I will when I get a new computer one day. But for now, I'm stuck with the v10.

This screams for some kind of @finally and/or @first modifier.. o)

You could have a button like this:

echo >>list.txt file "{f}"

set filename={f|noext}

ffmpeg.exe -f concat -i list.txt -c copy "{dest}$filename.mp3"
del list.txt[/code]

I'm sorry this does not help you fred, and leo, you probably roll you eyes now, but I thought the idea was great. o)

In case you run v11 one day, I'd be glad to supply the missing piece of scripting.

We have real scripting now, so we probably won't be adding many more script-like things to the basic command syntax.

Which is totally sane! o)

So no idea compatible with the v10 guys?

Well, it can be jscripted or put into a batch file of course.
Can you estimate the maximum number of files to join?

For security purpose Windows Scripting Host is disabled on my computer so js & vbs fies won't run. Only bat or cmd files can be used for this. I estimate the maximum number of files to join to 10.

I would say now you have a need, I would do this in a script and could assist you if you could run scripts.
An alternative approach would be to use Powershell if you cant do what you want in BAT.

Thanks.The new script feature seems very powerful. I'll come back when I upgrade in the course of the year. In the meantime, if someone have an idea with batch in v10...

can you use powershell, it will be easier to code (least would be for me)?

Yes. I can install it and use it. If you think you can achieve the need described in first post with it, you're welcome.

Quick and dirty powershell version (actually this was not so very quick, as handling named and unnamed params at the same time, did not work out, so there's no usage of powershells regular param() handling here, but things should work as expected nonetheless, just keep params in expected order).

Save to "join.ps1"

$ffmpeg, $destfolder, $files = $args; &"$ffmpeg" -i ('"concat:'+($files -join '|')+'" -acodec copy "'+(join-path -path $destfolder -childpath $files[0].split('.')[0])+'_joined.mp3"')
DO Button (edit path to "join.ps1" and "ffmpeg.exe", maybe remove @leavedoswindowopen after tests):

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>Join MP3s with ffmpeg</label> <tip>Join MP3s with ffmpeg to destination</tip> <icon1>#join</icon1> <function type="batch"> <instruction>@filesonly </instruction> <instruction>@nodeselect </instruction> <instruction>@leavedoswindowopen </instruction> <instruction>powershell.exe -file join.ps1 &quot;C:\path to\ffmpeg.exe&quot; {d} {O}</instruction> <instruction /> <instruction>//content of powershell script &quot;join.ps1&quot;</instruction> <instruction>//----------------------------------------</instruction> <instruction>//$ffmpeg, $destfolder, $files = $args;</instruction> <instruction>//&amp;&quot;$ffmpeg&quot; -i (&apos;&quot;concat:&apos;+($files -join &apos;|&apos;)+&apos;&quot; -acodec copy &quot;&apos;+(join-path -path $destfolder -childpath $files[0].split(&apos;.&apos;)[0])+&apos;_joined.mp3&quot;&apos;)</instruction> <instruction>//----------------------------------------</instruction> </function> </button>
Not tested with ffmpeg, in case it fails, you should be able to fix it. Instead of ffmpeg.exe I used a minimal batch file to get the resulting params printed, maybe it is of help to you too, here it is:

echo %*


Nice work :slight_smile:

Thanks. I'll try it as soon as I can and I'll give you feedback.

I was going to post this same question myself, but a search took me here and saved me the trouble. By tinkering with the answers above, I was able to get it to work.

echo >>list.txt file '{f}'

"C:\Program Files\Serviio\lib\ffmpeg.exe" -f concat -i list.txt -c copy "{d!}{Rs|Output file name? (mp3 will be appended}.mp3"
del list.txt[/quote]

Simple enough to adjust the output etc, or auto select the input, but it works, I while I don't have a v10 to test it on, it apprears the the @nofilenamequoting exists in 10, so it will work I think. It works in 11, that much I know. :slight_smile:

Yes it should work. I was planning to code an autoit app that would act as a launcher with command line options so it could face any situations, even the specific as this one. But I have no time at all at the moment to do it.

Thanks for sharing.

Well, as you can imagine, this isn't very robust, but it does (almost) exactly what you want. I just reread the original post and see that you wanted the output to source not dest, so just change it to...

"C:\Program Files\Serviio\lib\ffmpeg.exe" -f concat -i list.txt -c copy "{Rs|Output file name? (mp3 will be appended)}.mp3"

and voila! It is there :slight_smile:

Time for bed

I just discovered two shortcomings of the above command. The first is that with long paths, it will fail. The second is that it won't work in flat mode.
A bit of tweaking and these are circumvented.

echo >>c:\list.txt file '{fs}'

"C:\Program Files\Serviio\lib\ffmpeg.exe" -f concat -i c:\list.txt -c copy "{d!}{Rs|Output file name? (mp3 will be appended)}.mp3"

del c:\list.txt