videoffmpegh.264

FFmpeg problems: encode/normalize then concat multiples videos


I want to:

I need the operations to be done in distinct 2 steps. I read a lot of posts but don't manage to find the correct solution.
The videos comes from different source, and so have different encoding settings.

To encode the videos I use the following command:

ffmpeg -i input.1.mp4 -vcodec libx264 -acodec aac -pix_fmt yuv420p-vf scale=1920:-2, drawtext=fontfile=./roboto.ttf: fontsize=40: text='ABC': x=(w-text_w)-w/20: y=(h-text_h)-h/20 -y export/out.1.mp4

To concat I tried with:

ffmpeg -safe 0 -f concat -i <(find ./export/ -type f -printf "file '$PWD/%p'\n" | sort) -c copy concat.out.mp4

But I have a lot of warning like that, and the result video is buggy:

Non-monotonous DTS in output stream 0:0; previous: 2362816, current: 1624899; changing to 2362817. This may result in incorrect timestamps in the output file.

A little part of encoded videos information:

  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4138 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #1:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 5241 kb/s, 30.04 fps, 30.04 tbr, 22500 tbn (default)
  Stream #2:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4770 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #3:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4144 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #4:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 7547 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #5:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 10784 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #6:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 7165 kb/s, 30.04 fps, 30.04 tbr, 22500 tbn (default)
  Stream #7:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 3150 kb/s, 30.04 fps, 30.04 tbr, 22500 tbn (default)
  Stream #8:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 8996 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #9:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4673 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #10:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080, 3625 kb/s, 29 fps, 29 tbr, 14848 tbn (default)
  Stream #11:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080, 33163 kb/s, 29 fps, 29 tbr, 14848 tbn (default)
  Stream #12:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4624 kb/s, 29 fps, 29 tbr, 14848 tbn (default)
  Stream #13:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4034 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #14:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 6519 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #15:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 1816 kb/s, 30 fps, 30 tbr, 15360 tbn (default)

  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #4:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #5:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #6:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #7:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #8:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #9:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #10:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
  Stream #11:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
  Stream #12:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
  Stream #13:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #14:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #15:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)

I also tried:

ffmpeg -i 091245.mp4 -i 115405.mp4 -i 160743.mp4 -i 081024.mp4 -i 172500.mp4 -i 101658.mp4 -i 115904.mp4 -i 170035.mp4 -i 004129.mp4 -i 181930.mp4 -i 092100_01.mp4 -i 132726_01.mp4 -i 153927_01~2.mp4 -i 123552.mp4 -i 075329.mp4 -i 124002.mp4 -filter_complex "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a] [3:v] [3:a] [4:v] [4:a] [5:v] [5:a] [6:v] [6:a] [7:v] [7:a] [8:v] [8:a] [9:v] [9:a] [10:v] [10:a] [11:v] [11:a] [12:v] [12:a] [13:v] [13:a] [14:v] [14:a] [15:v] [15:a] concat=n=16:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" concat.out.mkv

which work fine but re-encode all the videos.

Is there a better way to normalize output video of the first encoding to be able to easily concat them ?


Solution

  • Attributes must be the same for proper concatenation with the concat demuxer.

    Make them the same in your encoding command:

    ffmpeg -i input.1.mp4 -vcodec libx264 -acodec aac -vf fps=30,scale=1920:-2, drawtext=fontfile=./roboto.ttf: fontsize=40: text='ABC': x=(w-text_w)-w/20: y=(h-text_h)-h/20,format=yuv420p -ar 48000 -y export/out.1.mp4