Cannot concatenate videos ffmpeg

bashconcatenationffmpegmpegvideo

I have a bitmap that I would like to concatenate to the front of many videos as a sort of title screen or disclaimer screen.

I try to turn it into a video with the same attributes as the rest of the video. So first I introspect the video:

ffmpeg version 2.2.1 Copyright (c) 2000-2014 the FFmpeg developers
  built on Apr 11 2014 22:50:38 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 66.100 / 52. 66.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  2.100 /  4.  2.100
  libavresample   1.  2.  0 /  1.  2.  0
  libswscale      2.  5.102 /  2.  5.102
  libswresample   0. 18.100 /  0. 18.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'EO1.mp4':
  Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
creation_time   : 1970-01-01 00:00:00
encoder         : Lavf52.78.3
  Duration: 00:00:17.77, start: 0.000000, bitrate: 582 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 584x328 [SAR 1:1 DAR 73:41], 512 kb/s, 23.98 fps, 23.98 tbr, 1199 tbn, 47.96 tbc (default)
Metadata:
  creation_time   : 1970-01-01 00:00:00
  handler_name    : VideoHandler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
Metadata:
  creation_time   : 1970-01-01 00:00:00
  handler_name    : SoundHandler

Then I try and create a similar file:

/usr/local/Cellar/ffmpeg/2.2.1/bin/ffmpeg -y -loop 1 -i Disclaimer.png -c:v libx264 -r 23.98 -t 5 -pix_fmt yuv420p -profile:v main disclaimer.mp4

It seems to work okay. The video plays I would expect it to. The attributes turn out very similar. Here is a diff:

< Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'disclaimer.mp4':
---
> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'EO1.mp4':
18,20c18,21
<     encoder         : Lavf55.33.100
<   Duration: 00:00:05.01, start: 0.000000, bitrate: 21 kb/s
<     Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 584x328 [SAR 1:1 DAR 73:41], 17 kb/s, 23.98 fps, 23.98 tbr, 19184 tbn, 47.96 tbc (default)
---
>     creation_time   : 1970-01-01 00:00:00
>     encoder         : Lavf52.78.3
>   Duration: 00:00:17.77, start: 0.000000, bitrate: 582 kb/s
>     Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 584x328 [SAR 1:1 DAR 73:41], 512 kb/s, 23.98 fps, 23.98 tbr, 1199 tbn, 47.96 tbc (default)
21a23
22a25,28
>     Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
>     Metadata:
>       handler_name    : SoundHandler

But when I try to concatenate, I get errors.

> $ cat temporary.txt 

    file disclaimer.mp4
    file EO1.mp4

/usr/local/Cellar/ffmpeg/2.2.1/bin/ffmpeg -y -f concat -i temporary.txt -c copy output.mp4

[concat @ 0x7fd880806600] Estimating duration from bitrate, this may be inaccurate
Input #0, concat, from 'temporary.txt':
  Duration: 00:00:00.02, start: 0.000000, bitrate: 17 kb/s
Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 584x328 [SAR 1:1 DAR 73:41], 17 kb/s, 23.98 fps, 23.98 tbr, 19184 tbn, 47.96 tbc
Output #0, mp4, to 'output.mp4':
  Metadata:
encoder         : Lavf55.33.100
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 584x328 [SAR 1:1 DAR 73:41], q=2-31, 17 kb/s, 23.98 fps, 19184 tbn, 19184 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x7fd880829a00] Non-monotonous DTS in output stream 0:0; previous: 93600, current: 5951; changing to 93601. This may result in incorrect timestamps in the output file.
[concat @ 0x7fd880806600] Invalid stream index 1
[mp4 @ 0x7fd880829a00] Non-monotonous DTS in output stream 0:0; previous: 93601, current: 6001; changing to 93602. This may result in incorrect timestamps in the output file.
[concat @ 0x7fd880806600] Invalid stream index 1
[mp4 @ 0x7fd880829a00] Non-monotonous DTS in output stream 0:0; previous: 93602, current: 6051; changing to 93603. This may result in incorrect timestamps in the output file.

frame=  546 fps=0.0 q=-1.0 Lsize=    1127kB time=00:00:04.90 bitrate=1882.9kbits/s    
video:1123kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead 0.349865%

The output looks like it only has my disclaimer file in it, not the rest of the video.

I'm also confused why it feels like it needs to "estimate" anything. It knows the input FPS and input durations. I'm not sure if this is the problem or not. Maybe its just a bug.

My other option is to use the "concat filter" but that's a lossy transcode, right? I'd rather have the second video be exactly the same after the concatenation as it was before.

Edit: ended up trying the concat "protocol" which is the third option. The docs discourage its use but it worked better than the other two (Concat demuxer and concat filter).

Best Answer

I know this is probably not the answer you are looking for but why not use video editing software to do this? Video editing can take different frame rates, codecs, etc and combine them into the target format and it will be playable by ordinary software. A number of programs offer batch mode if you need to add the disclaimer to a bunch of videos.

There are free open source video editors and proprietary. I think what you are doing is way outside of what concatenate was designed for which is basically combine files of the same type and format.