13

I want to concatinate 4 different videos of 4 different resolution and type into 1 video which can be played in android. I am using ffmpeg ported on android using https://github.com/guardianproject/android-ffmpeg

So I have these 4 different types of videos 1)

./ffmpeg -i 1.mp4 
Video: h264 (High), yuv420p, 1920x1080, 16959 kb/s, 29.85 fps, 90k tbr, 90k tbn, 180k tbc
Audio: aac, 48000 Hz, stereo, s16, 106 kb/s

2)

ffmpeg -i 2.mp4
Video: h264 (Constrained Baseline), yuv420p, 640x480, 3102 kb/s, 29.99 fps, 90k tbr, 90k tbn, 180k tbc
Audio: aac, 48000 Hz, stereo, s16, 93 kb/s

3)

ffmpeg -i 3.3gp
Video: h263, yuv420p, 1408x1152 [PAR 12:11 DAR 4:3], 2920 kb/s, 15 fps, 15 tbr, 15360 tbn, 29.97 tbc
Audio: amrnb, 8000 Hz, 1 channels, flt, 12 kb/s

4)

ffmpeg -i 4.3gp
Video: h264 (High), yuv420p, 352x288 [PAR 12:11 DAR 4:3], 216 kb/s, 24 fps, 24 tbr, 24 tbn, 48 tbc

Audio: aac, 44100 Hz, stereo, s16, 92 kb/s

So I am converting them to mpegts using following commands

./ffmpeg -i 1.mp4 -c:v libx264 -vf scale=1920:1080 -r 60 -c:a aac -ar 48000 -b:a 160k -strict experimental -f mpegts 1.ts
./ffmpeg -i 2.mp4 -c:v libx264 -vf scale=1920:1080 -r 60 -c:a aac -ar 48000 -b:a 160k -strict experimental -f mpegts 2.ts
./ffmpeg -i 3.3gp -c:v libx264 -vf scale=1920:1080 -r 60 -c:a aac -ar 48000 -b:a 160k -strict experimental -f mpegts 3.ts
./ffmpeg -i 4.3gp -c:v libx264 -vf scale=1920:1080 -r 60 -c:a aac -ar 48000 -b:a 160k -strict experimental -f mpegts 4.ts

then concatenating the .ts files into f.ts and then creating a final .mp4 file from it using

cat 1.ts 2.ts 3.ts 4.ts > f.ts
./ffmpeg -i f.ts -c copy -bsf:a aac_adtstoasc output.mp4

But my f.ts also doesnt seem to play correctly in VLC on linux, it plays first 2 mp4's video + audio and it plays last .3gp's audio only.(Same for output.mp4 too) Could you please help me in figuring out what am I missing ?

Thanks in advance

Aalap
  • 2,847
  • 2
  • 26
  • 24
  • This answer on [superuser](https://superuser.com/a/1136305/940163) has worked for me. You will need to know the highest resolution of all the video files that you are trying to concatenate. Once that is known, it should be pretty quick! – Gru Aug 24 '21 at 15:03

1 Answers1

8

You can use concat to append all the videos one by one after converting them to a single format.

You can also use the below command to convert differently formatted video to one format:

./ffmpeg -i 1.mp4 -acodec libvo_aacenc -vcodec libx264 -s 1920x1080 -r 60 -strict experimental 1.mp4

Convert everything to mp4 and then follow the instructions given in the link above. This will enable you to join all the videos in a single file.

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
Satyam Naolekar
  • 560
  • 7
  • 10
  • Concat demuxer worked great for me! resulting videos do play nicely only on smplayer (MPlayer2 2.0-701-gd4c5b7f-2ubuntu2) and ffplay (N-78744-gbc7beb6, local compilation); VLC 2.1.6 stops updating the video image right at the beginning of the file, seeking doesn't help. This is what I ran: === ffmpeg -f concat -i file-list.txt -c copy output.mp4 === Input files differ only in frame size (same bitrate, codec settings, etc). – Jedihe Mar 16 '16 at 16:42