FFMPEG recortando videos en una configuración de CPU baja de Docker

FFMPEG recortando videos en una configuración de CPU baja de Docker

Así que he estado intentando combinar varios mp4 dentro de un contenedor acoplable que ejecuta Debian Stretch. Tengo la limitación de no poder escribir el archivo mp4 de salida en el disco, por lo que necesito canalizar la salida del archivo ffmpeg a la salida estándar. He estado usando el siguiente comando.

$ffmpeg -i https://clips-media-assets.twitch.tv/214592710.mp4 -i https://clips-media-assets.twitch.tv/214731012.mp4 -i https://clips-media-assets.twitch.tv/28082606352-offset-2786.mp4 -i https://clips-media-assets.twitch.tv/214777342.mp4 -i https://clips-media-assets.twitch.tv/214638267.mp4 -i https://clips-media-assets.twitch.tv/214636156.mp4 -i https://clips-media-assets.twitch.tv/214804499.mp4 -i https://clips-media-assets.twitch.tv/214826823.mp4 -i https://clips-media-assets.twitch.tv/214741267.mp4 -i https://clips-media-assets.twitch.tv/214575427.mp4 -filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0] [2:v:0] [2:a:0] [3:v:0] [3:a:0] [4:v:0] [4:a:0] [5:v:0] [5:a:0] [6:v:0] [6:a:0] [7:v:0] [7:a:0] [8:v:0] [8:a:0] [9:v:0] [9:a:0] concat=n=10:v=1:a=1 [v] [a]" -map [v] -map [a] -frag_duration 3600 -f mp4 -

Esto da como resultado que las partes esperadas del video de salida se recorten a unos pocos segundos.

Aquí está la salida de ffmpegs que leí de stdErr donde el recuento de CPU de Docker es 1 con 2 GB de RAM.

ffmpeg version 3.4.2-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
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
libswscale      4.  8.100 /  4.  8.100
libswresample   2.  9.100 /  2.  9.100
libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214592710.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:00:21.47, start: 0.000000, bitrate: 3678 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 3501 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 163 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214731012.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:01:00.01, start: 0.000000, bitrate: 8782 kb/s
  Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 8606 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 164 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/28082606352-offset-2786.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:00:30.00, start: 0.000000, bitrate: 6181 kb/s
  Stream #2:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 6002 kb/s, 60 fps, 60 tbr, 90k tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 163 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214777342.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:00:27.67, start: 0.000000, bitrate: 5891 kb/s
  Stream #3:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 5715 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #3:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 164 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214638267.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:00:46.43, start: 0.000000, bitrate: 10449 kb/s
  Stream #4:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 10273 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #4:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 163 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #5, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214636156.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:00:07.75, start: 0.000000, bitrate: 8070 kb/s
  Stream #5:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 7892 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #5:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 163 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #6, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214804499.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:01:00.01, start: 0.000000, bitrate: 6529 kb/s
  Stream #6:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 6354 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #6:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 163 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #7, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214826823.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:00:07.68, start: 0.000000, bitrate: 3713 kb/s
  Stream #7:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 3536 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #7:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 163 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #8, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214741267.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:00:07.19, start: 0.000000, bitrate: 5785 kb/s
  Stream #8:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 5610 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #8:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 165 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Input #9, mov,mp4,m4a,3gp,3g2,mj2, from 'https://clips-media-assets.twitch.tv/214575427.mp4':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.71.100
Duration: 00:00:51.01, start: 0.000000, bitrate: 3874 kb/s
  Stream #9:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720, 3698 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  Stream #9:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 164 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
Stream mapping:
Stream #0:0 (h264) -> concat:in0:v0
Stream #0:1 (aac) -> concat:in0:a0
Stream #1:0 (h264) -> concat:in1:v0
Stream #1:1 (aac) -> concat:in1:a0
Stream #2:0 (h264) -> concat:in2:v0
Stream #2:1 (aac) -> concat:in2:a0
Stream #3:0 (h264) -> concat:in3:v0
Stream #3:1 (aac) -> concat:in3:a0
Stream #4:0 (h264) -> concat:in4:v0
Stream #4:1 (aac) -> concat:in4:a0
Stream #5:0 (h264) -> concat:in5:v0
Stream #5:1 (aac) -> concat:in5:a0
Stream #6:0 (h264) -> concat:in6:v0
Stream #6:1 (aac) -> concat:in6:a0
Stream #7:0 (h264) -> concat:in7:v0
Stream #7:1 (aac) -> concat:in7:a0
Stream #8:0 (h264) -> concat:in8:v0
Stream #8:1 (aac) -> concat:in8:a0
Stream #9:0 (h264) -> concat:in9:v0
Stream #9:1 (aac) -> concat:in9:a0
concat:out:v0 -> Stream #0:0 (libx264)
concat:out:a0 -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[libx264 @ 0x88d3640] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x88d3640] profile High, level 3.2
[libx264 @ 0x88d3640] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=1 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 'pipe:':
Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf57.83.100
  Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuvj420p(pc, progressive), 1280x720, q=-1--1, 60 fps, 15360 tbn, 60 tbc (default)
  Metadata:
    encoder         : Lavc57.107.100 libx264
  Side data:
    cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
  Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Metadata:
    encoder         : Lavc57.107.100 aac
frame= 2320 fps= 20 q=31.0 size=   25147kB time=00:00:38.50 bitrate=5318.2kbits/s dup=1 drop=0 speed=0.334x
frame= 4560 fps= 17 q=31.0 size=   62654kB time=00:01:15.83 bitrate=6768.0kbits/s dup=1 drop=0 speed=0.275x
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x6109940] stream 1, offset 0x1187c5: partial filets/s dup=2 drop=0 speed=0.315x    speed=0.275x
[h264 @ 0x69b8980] Invalid NAL unit size (10904 > 8072).39kB time=00:01:52.43 bitrate=5795.4kbits/s dup=2 drop=0 speed=0.315x
[h264 @ 0x69b8980] Error splitting the input into NAL units.
Error while decoding stream #3:0: Invalid data found when processing input
https://clips-media-assets.twitch.tv/214777342.mp4: Invalid data found when processing input
  Last message repeated 2 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x69c01c0] stream 1, offset 0x124bed: partial filets/s dup=4 drop=0 speed=0.314x    0 speed=0.315x
[h264 @ 0x69e5220] Invalid NAL unit size (40844 > 37063).8kB time=00:01:53.36 bitrate=5817.7kbits/s dup=4 drop=0 speed=0.314x
[h264 @ 0x69e5220] Error splitting the input into NAL units.
Error while decoding stream #4:0: Invalid data found when processing input
https://clips-media-assets.twitch.tv/214638267.mp4: Invalid data found when processing input
  Last message repeated 2 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x6e34300] stream 1, offset 0x134e04: partial filets/s dup=4 drop=0 speed=0.314x    0 speed=0.314x
[h264 @ 0x6e936e0] Invalid NAL unit size (3219 > 2887).
[h264 @ 0x6e936e0] Error splitting the input into NAL units.
Error while decoding stream #5:0: Invalid data found when processing input
https://clips-media-assets.twitch.tv/214636156.mp4: Invalid data found when processing input
  Last message repeated 2 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x6e65f80] stream 1, offset 0x1411c1: partial filets/s dup=5 drop=0 speed=0.314x    0 speed=0.314x
[h264 @ 0x72c63c0] Invalid NAL unit size (5000 > 3708).841kB time=00:01:55.87 bitrate=5856.6kbits/s dup=5 drop=0 speed=0.314x
[h264 @ 0x72c63c0] Error splitting the input into NAL units.
Error while decoding stream #6:0: Invalid data found when processing input
https://clips-media-assets.twitch.tv/214804499.mp4: Invalid data found when processing input
  Last message repeated 2 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x779e0e0] stream 1, offset 0x134b57: partial filets/s dup=6 drop=0 speed=0.316x    0 speed=0.314x
[h264 @ 0x7bec920] Invalid NAL unit size (18581 > 8590).18kB time=00:02:05.68 bitrate=5698.0kbits/s dup=6 drop=0 speed=0.316x
[h264 @ 0x7bec920] Error splitting the input into NAL units.
Error while decoding stream #8:0: Invalid data found when processing input
https://clips-media-assets.twitch.tv/214741267.mp4: Invalid data found when processing input
  Last message repeated 2 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7bed200] stream 1, offset 0xdb7f6: partial fileits/s dup=6 drop=0 speed=0.317x    0 speed=0.317x
[h264 @ 0x84cbc60] Invalid NAL unit size (1625 > 440).
[h264 @ 0x84cbc60] Error splitting the input into NAL units.
Error while decoding stream #9:0: Invalid data found when processing input
https://clips-media-assets.twitch.tv/214575427.mp4: Invalid data found when processing input
  Last message repeated 2 times
frame= 7655 fps= 19 q=31.0 Lsize=   88771kB time=00:02:07.54 bitrate=5701.5kbits/s dup=8 drop=0 speed=0.316x     speed=0.317x
video:85056kB audio:2074kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.883764%
[libx264 @ 0x88d3640] frame I:40    Avg QP:22.85  size:143772
[libx264 @ 0x88d3640] frame P:2853  Avg QP:26.55  size: 20092
[libx264 @ 0x88d3640] frame B:4762  Avg QP:31.26  size:  5045
[libx264 @ 0x88d3640] consecutive B-frames:  2.8% 41.0%  5.4% 50.8%
[libx264 @ 0x88d3640] mb I  I16..4: 13.8% 21.0% 65.2%
[libx264 @ 0x88d3640] mb P  I16..4:  3.7%  3.7%  3.9%  P16..4: 29.6% 13.4%  6.3%  0.0%  0.0%    skip:39.4%
[libx264 @ 0x88d3640] mb B  I16..4:  0.9%  0.6%  0.6%  B16..8: 21.9%  5.6%  0.8%  direct: 1.6%  skip:68.1%  L0:41.3% L1:46.4% BI:12.3%
[libx264 @ 0x88d3640] 8x8 transform intra:30.7% inter:37.6%
[libx264 @ 0x88d3640] coded y,uvDC,uvAC intra: 57.7% 42.7% 8.6% inter: 10.5% 5.6% 0.4%
[libx264 @ 0x88d3640] i16 v,h,dc,p: 28% 30% 22% 20%
[libx264 @ 0x88d3640] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 24% 22%  3%  3%  4%  5%  4%  5%
[libx264 @ 0x88d3640] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 20% 20%  5%  5%  6%  6%  5%  5%
[libx264 @ 0x88d3640] i8c dc,h,v,p: 66% 18% 14%  2%
[libx264 @ 0x88d3640] Weighted P-Frames: Y:2.4% UV:0.7%
[libx264 @ 0x88d3640] ref P L0: 68.0% 13.8% 15.7%  2.5%  0.0%
[libx264 @ 0x88d3640] ref B L0: 87.4% 11.4%  1.2%
[libx264 @ 0x88d3640] ref B L1: 98.8%  1.2%
[libx264 @ 0x88d3640] kb/s:5461.32
[aac @ 0x8076a00] Qavg: 721.442

Lo curioso es que cuando aumento el número de CPU de Docker, parece recortar cada vez menos la salida esperada hasta que le doy a Docker 6 CPU. En ese momento, ninguno de los videos se recorta y se combinan todos los videos como se esperaba. Además de que los errores "Tamaño de unidad NAL no válido" ya no aparecen en la salida. Como es bastante nuevo en ffmpeg, cualquier ayuda para hacer que la concatenación de mp4 sea más estable en una configuración de CPU baja sería excelente.

información relacionada