-2

I am allowing users to upload audio files with file extensions mp3, wav, flac. With the following command, I can concatenate audio files if it is in mp3 only.

ffmpeg -i "concat:sample1.mp3|sample2.mp3" -c:a libmp3lame -write_xing 0 merged.mp3

How can i merge if the audio files are in different formats and encoding using ffmpeg or php? In the ffmpeg documentation, it provides an example for concatenating files with different codes but the example includes video files like mp4,webm,mov but i need example for audio only. FFmpeg documentation of concatenate

-filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mkv```

sonam
  • 3,720
  • 12
  • 45
  • 66
  • 1
    I’m voting to close this question because , as explained by the ffmpeg tag: Only questions about programmatic use of the FFmpeg libraries, API, or tools are on topic. Questions about interactive use of the command line tool should be asked on https://superuser.com/ or https://video.stackexchange.com/. Please delete this. – Rob May 25 '23 at 07:15
  • Then why allow ffmpeg tag questions to be posted in first place? – sonam May 25 '23 at 07:59

1 Answers1

2
ffmpeg -i sample1.mp3 -i sample2.wav -i sample3.flac -filter_complex "[0:a][1:a][2:a]concat=n=3:v=0:a=1[outa]" -map "[outa]" -c:a libmp3lame merged.mp3

-i sample1.mp3 -i sample2.wav -i sample3.flac : Audio files are specified.

-filter_complex "[0:a][1:a][2:a]concat=n=3:v=0:a=1[outa] : The filter_complex concatenates the audio streams from the three input files.

[0:a][1:a][2:a] Three audio streams are represented, and concat=n=3:v=0:a=1[outa] concatenates them into a single audio stream [outa].

The v=0 Parameter indicates no video streams.

-map [outa] : [outa] specifies the output should include audio.

-c:a libmp3lame : Is used to encode the merged audio as an MP3 file.

merged.mp3 : Specifies the name of the output file.