Opened 2 years ago

#6479 new defect

Concat filter uses duration of longer stream for the last segment

Reported by: Gyan Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

The doc for concat filter says, The concat filter will use the duration of the longest stream in each segment (except the last one), and if necessary pad shorter audio streams with silence. Thus implying that the duration of the shorter stream is used for the last segment. But that doesn't seem to be the case.


Generate sources

ffmpeg -f lavfi -i color=yellow:d=1 -f lavfi -i sine=d=1 a.mp4
ffmpeg -f lavfi -i color=orange:d=12 b.mp4
ffmpeg -i AnyExistingAudio.m4a -t 5 b.mp3

Concat

ffmpeg -i a.mp4 -i b.mp4 -f lavfi -i amovie=b.mp3:loop=3,asetpts=N/SR/TB -filter_complex [0:v][0:a][1:v][2:a]concat=n=2:v=1:a=1[v][a] -map [v] -map [a] concat.mp4

Result is

Duration: 00:00:16.17, start: 0.000000, bitrate: 79 kb/s

It should be 13 seconds --> 1 second of a + 12 seconds of b.mp4 (shorter than 3 loops of 5-second b.mp3).

Log:

ffmpeg version N-86504-gc557718bea Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (Rev3, Built by MSYS2 project)
  configuration:  --enable-avisynth --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-cuda --enable-cuvid --enable-schannel --enable-decklink --enable-fontconfig --enable-frei0r --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libilbc --enable-libmfx --enable-libmodplug --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwavpack --enable-libwebp --enable-libxavs --enable-libxvid --enable-libzimg --enable-openssl --enable-libsnappy --enable-gpl --enable-opencl --enable-opengl --enable-libcdio --enable-libfdk-aac --enable-libkvazaar --enable-librubberband --enable-libssh --enable-libtesseract --enable-libzvbi --enable-chromaprint --enable-libopenh264 --enable-libopenmpt --enable-libzmq --enable-libmysofa --extra-cflags=-fopenmp --extra-libs=-lgomp --extra-cflags=-DLIBTWOLAME_STATIC --extra-libs=-lstdc++ --extra-cflags=-DLIBSSH_STATIC --extra-ldflags='-Wl,--allow-multiple-definition' --extra-cflags=-DCACA_STATIC --extra-cflags=-DMODPLUG_STATIC --extra-cflags=-DCHROMAPRINT_NODLL --extra-libs=-lstdc++ --extra-cflags=-DZMQ_STATIC --extra-libs=-lpng --disable-w32threads --extra-cflags=-DPTW32_STATIC_LIB --extra-libs=-lpthread --extra-libs=-lwsock32 --extra-cflags=-DKVZ_STATIC_LIB --enable-version3 --enable-nonfree --enable-filter=frei0r --disable-debug
  libavutil      55. 66.100 / 55. 66.100
  libavcodec     57. 99.100 / 57. 99.100
  libavformat    57. 73.100 / 57. 73.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 92.100 /  6. 92.100
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.73.100
  Duration: 00:00:01.02, start: 0.000000, bitrate: 96 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 9 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 70 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'b.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.73.100
  Duration: 00:00:12.00, start: 0.000000, bitrate: 6 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 3 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #2, lavfi, from 'amovie=b.mp3:loop=3,asetpts=N/SR/TB':
  Duration: N/A, start: 0.000000, bitrate: 768 kb/s
    Stream #2:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
Stream mapping:
  Stream #0:0 (h264) -> concat:in0:v0
  Stream #0:1 (aac) -> concat:in0:a0
  Stream #1:0 (h264) -> concat:in1:v0
  Stream #2:0 (pcm_s16le) -> concat:in1:a0
  concat:out:v0 -> Stream #0:0 (libx264)
  concat:out:a0 -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[libx264 @ 00000000029f2580] using SAR=1/1
[libx264 @ 00000000029f2580] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000000029f2580] profile High, level 1.3
[libx264 @ 00000000029f2580] 264 - core 150 r2833 df79067 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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 'concat.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.73.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc57.99.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, mono, fltp, 69 kb/s (default)
    Metadata:
      encoder         : Lavc57.99.100 aac
frame=  326 fps=0.0 q=-1.0 Lsize=     157kB time=00:00:16.16 bitrate=  79.7kbits/s dup=1 drop=0 speed=41.9x    
video:6kB audio:139kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.640960%
[libx264 @ 00000000029f2580] frame I:3     Avg QP: 7.00  size:    70
[libx264 @ 00000000029f2580] frame P:82    Avg QP: 9.23  size:    23
[libx264 @ 00000000029f2580] frame B:241   Avg QP:12.67  size:    15
[libx264 @ 00000000029f2580] consecutive B-frames:  1.2%  0.6%  0.0% 98.2%
[libx264 @ 00000000029f2580] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 00000000029f2580] 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 @ 00000000029f2580] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%
[libx264 @ 00000000029f2580] 8x8 transform intra:0.0%
[libx264 @ 00000000029f2580] coded y,uvDC,uvAC intra: 0.0% 0.3% 0.0% inter: 0.0% 0.0% 0.0%
[libx264 @ 00000000029f2580] i16 v,h,dc,p: 93%  0%  7%  0%
[libx264 @ 00000000029f2580] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 00000000029f2580] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000000029f2580] kb/s:3.44
[aac @ 00000000029f33e0] Qavg: 199.850\

If this isn't a bug, I'll send a patch to amend the documentation.

Change History (0)

Note: See TracTickets for help on using tickets.