#10102 closed defect (invalid)

lavfi color background with clear png creating extra frames

Reported by: seankennett Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords: overlay image2 filter_complex
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I have 64 png images with transparent backgrounds which I want to overlay onto a plain black background. The issue I have is that additional black frames are added to the end of the video. Some of the images are completely transparent which seem to be the cause of the issue. Replacing these fully transparent images with partially transparent images works as expected. With fully transparent the length of video is 5.333 seconds, without is the expected length of 2.667.

ffmpeg -framerate 24 -i %d.png -f lavfi -i color=0x000000@1:s=1920x1080:r=24 -filter_complex "[1:v]trim=end_frame=64[b0];[b0][0:v]overlay" Recreate24.mp4

using latest master build:
ffmpeg version 2022-12-11-git-c3e20f78b0-essentials_build-www.gyan.dev

stack:
ffmpeg -framerate 24 -i %d.png -f lavfi -i color=0x000000@1:s=1920x1080:r=24 -filter_complex "[1:v]trim=end_frame=64[b0];[b0][0:v]overlay" Recreate24.mp4
ffmpeg version 2022-12-11-git-c3e20f78b0-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers

built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 57. 43.100 / 57. 43.100
libavcodec 59. 55.100 / 59. 55.100
libavformat 59. 34.102 / 59. 34.102
libavdevice 59. 8.101 / 59. 8.101
libavfilter 8. 52.100 / 8. 52.100
libswscale 6. 8.112 / 6. 8.112
libswresample 4. 9.100 / 4. 9.100
libpostproc 56. 7.100 / 56. 7.100

Input #0, image2, from '%d.png':

Duration: 00:00:02.67, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, monob(pc), 1920x1080, 24 fps, 24 tbr, 24 tbn

Input #1, lavfi, from 'color=0x000000@1:s=1920x1080:r=24':

Duration: N/A, start: 0.000000, bitrate: N/A
Stream #1:0: Video: wrapped_avframe, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 24 tbn

File 'Recreate24.mp4' already exists. Overwrite? [y/N] y
Stream mapping:

Stream #0:0 (png) -> overlay
Stream #1:0 (wrapped_avframe) -> trim:default
overlay:default -> Stream #0:0 (libx264)

Press [q] to stop, ? for help
[image2 @ 0000025ca857dcc0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
[libx264 @ 0000025ca8bbadc0] using SAR=1/1
[libx264 @ 0000025ca8bbadc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0000025ca8bbadc0] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0000025ca8bbadc0] 264 - core 164 r3102 416e3eb - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - 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=9 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=24 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 'Recreate24.mp4':

Metadata:

encoder : Lavf59.34.102

Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 24 fps, 12288 tbn

Metadata:

encoder : Lavc59.55.100 libx264

Side data:

cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A

frame= 128 fps= 65 q=-1.0 Lsize= 189kB time=00:00:05.20 bitrate= 296.5kbits/s dup=4 drop=0 speed=2.63x
video:186kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.242933%
[libx264 @ 0000025ca8bbadc0] frame I:2 Avg QP: 6.14 size: 3302
[libx264 @ 0000025ca8bbadc0] frame P:34 Avg QP:16.27 size: 2692
[libx264 @ 0000025ca8bbadc0] frame B:92 Avg QP:17.66 size: 999
[libx264 @ 0000025ca8bbadc0] consecutive B-frames: 1.6% 3.1% 14.1% 81.2%
[libx264 @ 0000025ca8bbadc0] mb I I16..4: 78.7% 20.5% 0.8%
[libx264 @ 0000025ca8bbadc0] mb P I16..4: 0.1% 0.5% 0.5% P16..4: 0.6% 0.4% 0.2% 0.0% 0.0% skip:97.8%
[libx264 @ 0000025ca8bbadc0] mb B I16..4: 0.0% 0.0% 0.1% B16..8: 1.1% 0.3% 0.1% direct: 0.1% skip:98.3% L0:52.8% L1:44.2% BI: 3.0%
[libx264 @ 0000025ca8bbadc0] 8x8 transform intra:24.5% inter:16.0%
[libx264 @ 0000025ca8bbadc0] coded y,uvDC,uvAC intra: 6.6% 10.0% 9.6% inter: 0.3% 0.3% 0.2%
[libx264 @ 0000025ca8bbadc0] i16 v,h,dc,p: 97% 1% 2% 0%
[libx264 @ 0000025ca8bbadc0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 59% 3% 36% 0% 0% 0% 0% 0% 1%
[libx264 @ 0000025ca8bbadc0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 20% 31% 4% 7% 6% 6% 3% 4%
[libx264 @ 0000025ca8bbadc0] i8c dc,h,v,p: 93% 3% 3% 0%
[libx264 @ 0000025ca8bbadc0] Weighted P-Frames: Y:8.8% UV:5.9%
[libx264 @ 0000025ca8bbadc0] ref P L0: 51.1% 6.3% 17.3% 25.3%
[libx264 @ 0000025ca8bbadc0] ref B L0: 77.5% 19.2% 3.3%
[libx264 @ 0000025ca8bbadc0] ref B L1: 94.0% 6.0%
[libx264 @ 0000025ca8bbadc0] kb/s:284.98

Attachments (2)

ErrorCausingFilesPart1.7z (1.4 MB ) - added by seankennett 17 months ago.
Part one of images
ErrorCausingFilesPart2.7z (2.0 MB ) - added by seankennett 17 months ago.
Part two of issue images

Change History (6)

by seankennett, 17 months ago

Attachment: ErrorCausingFilesPart1.7z added

Part one of images

by seankennett, 17 months ago

Attachment: ErrorCausingFilesPart2.7z added

Part two of issue images

comment:1 by Elon Musk, 17 months ago

Are you sure you should not use shortest option for overlay filter?

comment:2 by seankennett, 17 months ago

Shortest makes it behave better but not perfect, I think it's cutting the last frame as it happens to be fully clear image. Using that option gives a length of 2.625 seconds not the desired 2.667. I have 64 images and in the complex filter I limit the color to also be 64 frames, they both have the same framerate so they should overlay perfectly. Theoretically if I have 64 frames at 24 fps my video should be 2.6 recurring seconds long. Clear PNGs are the issue as when I replace those images with other PNGs that are not clear I get the desired outcome.

comment:3 by Elon Musk, 16 months ago

Source of your problem is mixture of pixel formats for images, some are monob and rest are rgba. This is not supposed to work perfectly as it will cause reset of filtergraph and in end result give wrong/unexpected results.

comment:4 by seankennett, 16 months ago

Resolution: invalid
Status: newclosed

Brilliant that makes sense. Thank you for looking into this, I will ensure my formats stay consistent in future

Note: See TracTickets for help on using tickets.