Hahnemann
Hahnemann

Reputation: 4678

Merge M4A files in Terminal

I have a couple of M4A (sound) files on a Mac that I want to combine into a single sound file. Can this be done with a Terminal command? Is there such a thing?

Upvotes: 21

Views: 17274

Answers (6)

Ben
Ben

Reputation: 6348

Gleaned from the comments of https://stackoverflow.com/a/31033308/2958070:

ffmpeg -f concat -safe 0 -i <(for f in ./*.m4a; do echo "file '$PWD/$f'"; done) -c copy output.m4a

Here's the version of my ffmpeg that brew installed

$ ffmpeg -version
ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 14.0.0 (clang-1400.0.29.202)
configuration: --prefix=/usr/local/Cellar/ffmpeg/5.1.2_4 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil      57. 28.100 / 57. 28.100
libavcodec     59. 37.100 / 59. 37.100
libavformat    59. 27.100 / 59. 27.100
libavdevice    59.  7.100 / 59.  7.100
libavfilter     8. 44.100 /  8. 44.100
libswscale      6.  7.100 /  6.  7.100
libswresample   4.  7.100 /  4.  7.100
libpostproc    56.  6.100 / 56.  6.100

See also: https://trac.ffmpeg.org/wiki/Concatenate

Upvotes: 4

Estatistics
Estatistics

Reputation: 946

echo "" >./m4a.txt; for f in *.m4a; do echo "file '$PWD/$f'" >> ./m4a.txt; done; fpdd ./m4a.txt;

and then:

ffmpeg -f concat -safe 0 -i "./m4a.txt" --whatever parameters output.m4a

Upvotes: 1

Nick Haddad
Nick Haddad

Reputation: 8937

FFMPEG can help you with this. Check out their How To Contatenate media files article.

Upvotes: 6

Marek M&#246;hling
Marek M&#246;hling

Reputation: 152

github.com/mifi/lossless-cut is for audio/video editing using ffmpeg. Works fine for merging mp3/mp4/m4a with drag and drop.

sudo snap install losslesscut

Upvotes: 2

occvtech
occvtech

Reputation: 463

Are you trying to have the audio playback one after another, or playback on top of one another at the same time?

Either way FFmpeg can do the trick. The way I read your question, you want them playing back at the same time... If that's the case, try:

ffmpeg -i [input1] -i [input2] -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map [a] -c:a libfdk_aac out.m4a

Note: this is going to compress the audio to AAC. It is one of the best audio encoders, so you won't really notice a difference, but if you need to maintain quality, you can always go uncompressed with pcm_s16le. However, I think you would then be better off going out to a .wav file.

Upvotes: 1

Kafaraqgatri
Kafaraqgatri

Reputation: 452

Yeah, ffmpeg doesn't work, contrary to what the internet echo chamber will tell you. At least not that way. It's incredible how many have to drool their wisdumb and waste everyone's time.

Here. Prove me wrong with a link, but this is what you want and this is the only place you'll see it. Tres simple.

ffmpeg -i file1.m4a -acodec copy file1.aac

ffmpeg -i file2.m4a -acodec copy file2.aac

cat file1.aac file2.aac >>filenew.aac

ffmpeg -i filenew.aac -acodec copy -bsf:a aac_adtstoasc filenew.m4a

I compiled my own ffmpeg for the extra libs, so I hope that that is one of the default ones. If not, it's definitely worth the hassle. I haven't been able to validate the above on a second system, but on my old Hardy Heron Ubuntu grunt system the joined file has all the right m4a meta data and tags and there is no change in audio quality.

Upvotes: 32

Related Questions