[FFmpeg-user] movie filter concatenation removes the last frame

Louis Letourneau lletourn49 at gmail.com
Fri Apr 26 21:47:58 EEST 2024


I'm trying to concatenate multiple videos using filter_complex.
Problem is, the movie filter always removes the last frame.
The more movie filters there are, the more frames are removed

here are example commands to reproduce the problem

ffmpeg -y -s 640x480 -f rawvideo -pix_fmt rgb24 -r 60 -i /dev/zero -vf
"drawtext=fontfile=/usr/share/fonts/truetype/freefont/FreeMono.ttf:
text=%{n}: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1:
boxcolor=0x000000FF" -an -vcodec libx264 -preset fast -bf 0 -crf 24
-pix_fmt yuv420p -shortest -t 5 a.mp4
ffmpeg -y -s 640x480 -f rawvideo -pix_fmt rgb24 -r 60 -i /dev/zero -vf
"drawtext=fontfile=/usr/share/fonts/truetype/freefont/FreeMono.ttf:
text=%{n}: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1:
boxcolor=0x000000FF" -an -vcodec libx264 -preset fast -bf 0 -crf 24
-pix_fmt yuv420p -shortest -t 5 b.mp4

ffmpeg -y -i a.mp4 -i b.mp4 -filter_complex
"[0:v]setpts=PTS-STARTPTS[i0];[1:v]setpts=PTS-STARTPTS[i1];[i0][i1]concat=n=2:v=1,fps=60[outv]"
-map "[outv]" -an -codec:v libx264 -crf 23 -preset fast i.mp4

ffmpeg -y -i a.mp4 -filter_complex
"[0:v]setpts=PTS-STARTPTS[i0];movie=b.mp4,setpts=PTS-STARTPTS[i1];[i0][i1]concat=n=2:v=1,fps=60[outv]"
-map "[outv]" -an -codec:v libx264 -crf 23 -preset fast movie.mp4

ffprobe -v error -i a.mp4 -select_streams v -show_packets | grep flags |
sort | uniq -c
ffprobe -v error -i b.mp4 -select_streams v -show_packets | grep flags |
sort | uniq -c
# there should be a + b nb of frames, 600 frames
    298 flags=__
      2 flags=K_
    298 flags=__
      2 flags=K_

ffprobe -v error -i i.mp4 -select_streams v -show_packets | grep flags |
sort | uniq -c
# it works
    597 flags=__
      3 flags=K_

ffprobe -v error -i movie.mp4 -select_streams v -show_packets | grep flags
| sort | uniq -c
# missing 1
    596 flags=__
      3 flags=K_

duration also shows the same
ffprobe i.mp4
  Duration: 00:00:10.00, start: 0.000000, bitrate: 38 kb/s

$ ffprobe movie.mp4
  Duration: 00:00:09.98, start: 0.000000, bitrate: 38 kb/s

Tried with 5.1.3 and master from git
$ ./ffmpeg -y -i a.mp4 -filter_complex
"[0:v]setpts=PTS-STARTPTS[i0];movie=b.mp4,setpts=PTS-STARTPTS[i1];[i0][i1]concat=n=2:v=1,fps=60[outv]"
-map "[outv]" -an -codec:v libx264 -crf 23 -preset fast movie.mp4
ffmpeg version N-115009-g2d5fa816fb Copyright (c) 2000-2024 the FFmpeg
developers
  built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04)
  configuration: --enable-libxml2 --enable-libfreetype --enable-gpl
--enable-libx264 --enable-libx265 --enable-nonfree --enable-libopus
--enable-libvpx --enable-openssl --enable-static --enable-libpulse
--enable-sdl2 --enable-libharfbuzz
  libavutil      59. 16.101 / 59. 16.101
  libavcodec     61.  5.103 / 61.  5.103
  libavformat    61.  3.103 / 61.  3.103
  libavdevice    61.  2.100 / 61.  2.100
  libavfilter    10.  2.101 / 10.  2.101
  libswscale      8.  2.100 /  8.  2.100
  libswresample   5.  2.100 /  5.  2.100
  libpostproc    58.  2.100 / 58.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf61.3.103
  Duration: 00:00:05.00, start: 0.000000, bitrate: 34 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661),
yuv420p(progressive), 640x480, 31 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
      Metadata:
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.5.103 libx264
Stream mapping:
  Stream #0:0 (h264) -> setpts:default
  fps:default -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[libx264 @ 0x63454b41ca40] using SAR=1/1
[libx264 @ 0x63454b41ca40] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x63454b41ca40] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x63454b41ca40] 264 - core 163 r3060 5db6aa6 - H.264/MPEG-4 AVC
codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options:
cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 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=15
lookahead_threads=2 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=1 keyint=250 keyint_min=25
scenecut=40 intra_refresh=0 rc_lookahead=30 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 'movie.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf61.3.103
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive),
640x480 [SAR 1:1 DAR 4:3], q=2-31, 60 fps, 15360 tbn
      Metadata:
        encoder         : Lavc61.5.103 libx264
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[out#0/mp4 @ 0x63454b4960c0] video:37KiB audio:0KiB subtitle:0KiB other
streams:0KiB global headers:0KiB muxing overhead: 21.353021%
frame=  599 fps=0.0 q=-1.0 Lsize=      45KiB time=00:00:09.95 bitrate=
 36.8kbits/s speed=35.8x
[libx264 @ 0x63454b41ca40] frame I:3     Avg QP:10.01  size:   238
[libx264 @ 0x63454b41ca40] frame P:151   Avg QP:13.09  size:    88
[libx264 @ 0x63454b41ca40] frame B:445   Avg QP:16.56  size:    52
[libx264 @ 0x63454b41ca40] consecutive B-frames:  0.5%  1.0%  1.0% 97.5%
[libx264 @ 0x63454b41ca40] mb I  I16..4: 99.8%  0.1%  0.2%
[libx264 @ 0x63454b41ca40] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.1%
 0.0%  0.0%  0.0%  0.0%    skip:99.8%
[libx264 @ 0x63454b41ca40] 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:49.8% L1:38.8% BI:11.4%
[libx264 @ 0x63454b41ca40] 8x8 transform intra:0.6% inter:0.8%
[libx264 @ 0x63454b41ca40] coded y,uvDC,uvAC intra: 1.2% 0.0% 0.0% inter:
0.1% 0.0% 0.0%
[libx264 @ 0x63454b41ca40] i16 v,h,dc,p: 96%  1%  3%  0%
[libx264 @ 0x63454b41ca40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33%  7% 56%  2%
 0%  1%  0%  0%  1%
[libx264 @ 0x63454b41ca40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 13% 38%  9%
 2%  2%  2%  4%  5%
[libx264 @ 0x63454b41ca40] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 0x63454b41ca40] Weighted P-Frames: Y:2.0% UV:0.0%
[libx264 @ 0x63454b41ca40] ref P L0: 60.6% 39.4%
[libx264 @ 0x63454b41ca40] ref B L0: 82.0% 18.0%
[libx264 @ 0x63454b41ca40] ref B L1: 90.3%  9.7%
[libx264 @ 0x63454b41ca40] kb/s:29.68

am I doing something wrong?

Thanks
Louis


More information about the ffmpeg-user mailing list