Answers.Body: <h1>concat filter</h1>
  
  <p>Use the <a href="https://ffmpeg.org/ffmpeg-filters.html#concat" rel="nofollow noreferrer">concat filter</a>:</p>
  
  <pre><code>ffmpeg -i 1.mkv -i 2.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.mp4
  </code></pre>
  
  <p>In your case it should work without needing any additional filters because the inputs match parameters such as width, height, stream types, etc.</p>
  
  <h1>concat demxuer</h1>
  
  <p>Alternatively you could re-encode one segment to match parameters of the other then concatenate using the <a href="https://ffmpeg.org/ffmpeg-formats.html#concat-1" rel="nofollow noreferrer">concat demuxer</a>. Advantage is that one segment can avoid re-encoding unlike the concat filter. Disadvantage is that you have to properly match formats and parameters for it to work and it will require multiple steps.</p>
  
  <pre><code>ffmpeg -i 1.mkv -c:v libx264 -vf format=yuvj420p -c:a copy 1b.mp4
  ffmpeg -f concat -i inputs.txt -c copy output.mp4
  </code></pre>
  
  <p>Contents of <code>inputs.txt</code>:</p>
  
  <pre><code>file "1b.mp4"
  file "2.mp4"
  </code></pre>
  
  <p>Also see <a href="https://trac.ffmpeg.org/wiki/Concatenate" rel="nofollow noreferrer">FFmpeg Wiki: Concatenate</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-21T21:27:59.480Z
Answers.LastActivityDate: 2018-05-21T21:27:59.480Z
Answers.UserDisplayName: llogan
Body: <p>I would like to use ffmpeg, mencoder or still something free.</p>
  
  <p>I cannot concatenate two videos because of different video codecs:</p>
  
  <pre><code>$ mkvmerge -o merged.mkv 1.mkv \+ 2.mp4
  mkvmerge v19.0.0 ('Brave Captain') 64-bit
  '1.mkv': Using the demultiplexer for the format 'Matroska'.
  '2.mp4': Using the demultiplexer for the format 'QuickTime/MP4'.
  '1.mkv' track 0: Using the output module for the format 'MPEG-4'.
  '1.mkv' track 1: Using the output module for the format 'AAC'.
  '2.mp4' track 0: Using the output module for the format 'AVC/h.264'.
  '2.mp4' track 1: Using the output module for the format 'AAC'.
  No append mapping was given for the file no. 1 ('2.mp4'). A default mapping of 1:0:0:0,1:1:0:1 will be used instead. Please keep that in mind if mkvmerge aborts with an error message regarding invalid '--append-to' options.
  Error: The track number 0 from the file '2.mp4' cannot be appended to the track number 0 from the file '1.mkv'. The formats do not match.
  </code></pre>
  
  <p>Output of <code>ffmpeg -i 1.mkv -i 2.mp4</code> :</p>
  
  <pre><code>ffmpeg version 3.4.2-2 Copyright (c) 2000-2018 the FFmpeg developers
    built with gcc 7 (Ubuntu 7.3.0-16ubuntu2)
    configuration: --prefix=/usr --extra-version=2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
    libavutil      55. 78.100 / 55. 78.100
    libavcodec     57.107.100 / 57.107.100
    libavformat    57. 83.100 / 57. 83.100
    libavdevice    57. 10.100 / 57. 10.100
    libavfilter     6.107.100 /  6.107.100
    libavresample   3.  7.  0 /  3.  7.  0
    libswscale      4.  8.100 /  4.  8.100
    libswresample   2.  9.100 /  2.  9.100
    libpostproc    54.  7.100 / 54.  7.100
  Input #0, matroska,webm, from '1.mkv':
    Metadata:
      encoder         : libebml v1.3.5 + libmatroska v1.4.8
      creation_time   : 2018-05-21T03:04:06.000000Z
    Duration: 00:00:34.42, start: 0.000000, bitrate: 9455 kb/s
      Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 1k tbn, 60k tbc (default)
      Metadata:
        BPS             : 9319990
        BPS-eng         : 9319990
        DURATION        : 00:00:34.417000000
        DURATION-eng    : 00:00:34.417000000
        NUMBER_OF_FRAMES: 1758
        NUMBER_OF_FRAMES-eng: 1758
        NUMBER_OF_BYTES : 40095766
        NUMBER_OF_BYTES-eng: 40095766
        _STATISTICS_WRITING_APP: mkvmerge v19.0.0 ('Brave Captain') 64-bit
        _STATISTICS_WRITING_APP-eng: mkvmerge v19.0.0 ('Brave Captain') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2018-05-21 03:04:06
        _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-21 03:04:06
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
        _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp (default)
      Metadata:
        BPS             : 128301
        BPS-eng         : 128301
        DURATION        : 00:00:34.410000000
        DURATION-eng    : 00:00:34.410000000
        NUMBER_OF_FRAMES: 1613
        NUMBER_OF_FRAMES-eng: 1613
        NUMBER_OF_BYTES : 551855
        NUMBER_OF_BYTES-eng: 551855
        _STATISTICS_WRITING_APP: mkvmerge v19.0.0 ('Brave Captain') 64-bit
        _STATISTICS_WRITING_APP-eng: mkvmerge v19.0.0 ('Brave Captain') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2018-05-21 03:04:06
        _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-21 03:04:06
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
        _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
    Metadata:
      major_brand     : isom
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : Lavf57.83.100
    Duration: 00:00:55.74, start: 0.000000, bitrate: 44754 kb/s
      Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m/bt709/bt709), 1280x720, 44627 kb/s, SAR 1:1 DAR 16:9, 59.92 fps, 59.94 tbr, 16k tbn, 32k tbc (default)
      Metadata:
        handler_name    : VideoHandler
      Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
      Metadata:
        handler_name    : SoundHandler
  At least one output file must be specified
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-21T20:24:44.350Z
Comments.Text: @LordNeckbeard take a look, please.
Comments.UserDisplayName: R S
Tags: <ffmpeg><mp4><conversion><h.264><concatenation>
Title: How to concatenate MPEG-4 and AVC/h.264?
UserDisplayName: R S
ThreadText: # How to concatenate MPEG-4 and AVC/h.264?
  
  (Asked by: username_0 on 2018-05-21)
  
  I would like to use ffmpeg, mencoder or still something free.
  
  I cannot concatenate two videos because of different video codecs:
  
  ```
  $ mkvmerge -o merged.mkv 1.mkv \+ 2.mp4
  mkvmerge v19.0.0 ('Brave Captain') 64-bit
  '1.mkv': Using the demultiplexer for the format 'Matroska'.
  '2.mp4': Using the demultiplexer for the format 'QuickTime/MP4'.
  '1.mkv' track 0: Using the output module for the format 'MPEG-4'.
  '1.mkv' track 1: Using the output module for the format 'AAC'.
  '2.mp4' track 0: Using the output module for the format 'AVC/h.264'.
  '2.mp4' track 1: Using the output module for the format 'AAC'.
  No append mapping was given for the file no. 1 ('2.mp4'). A default mapping of 1:0:0:0,1:1:0:1 will be used instead. Please keep that in mind if mkvmerge aborts with an error message regarding invalid '--append-to' options.
  Error: The track number 0 from the file '2.mp4' cannot be appended to the track number 0 from the file '1.mkv'. The formats do not match.
  
  ```
  
  Output of `ffmpeg -i 1.mkv -i 2.mp4` :
  
  ```
  ffmpeg version 3.4.2-2 Copyright (c) 2000-2018 the FFmpeg developers
    built with gcc 7 (Ubuntu 7.3.0-16ubuntu2)
    configuration: --prefix=/usr --extra-version=2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
    libavutil      55. 78.100 / 55. 78.100
    libavcodec     57.107.100 / 57.107.100
    libavformat    57. 83.100 / 57. 83.100
    libavdevice    57. 10.100 / 57. 10.100
    libavfilter     6.107.100 /  6.107.100
    libavresample   3.  7.  0 /  3.  7.  0
    libswscale      4.  8.100 /  4.  8.100
    libswresample   2.  9.100 /  2.  9.100
    libpostproc    54.  7.100 / 54.  7.100
  Input #0, matroska,webm, from '1.mkv':
    Metadata:
      encoder         : libebml v1.3.5 + libmatroska v1.4.8
      creation_time   : 2018-05-21T03:04:06.000000Z
    Duration: 00:00:34.42, start: 0.000000, bitrate: 9455 kb/s
      Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 1k tbn, 60k tbc (default)
      Metadata:
        BPS             : 9319990
        BPS-eng         : 9319990
        DURATION        : 00:00:34.417000000
        DURATION-eng    : 00:00:34.417000000
        NUMBER_OF_FRAMES: 1758
        NUMBER_OF_FRAMES-eng: 1758
        NUMBER_OF_BYTES : 40095766
        NUMBER_OF_BYTES-eng: 40095766
        _STATISTICS_WRITING_APP: mkvmerge v19.0.0 ('Brave Captain') 64-bit
        _STATISTICS_WRITING_APP-eng: mkvmerge v19.0.0 ('Brave Captain') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2018-05-21 03:04:06
        _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-21 03:04:06
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
        _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp (default)
      Metadata:
        BPS             : 128301
        BPS-eng         : 128301
        DURATION        : 00:00:34.410000000
        DURATION-eng    : 00:00:34.410000000
        NUMBER_OF_FRAMES: 1613
        NUMBER_OF_FRAMES-eng: 1613
        NUMBER_OF_BYTES : 551855
        NUMBER_OF_BYTES-eng: 551855
        _STATISTICS_WRITING_APP: mkvmerge v19.0.0 ('Brave Captain') 64-bit
        _STATISTICS_WRITING_APP-eng: mkvmerge v19.0.0 ('Brave Captain') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2018-05-21 03:04:06
        _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-21 03:04:06
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
        _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
    Metadata:
      major_brand     : isom
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : Lavf57.83.100
    Duration: 00:00:55.74, start: 0.000000, bitrate: 44754 kb/s
      Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m/bt709/bt709), 1280x720, 44627 kb/s, SAR 1:1 DAR 16:9, 59.92 fps, 59.94 tbr, 16k tbn, 32k tbc (default)
      Metadata:
        handler_name    : VideoHandler
      Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
      Metadata:
        handler_name    : SoundHandler
  At least one output file must be specified
  
  ```
  
  **Tags:** ffmpeg, mp4, conversion, h.264, concatenation
  
  > **Comments:**
  > **username_0**: @LordNeckbeard take a look, please.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-21. Score: 2 | Accepted answer
  
  # concat filter
  
  Use the [concat filter](https://ffmpeg.org/ffmpeg-filters.html#concat):
  
  ```
  ffmpeg -i 1.mkv -i 2.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.mp4
  
  ```
  
  In your case it should work without needing any additional filters because the inputs match parameters such as width, height, stream types, etc.
  
  # concat demxuer
  
  Alternatively you could re-encode one segment to match parameters of the other then concatenate using the [concat demuxer](https://ffmpeg.org/ffmpeg-formats.html#concat-1). Advantage is that one segment can avoid re-encoding unlike the concat filter. Disadvantage is that you have to properly match formats and parameters for it to work and it will require multiple steps.
  
  ```
  ffmpeg -i 1.mkv -c:v libx264 -vf format=yuvj420p -c:a copy 1b.mp4
  ffmpeg -f concat -i inputs.txt -c copy output.mp4
  
  ```
  
  Contents of `inputs.txt`:
  
  ```
  file "1b.mp4"
  file "2.mp4"
  
  ```
  
  Also see [FFmpeg Wiki: Concatenate](https://trac.ffmpeg.org/wiki/Concatenate).
  
  
  ---
  
  