ffmpeg – concat 2 mp4 files results in bad output file-Collection of common programming errors


  • DevDewboy

    I generated 2 mp4 files – a 5 second intro file which is created by the script below and the main video about 1 minute long is created by screen-cast-omatic both in mp4 format. When I attempt to concat using the “ffmpeg -f concat -i mylist.txt -c copy output” method, it produces an output file where the intro file plays fine. Then the main video plays; the audio is fine but the video is messed up where it displays garbled video on top.

    Using the “ffmpeg -i “concat:input1.mpg|input2.mpg|input3.mpg” -c copy output.mpg” method, the output is a video which is not complete. I did not include any script output on this.

    Can some check this out and offer a recommendation?

    The follow is the script and out put for the first method of concat:

    # intro_vid.cfg
    #!/bin/bash
    INPUTFILE="intro_vid.mp4"
    LOGO=intro".png"
    LOGOLENGTH="5"
    SPEAKER="Jason"
    TITLE="Basic SSH Video"
    DATE="October 28, 2013"
    SCENESTART="00:00:01"
    SCENEDURATION="00:00:05"
    OUTPUTFILE="intro_vid_final"
    

    mylist.txt

    # Comment
    file './intro_vid_final-intro.mp4'
    file './ssh_main.mp4'
    

    VideoEditIntro.sh #!/bin/bash

    PARAMFILE=${1}
    
    . ${PARAMFILE}
    
    extractVideo () {
      # Split the portion of the video that we want to work on directly from the source file
      # converting the video to frame files one PNG file per frame and
      # splitting the audio to to an mp3 file
      rm -fr "${OUTPUTFILE}-frames"
      mkdir -p "${OUTPUTFILE}-frames"
    
      ./ffmpeg -threads 4 \
         -i ${INPUTFILE} -ss ${SCENESTART} -t ${SCENEDURATION} \
         -f image2 -y "${OUTPUTFILE}-frames"/frame%d.png \
         -c:a copy -y "${OUTPUTFILE}.m4a"
    }
    
    createIntro () {
      # Create the introduction image by merging the logo file with the titles for the video
      convert ${LOGO} -gravity Center -font DejaVu-Sans-Book \
         -pointsize 20 -fill gray -draw "text 1,21 'University'" \
         -fill white -draw "text 0,20 'University'" \
         -pointsize 50 -fill gray -draw "text 2,72 '${SPEAKER}'" \
         -fill white -draw "text 0,70 '${SPEAKER}'" \
         -pointsize 30 -fill gray -draw "text 1,131 '${TITLE}'" \
         -fill white -draw "text 0,130 '${TITLE}'" \
         -pointsize 20 -fill gray -draw "text 1,171 '${DATE}'" \
         -fill white -draw "text 0,170 '${DATE}'" \
         "${OUTPUTFILE}-intro.png"
    
      # Create still video from the introduction image and silence
    
      ./ffmpeg -ar 48000 -t ${LOGOLENGTH} -f s16le -ac 2 \
           -channel_layout stereo -c:a pcm_s16le \
           -i /dev/zero -ab 64K -c:a libvo_aacenc -y silence.m4a
    
      ./ffmpeg -loop 1 -i "${OUTPUTFILE}-intro.png" -q:v 1 \
           -r 29.97 -t ${LOGOLENGTH} -y -f MP4 -pix_fmt yuv420p "${OUTPUTFILE}-logo1.mp4"
    
      ./ffmpeg -i "${OUTPUTFILE}-logo1.mp4" -i "silence.m4a" \
           -c:v copy -c:a copy -map 0:0 -map 1:0 -threads 4 \
           -y -f MP4 "${OUTPUTFILE}-intro.mp4"
    
    }
    
    reasembleVideo () {
      # Merge the modified frames onto the original frames
      # Reassembles the modified frames and the audio into an output video
    #  ./ffmpeg -threads 4 \
    #           -i concat:"${OUTPUTFILE}-intro.mp4"\|"ssh_main.mp4" \
    #           -r 29.97 -y "${OUTPUTFILE}-final_ssh.mp4"
       ./ffmpeg -f concat -i mylist.txt -codec copy "${OUTPUTFILE}-final_ssh.mp4"
    
    
    }
    
    
    
    # These functions do not depend on each other. They can be executed in parallel
    extractVideo &
    echo "CREATE INTRO ROUTINE"
    createIntro &
    wait
    reasembleVideo
    
    # Done!
    echo "Done!"
    

    The following is the processing output:

    iavideo@colfax:~$ cd video/wip2/
    iavideo@colfax:~/video/wip2$ cd video/wip2/./VideoEditIntro.sh intro_vid.cfg 
    CREATE INTRO ROUTINE
    ffmpeg version N-57401-ga443b97 Copyright (c) 2000-2013 the FFmpeg developers
      built on Oct 25 2013 05:34:36 with gcc 4.6 (Debian 4.6.3-1)
      configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
      libavutil      52. 47.101 / 52. 47.101
      libavcodec     55. 38.101 / 55. 38.101
      libavformat    55. 19.104 / 55. 19.104
      libavdevice    55.  5.100 / 55.  5.100
      libavfilter     3. 89.100 /  3. 89.100
      libswscale      2.  5.101 /  2.  5.101
      libswresample   0. 17.104 /  0. 17.104
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'intro_vid.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        creation_time   : 1970-01-01 00:00:00
      Duration: 00:00:07.00, start: 0.000000, bitrate: 116 kb/s
        Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1720x752, 46 kb/s, 10 fps, 10 tbr, 10 tbn, 20 tbc (default)
        Metadata:
          creation_time   : 1970-01-01 00:00:00
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 75 kb/s (default)
        Metadata:
          creation_time   : 1970-01-01 00:00:00
          handler_name    : SoundHandler
    [libx264 @ 0x3a6c140] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
    [libx264 @ 0x3a6c140] profile High, level 3.2
    [libx264 @ 0x3a6c140] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, image2, to 'intro_vid_final-frames/frame%d.png':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf55.19.104
        Stream #0:0(und): Video: png, rgb24, 1720x752, q=2-31, 200 kb/s, 90k tbn, 10 tbc (default)
        Metadata:
          creation_time   : 1970-01-01 00:00:00
          handler_name    : VideoHandler
    Output #1, ipod, to 'intro_vid_final.m4a':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf55.19.104
        Stream #1:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1720x752, q=-1--1, 10240 tbn, 10 tbc (default)
        Metadata:
          creation_time   : 1970-01-01 00:00:00
          handler_name    : VideoHandler
        Stream #1:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, 75 kb/s (default)
        Metadata:
          creation_time   : 1970-01-01 00:00:00
          handler_name    : SoundHandler
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 -> png)
      Stream #0:0 -> #1:0 (h264 -> libx264)
      Stream #0:1 -> #1:1 (copy)
    Press [q] to stop, [?] for help
    ffmpeg version N-57401-ga443b97 Copyright (c) 2000-2013 the FFmpeg developers
      built on Oct 25 2013 05:34:36 with gcc 4.6 (Debian 4.6.3-1)
      configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
      libavutil      52. 47.101 / 52. 47.101
      libavcodec     55. 38.101 / 55. 38.101
      libavformat    55. 19.104 / 55. 19.104
      libavdevice    55.  5.100 / 55.  5.100
      libavfilter     3. 89.100 /  3. 89.100
      libswscale      2.  5.101 /  2.  5.101
      libswresample   0. 17.104 /  0. 17.104
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, s16le, from '/dev/zero':
      Duration: N/A, bitrate: 1536 kb/s
        Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Output #0, ipod, to 'silence.m4a':
      Metadata:
        encoder         : Lavf55.19.104
        Stream #0:0: Audio: aac (libvo_aacenc) (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 64 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (pcm_s16le -> libvo_aacenc)
    Press [q] to stop, [?] for help
    size=      41kB time=00:00:05.00 bitrate=  67.1kbits/s    
    
    video:0kB audio:39kB subtitle:0 global headers:0kB muxing overhead 4.190769%
    ffmpeg version N-57401-ga443b97 Copyright (c) 2000-2013 the FFmpeg developers
      built on Oct 25 2013 05:34:36 with gcc 4.6 (Debian 4.6.3-1)
      configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
      libavutil      52. 47.101 / 52. 47.101
      libavcodec     55. 38.101 / 55. 38.101
      libavformat    55. 19.104 / 55. 19.104
      libavdevice    55.  5.100 / 55.  5.100
      libavfilter     3. 89.100 /  3. 89.100
      libswscale      2.  5.101 /  2.  5.101
      libswresample   0. 17.104 /  0. 17.104
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, image2, from 'intro_vid_final-intro.png':
      Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: png, rgba, 1720x752, 25 fps, 25 tbr, 25 tbn, 25 tbc
    [libx264 @ 0x32d6860] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
    [libx264 @ 0x32d6860] profile High, level 3.2
    [libx264 @ 0x32d6860] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'intro_vid_final-logo1.mp4':
      Metadata:
        encoder         : Lavf55.19.104
        Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1720x752, q=-1--1, 11988 tbn, 29.97 tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (png -> libx264)
    Press [q] to stop, [?] for help
    frame=   32 fps=0.0 q=0.0 q=0.0 size=N/A time=00:00:04.43 bitrate=N/A    
    frame=   41 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=7 drop=0    
    frame=   50 fps= 49 q=0.0 q=25.0 size=N/A time=00:00:06.10 bitrate=N/A    
    frame=   73 fps= 72 q=29.0 size=       8kB time=00:00:00.70 bitrate=  97.6kbits/s dup=12 drop=0    
    frame=   50 fps= 33 q=0.0 Lq=-1.0 size=N/A time=00:00:06.80 bitrate=N/A    
    
    video:608kB audio:57kB subtitle:0 global headers:0kB muxing overhead -100.003232%
    [libx264 @ 0x3a6c140] frame I:1     Avg QP: 6.68  size:  2396
    [libx264 @ 0x3a6c140] frame P:18    Avg QP: 7.26  size:   583
    [libx264 @ 0x3a6c140] frame B:51    Avg QP: 9.71  size:    74
    [libx264 @ 0x3a6c140] consecutive B-frames:  2.9%  0.0%  0.0% 97.1%
    [libx264 @ 0x3a6c140] mb I  I16..4: 99.4%  0.0%  0.6%
    [libx264 @ 0x3a6c140] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.3%  0.1%  0.1%  0.0%  0.0%    skip:99.6%
    [libx264 @ 0x3a6c140] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.1%  0.0%  0.0%  direct: 0.0%  skip:99.9%  L0:53.1% L1:46.8% BI: 0.1%
    [libx264 @ 0x3a6c140] 8x8 transform intra:0.0% inter:10.8%
    [libx264 @ 0x3a6c140] coded y,uvDC,uvAC intra: 0.4% 0.0% 0.0% inter: 0.1% 0.0% 0.0%
    [libx264 @ 0x3a6c140] i16 v,h,dc,p: 98%  0%  2%  0%
    [libx264 @ 0x3a6c140] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 28% 26%  2%  5%  4% 10%  3%  6%
    [libx264 @ 0x3a6c140] i8c dc,h,v,p: 100%  0%  0%  0%
    [libx264 @ 0x3a6c140] Weighted P-Frames: Y:44.4% UV:0.0%
    [libx264 @ 0x3a6c140] ref P L0: 72.8% 11.4% 15.1%  0.2%  0.5%
    [libx264 @ 0x3a6c140] ref B L0: 86.6% 13.4%
    [libx264 @ 0x3a6c140] kb/s:19.03
    frame=  124 fps= 82 q=29.0 size=      11kB time=00:00:02.40 bitrate=  37.0kbits/s dup=20 drop=0    
    frame=  150 fps= 77 q=-1.0 Lsize=      17kB time=00:00:04.93 bitrate=  28.3kbits/s dup=25 drop=0    
    
    video:14kB audio:0kB subtitle:0 global headers:0kB muxing overhead 17.449439%
    [libx264 @ 0x32d6860] frame I:1     Avg QP:15.18  size:  6574
    [libx264 @ 0x32d6860] frame P:38    Avg QP:10.44  size:    59
    [libx264 @ 0x32d6860] frame B:111   Avg QP:13.67  size:    48
    [libx264 @ 0x32d6860] consecutive B-frames:  1.3%  0.0%  0.0% 98.7%
    [libx264 @ 0x32d6860] mb I  I16..4: 97.4%  0.0%  2.6%
    [libx264 @ 0x32d6860] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:100.0%
    [libx264 @ 0x32d6860] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%  L0:69.8% L1:30.2% BI: 0.0%
    [libx264 @ 0x32d6860] 8x8 transform intra:0.0% inter:12.5%
    [libx264 @ 0x32d6860] coded y,uvDC,uvAC intra: 1.7% 0.0% 0.0% inter: 0.0% 0.0% 0.0%
    [libx264 @ 0x32d6860] i16 v,h,dc,p: 98%  0%  2%  0%
    [libx264 @ 0x32d6860] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 47% 20% 14%  2%  2%  3%  4%  3%  4%
    [libx264 @ 0x32d6860] i8c dc,h,v,p: 100%  0%  0%  0%
    [libx264 @ 0x32d6860] Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 0x32d6860] ref B L0:  2.7% 97.3%
    [libx264 @ 0x32d6860] kb/s:22.63
    ffmpeg version N-57401-ga443b97 Copyright (c) 2000-2013 the FFmpeg developers
      built on Oct 25 2013 05:34:36 with gcc 4.6 (Debian 4.6.3-1)
      configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
      libavutil      52. 47.101 / 52. 47.101
      libavcodec     55. 38.101 / 55. 38.101
      libavformat    55. 19.104 / 55. 19.104
      libavdevice    55.  5.100 / 55.  5.100
      libavfilter     3. 89.100 /  3. 89.100
      libswscale      2.  5.101 /  2.  5.101
      libswresample   0. 17.104 /  0. 17.104
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'intro_vid_final-logo1.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf55.19.104
      Duration: 00:00:05.01, start: 0.000000, bitrate: 27 kb/s
        Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1720x752, 23 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
        Metadata:
          handler_name    : VideoHandler
    Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'silence.m4a':
      Metadata:
        major_brand     : M4A 
        minor_version   : 512
        compatible_brands: isomiso2
        encoder         : Lavf55.19.104
      Duration: 00:00:05.03, start: 0.033333, bitrate: 66 kb/s
        Stream #1:0(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    Output #0, mp4, to 'intro_vid_final-intro.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf55.19.104
        Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1720x752, q=2-31, 23 kb/s, 29.97 fps, 11988 tbn, 11988 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 64 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #1:0 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    frame=  150 fps=0.0 q=-1.0 Lsize=      60kB time=00:00:05.03 bitrate=  98.4kbits/s    
    
    video:14kB audio:39kB subtitle:0 global headers:0kB muxing overhead 12.325164%
    ffmpeg version N-57401-ga443b97 Copyright (c) 2000-2013 the FFmpeg developers
      built on Oct 25 2013 05:34:36 with gcc 4.6 (Debian 4.6.3-1)
      configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
      libavutil      52. 47.101 / 52. 47.101
      libavcodec     55. 38.101 / 55. 38.101
      libavformat    55. 19.104 / 55. 19.104
      libavdevice    55.  5.100 / 55.  5.100
      libavfilter     3. 89.100 /  3. 89.100
      libswscale      2.  5.101 /  2.  5.101
      libswresample   0. 17.104 /  0. 17.104
      libpostproc    52.  3.100 / 52.  3.100
    [concat @ 0x2497f80] Estimating duration from bitrate, this may be inaccurate
    Input #0, concat, from 'mylist.txt':
      Duration: 00:00:00.01, start: 0.000000, bitrate: 86 kb/s
        Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1720x752, 23 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc
        Stream #0:1: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 63 kb/s
    Output #0, mp4, to 'intro_vid_final-final_ssh.mp4':
      Metadata:
        encoder         : Lavf55.19.104
        Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1720x752, q=2-31, 23 kb/s, 29.97 fps, 11988 tbn, 11988 tbc
        Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 63 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:0; previous: 58800, current: 51; changing to 58801. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:1; previous: 240640, current: 223455; changing to 240641. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:1; previous: 240641, current: 224479; changing to 240642. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:1; previous: 240642, current: 225503; changing to 240643. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:1; previous: 240643, current: 226527; changing to 240644. This may result in incorrect timestamps in the output file.
    
    ... about 400 similar line removed
    
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:0; previous: 59305, current: 556; changing to 59306. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:0; previous: 59306, current: 557; changing to 59307. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:0; previous: 59307, current: 558; changing to 59308. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:0; previous: 59308, current: 559; changing to 59309. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x24a7a00] Non-monotonous DTS in output stream 0:0; previous: 59309, current: 560; changing to 59310. This may result in incorrect timestamps in the output file.
    frame=  660 fps=0.0 q=-1.0 Lsize=    2287kB time=00:00:50.99 bitrate= 367.4kbits/s    
    
    video:1763kB audio:507kB subtitle:0 global headers:0kB muxing overhead 0.759429%
    Done!
    iavideo@colfax:~/video/wip2$ 
    

    I tried using memcoder to concatenate the 2 videos and I get a problem there. I suspect it has to do with the codec or fps/bit rates etc, so I tweaked the script to 10 fps on both videos and here is memcoders output:

    iavideo@colfax:~/video/wip2$ mencoder -oac pcm -ovc copy -o intro_vid_final_ssh_2.mp4 intro_vid_final-intro.mp4 ssh_main.mp4
    MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team
    
    WARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.
    success: format: 0  data: 0x0 - 0xd26c
    libavformat version 53.21.1 (external)
    Mismatching header version 53.19.0
    libavformat file format detected.
    [lavf] stream 0: video (h264), -vid 0
    [lavf] stream 1: audio (aac), -aid 0, -alang und
    VIDEO:  [H264]  1720x752  24bpp  10.000 fps   17.7 kbps ( 2.2 kbyte/s)
    [V] filefmt:44  fourcc:0x34363248  size:1720x752  fps:10.000  ftime:=0.1000
    ==========================================================================
    Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
    libavcodec version 53.35.0 (external)
    Mismatching header version 53.32.2
    AUDIO: 44100 Hz, 1 ch, s16le, 63.3 kbit/8.97% (ratio: 7914->88200)
    Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
    ==========================================================================
    videocodec: framecopy (1720x752 24bpp fourcc=34363248)
    Writing header...
    ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
    Writing header...
    ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
    Pos:   4.9s     50f (100%)  0.00fps Trem:   0min   0mb  A-V:0.063 [18:705]
    success: format: 0  data: 0x0 - 0x22f78d
    libavformat file format detected.
    [lavf] stream 0: video (h264), -vid 0
    [lavf] stream 1: audio (aac), -aid 0, -alang und
    VIDEO:  [H264]  1720x752  24bpp  10.000 fps  280.8 kbps (34.3 kbyte/s)
    [V] filefmt:44  fourcc:0x34363248  size:1720x752  fps:10.000  ftime:=0.1000
    ==========================================================================
    Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
    AUDIO: 44100 Hz, 1 ch, s16le, 75.9 kbit/10.76% (ratio: 9493->88200)
    Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
    ==========================================================================
    videocodec: framecopy (1720x752 24bpp fourcc=34363248)
    videocodec: framecopy (1720x752 24bpp fourcc=34363248)
    
    All video files must have identical fps, resolution, and codec for -ovc copy.
    
    Exiting...
    iavideo@colfax:~/video/wip2$
    

    Use MP4Box I get the error that it can’t concatenate the files because the AVCs are different. Here is the output:

    iavideo@colfax:~/video/wip2$ MP4Box -cat intro_vid_final-intro.mp4 -cat ssh_main.mp4 intro_vid_final_ssh_3.mp4
    Appending file intro_vid_final-intro.mp4
    Cannot concatenate files: Different AVC Profile Indication between source (100) and destination (66)
    Appending file ssh_main.mp4
    Saving intro_vid_final_ssh_3.mp4: 0.500 secs Interleaving
    iavideo@colfax:~/video/wip2$
    

  • Rajib

    Do not use the concat demuxer or concat protocol when the source files may have different codecs or other differences. Use the concat filter. That will re-encode all, but will produce stable results.

    ffmpeg -i title -i main -y -filter_complex '[0:0] setsar=1/1[sarfix];[sarfix] [1:0] concat=n=2:v=1:a=0 [v]' -map '[v]' -pass 1 -strict -2 -an -vcodec libx264 -pix_fmt yuv420p -aspect 16:9 -threads 4 -b:v 2400k -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 1 -trellis 0 -refs 1 -bf 3 -b_strategy 2 -coder 1 -me_range 16 -g 250 -keyint_min 75 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 output.mp4  
    
    ffmpeg -i title -i main -y -filter_complex '[0:0] setsar=1/1[sarfix];[sarfix] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1[v] [a]' -map '[v]' -map '[a]' -strict -2 -acodec aac -b:a 128k -pass 2 -vcodec libx264 -pix_fmt yuv420p -aspect 16:9 -threads 4 -b:v 2400k -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -mixed-refs 1 -subq 6 -trellis 1 -refs 5 -bf 3 -b_strategy 2 -coder 1 -me_range 16 -g 250 -keyint_min 75 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 output.mp4  
    

    This shows a two pass solution. In pass 1 audio is ignored. It does not matter how your two sections input are produced.