Step 1: First you must trans-code into standard MEPG-2 :
ffmpeg -i "file 1.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts temp1.ts
Example:
D:\ffmpeg\bin>ffmpeg -i "file 1.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegt s temp1.ts ffmpeg version N-84014-g9e6b269 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 6.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --e nable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth -- enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-li bfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug - -enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enabl e-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-li bsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolam e --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable -libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib libavutil 55. 48.100 / 55. 48.100 libavcodec 57. 83.100 / 57. 83.100 libavformat 57. 66.104 / 57. 66.104 libavdevice 57. 3.100 / 57. 3.100 libavfilter 6. 76.100 / 6. 76.100 libswscale 4. 3.101 / 4. 3.101 libswresample 2. 4.100 / 2. 4.100 libpostproc 54. 2.100 / 54. 2.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'em lien 1.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf56.40.101 Duration: 00:00:25.15, start: 0.000000, bitrate: 547 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 360x640, 474 kb/s, 28.59 fps, 29.97 tbr, 16k tbn, 59.94 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 63 kb/s (default) Metadata: handler_name : SoundHandler Output #0, mpegts, to 'temp1.ts': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.66.104 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 360x640, q=2-31, 474 kb/s, 28.59 fps, 29.97 tbr, 90k tbn, 16k tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 63 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 719 fps=0.0 q=-1.0 Lsize= 1884kB time=00:00:25.15 bitrate= 613.7kbits /s speed= 786x video:1457kB audio:194kB subtitle:0kB other streams:0kB global headers:0kB muxin g overhead: 14.187922% D:\ffmpeg\bin>ffmpeg -i "file 2.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegt s temp2.ts ffmpeg version N-84014-g9e6b269 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 6.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --e nable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth -- enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-li bfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug - -enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enabl e-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-li bsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolam e --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable -libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib libavutil 55. 48.100 / 55. 48.100 libavcodec 57. 83.100 / 57. 83.100 libavformat 57. 66.104 / 57. 66.104 libavdevice 57. 3.100 / 57. 3.100 libavfilter 6. 76.100 / 6. 76.100 libswscale 4. 3.101 / 4. 3.101 libswresample 2. 4.100 / 2. 4.100 libpostproc 54. 2.100 / 54. 2.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'em lien 2.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 title : 907341562758589 encoder : Lavf56.40.101 Duration: 00:00:19.57, start: -0.022109, bitrate: 1276 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280, 1240 kb/s, 24.95 fps, 24.92 tbr, 90k tbn, 49.81 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 47 kb/s (default) Metadata: handler_name : SoundHandler Output #0, mpegts, to 'temp2.ts': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 title : 907341562758589 encoder : Lavf57.66.104 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280, q=2-31, 1240 kb/s, 24.95 fps, 24.92 tbr, 90k tbn, 90k tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 47 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 481 fps=0.0 q=-1.0 Lsize= 3339kB time=00:00:19.31 bitrate=1416.0kbits /s speed= 690x video:2920kB audio:114kB subtitle:0kB other streams:0kB global headers:0kB muxin g overhead: 10.050540%
Step 2: join
ffmpeg -i "concat:temp1.ts|temp2.ts" -c copy -bsf:a aac_adtstoasc output2.mp4
Example:
D:\ffmpeg\bin>ffmpeg -i "concat:temp1.ts|temp2.ts" -c copy -bsf:a aac_adtstoasc output2.mp4 ffmpeg version N-84014-g9e6b269 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 6.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --e nable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth -- enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-li bfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug - -enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enabl e-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-li bsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolam e --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable -libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib libavutil 55. 48.100 / 55. 48.100 libavcodec 57. 83.100 / 57. 83.100 libavformat 57. 66.104 / 57. 66.104 libavdevice 57. 3.100 / 57. 3.100 libavfilter 6. 76.100 / 6. 76.100 libswscale 4. 3.101 / 4. 3.101 libswresample 2. 4.100 / 2. 4.100 libpostproc 54. 2.100 / 54. 2.100 Input #0, mpegts, from 'concat:temp1.ts|temp2.ts': Duration: 00:00:19.39, start: 1.400000, bitrate: 2207 kb/s Program 1 Metadata: service_name : Service01 service_provider: FFmpeg Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(pro gressive), 360x640, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc Stream #0:1[0x101](und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, mono, fltp, 65 kb/s Output #0, mp4, to 'output2.mp4': Metadata: encoder : Lavf57.66.104 Stream #0:0: Video: h264 (Main) ([33][0][0][0] / 0x0021), yuv420p(progressiv e), 360x640, q=2-31, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, mono, fltp, 65 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help [mp4 @ 000000000274c580] Non-monotonous DTS in output stream 0:1; previous: 7096 24, current: 708024; changing to 709625. This may result in incorrect timestamps in the output file. [mp4 @ 000000000274c580] Non-monotonous DTS in output stream 0:1; previous: 7096 25, current: 709048; changing to 709626. This may result in incorrect timestamps in the output file. frame= 1200 fps=0.0 q=-1.0 Lsize= 4733kB time=00:00:44.49 bitrate= 871.6kbits /s speed= 947x video:4381kB audio:308kB subtitle:0kB other streams:0kB global headers:1kB muxin g overhead: 0.953834%