Use Ffmpeg to Add Music Intro and Outro to Video
Step 1 Get the duration of the main file.

ffprobe main.mp4 -show_entries format=duration -of compact=nk=1:p=0 -v 0


This will print out a single value, like this

61.600204


which is the duration in seconds.

Step 2 Perform the concat

ffmpeg -i main.mp4 -i intro.mp4 -i outro.mp4 \
  -filter_complex "[1]trim=0:20,setpts=PTS-STARTPTS[pre]; \
                   [2]trim=10,setpts=PTS-STARTPTS[post]; \
                   [pre][0][post]concat=n=3:v=1:a=0[v]; \
                   [1:a][0:a]acrossfade=d=10[a1];[a1][2:a]acrossfade=d=10[a]" \
  -map '[v]' -map '[a]' out.mp4


Since the video and audio from the intro/outro are treated differently, in terms of duration, we perform two separate concats.

First, the intro video is trimmed to leave out the last ten seconds. The outro is trimmed to leave out its first ten seconds. Then those two trimmed segments are sandwiched with the main video stream in the first concat.

For audio, the crossfades are performed in two stages. First, the intro with the main audio. Then, that result with the outro audio. Duration of crossfade is 10 seconds.



In case, the intro/outro music and image are separate files, use

ffmpeg -i main.mp4 -i intro.mp3 -i outro.mp3 \
       -loop 1 -framerate X -t 20 -i pre.jpg -loop 1 -framerate X -t 20 -i post.jpg \
  -filter_complex "[3][0][4]concat=n=3:v=1:a=0[v]; \
                   [1:a][0:a]acrossfade=d=10[a1];[a1][2:a]acrossfade=d=10[a]" \
  -map '[v]' -map '[a]' out.mp4


Here, X should be replaced with the framerate of the main file. The images should be of the same resolution as the video.