Merging mp3 files using cmd.exe

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WantToKnow
Posts: 61
Joined: 28 Mar 2020, 08:46

Merging mp3 files using cmd.exe

Post by WantToKnow » 01 Jul 2022, 06:56

Hello,

I'd like to merge a few mp3 files.

Using a batch file it works like this:

Code: Select all

copy /b file1.mp3+file2.mp3+file3.mp3 outputfile.mp3
How can I do this by using cm.exe?

Code: Select all

; Correct code for this code line needed:
Run cmd.exe copy /b file1.mp3+file2.mp3+file3.mp3 outputfile.mp3  ; ?? doesn't work

Thanks a lot for your help!

RussF
Posts: 1242
Joined: 05 Aug 2021, 06:36

Re: Merging mp3 files using cmd.exe

Post by RussF » 01 Jul 2022, 06:59

From the Run documentation:
If the program/document name or a parameter contains spaces, it is safest to enclose it in double quotes (even though it may work without them in some cases). For example, Run, MyProgram.exe "param with spaces".
Russ

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Merging mp3 files using cmd.exe

Post by mikeyww » 01 Jul 2022, 07:00

More ideas (I tested with some plain text files):

Code: Select all

dir   = %A_ScriptDir%
file1 = %dir%\a.txt
file2 = %dir%\b.txt
out   = %dir%\merged.txt
RunWait, %ComSpec% /c COPY %file1%+%file2% %out%
Run, %out%
Tips:

1. /c with ComSpec.
2. RunWait instead of Run (usually useful for situations like this).

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Merging mp3 files using cmd.exe

Post by garry » 01 Jul 2022, 15:56

also an example , read folder\subfolders for musicfiles and add fullpath to a text-file m3u to listen

Code: Select all

;- create a M3U-file at desktop to play music
;-
#warn
setworkingdir,%a_scriptdir%
mf:="D:\M_MEDIA\M_MUSIC\ASIA"  ;-- <<< your folder with Music files
SplitPath,MF, name, dir, ext, name_no_ext, drive
Extensions := "mp3,wav,aac"    ;-- some music extensions
F1:=a_desktop . "\" . name_no_ext . ".m3u"
ifexist,%f1%
  filedelete,%f1%
setworkingdir,%MF%
e:=""
Loop, Files,%mf%\*.*,R
    If InStr(Extensions, A_LoopFileExt)
        e .= A_LoopFileFullPath . "`r`n"
fileappend,%e%,%f1%,utf-8
e:=""
try
 run,%f1%
exitapp

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Merging mp3 files using cmd.exe

Post by teadrinker » 01 Jul 2022, 16:12

CMD is not needed at all for this purpose, AHK can merge files without help.

Code: Select all

file1 := "file1.mp3"
file2 := "file2.mp3"
file3 := "file3.mp3"

outFilePath := A_Desktop . "\test.mp3"
OutFile := FileOpen(outFilePath, "w")
for k, v in [file1, file2, file3] {
   File := FileOpen(v, "r")
   File.RawRead(buf, File.Length)
   OutFile.RawWrite(buf, File.Length)
}
File = OutFile := ""
Last edited by teadrinker on 02 Jul 2022, 03:29, edited 1 time in total.

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Merging mp3 files using cmd.exe

Post by garry » 02 Jul 2022, 03:15

thank you for examples
@mikeyww works fine with text-files
@teadrinker small typo > file3 := "file2.mp3"
works fine with mp3 ( just vlc.exe show me the wrong total time and see only the first picture ( pictures included in mp3-files ) )

another example to copy text-files to one text-file

Code: Select all

#warn
setworkingdir,%a_scriptdir%
mf:=a_desktop . "\TEST"                              ;- here files *.txt und *.ahk
SplitPath,MF, name, dir, ext, name_no_ext, drive
F1:=a_desktop . "\" . name_no_ext . ".txt"
ifnotexist,%f1%
  fileappend,,%f1%,utf-8
setworkingdir,%MF%
runwait, %comspec% /c type *.txt >>%F1%,,hide
runwait, %comspec% /c type *.ahk >>%F1%,,hide
try
run,%f1%
return
Last edited by garry on 02 Jul 2022, 03:49, edited 1 time in total.

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Merging mp3 files using cmd.exe

Post by teadrinker » 02 Jul 2022, 03:28

Yeah, thanks, edited.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Merging mp3 files using cmd.exe

Post by mikeyww » 02 Jul 2022, 05:01

Issue with merging MP3 may be the metadata, as I do not imagine that the metadata could be preserved that way-- seemingly confirmed by garry here.

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Merging mp3 files using cmd.exe

Post by teadrinker » 02 Jul 2022, 12:48

But cmd doesn't save metadata either.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Merging mp3 files using cmd.exe

Post by mikeyww » 02 Jul 2022, 13:04

I just meant either technique-- not really viable for true MP3.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Merging mp3 files using cmd.exe

Post by BoBo » 02 Jul 2022, 13:13

mikeyww wrote:
02 Jul 2022, 05:01
..., as I do not imagine that the metadata could be preserved that way-- seemingly confirmed by garry here.
Well, has he already tried cmd copy's /b(inary) switch? https://ss64.com/nt/copy.html

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Merging mp3 files using cmd.exe

Post by teadrinker » 02 Jul 2022, 13:56

I haven't tried it, but I think there's no point in keeping the metadata in this case. Imagine the files have different bitrates, what should be in the metadata? it would be better to just remove it.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Merging mp3 files using cmd.exe

Post by mikeyww » 02 Jul 2022, 14:06

Good point. MP3 can store multiple images, plus lyrics. Not sure if needed here.

From @BoBo: http://mp3wrap.sourceforge.net

Post Reply

Return to “Ask for Help (v1)”