Opened 9 months ago

Last modified 3 months ago

#9152 open defect

FFmpeg doesn't stop after it has written the correct output file

Reported by: Michael Koch Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: framesync
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

I just created a special effect which shows several optical sound tracks, like in cine film.
The output video is perfectly ok and has the correct length 20s. But FFmpeg doesn't stop after it has written the output file. I have to terminate it with ctrl-c, and I don't understand why.

The problem can be reproduced with some audio input files, but not with all. This input file can be used for reproducing:

ffmpeg -f lavfi -i "sine=1k:b=2,channelmap=0|0" -t 20 -y sine.mp3

This is the command line for the special effect:

ffmpeg -i sine.mp3 -lavfi
"asplit=4[a0][a1][a2][a3];[a0]asplit[b0][c0];[a1]adelay=0.05:all=1,volume='gt(t,5)':eval=frame,asplit[b1][c1];[a2]adelay=0.1:all=1,volume='gt(t,10)':eval=frame,asplit[b2][c2];[a3]adelay=0.15:all=1,volume='gt(t,15)':eval=frame,asplit[b3][c3];[b0]showwaves=mode=cline:split_channels=true:s=1080x480:colors=white[v0];[b1]showwaves=mode=cline:split_channels=true:s=1080x480:colors=white[v1];[b2]showwaves=mode=cline:split_channels=true:s=1080x480:colors=white[v2];[b3]showwaves=mode=cline:split_channels=true:s=1080x480:colors=white[v3];[v0][v1][v2][v3]vstack=4,transpose;[c0][c1][c2][c3]amix=4"
-y out.mp4

The console outputs are below.

C:\Users\astro\Desktop>ffmpeg -f lavfi -i "sine=1k:b=2,channelmap=0|0"
-t 20 -y sine.mp3
ffmpeg version 2021-03-09-git-c35e456f54-essentials_build-www.gyan.dev
Copyright (c) 2000-2021 the FFmpeg developers

built with gcc 10.2.0 (Rev6, 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-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-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-libmfx --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 56. 67.100 / 56. 67.100
libavcodec 58.129.100 / 58.129.100
libavformat 58. 71.100 / 58. 71.100
libavdevice 58. 12.100 / 58. 12.100
libavfilter 7.109.100 / 7.109.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100

Input #0, lavfi, from 'sine=1k:b=2,channelmap=0|0':

Duration: N/A, start: 0.000000, bitrate: 1411 kb/s
Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s

Stream mapping:

Stream #0:0 -> #0:0 (pcm_s16le (native) -> mp3 (libmp3lame))

Press [q] to stop, ? for help
Output #0, mp3, to 'sine.mp3':

Metadata:

TSSE : Lavf58.71.100

Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p

Metadata:

encoder : Lavc58.129.100 libmp3lame

size= 313kB time=00:00:19.98 bitrate= 128.4kbits/s speed= 120x
video:0kB audio:313kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.078921%

C:\Users\astro\Desktop>ffmpeg -i sine.mp3 -lavfi
"asplit=4[a0][a1][a2][a3];[a0]asplit[b0][c0];[a1]adelay=0.05:all=1,volume='gt(t,5)':eval=frame,asplit[b1][c1];[a2]adelay=0.1:all=1,volume='gt(t,10)':eval=frame,asplit[b2][c2];[a3]adelay=0.15:all=1,volume='gt(t,15)':eval=frame,asplit[b3][c3];[b0]showwaves=mode=cline:split_channels=true:s=1080x480:colors=white[v0];[b1]showwaves=mode=cline:split_channels=true:s=1080x480:colors=white[v1];[b2]showwaves=mode=cline:split_channels=true:s=1080x480:colors=white[v2];[b3]showwaves=mode=cline:split_channels=true:s=1080x480:colors=white[v3];[v0][v1][v2][v3]vstack=4,transpose;[c0][c1][c2][c3]amix=4"
-y out.mp4
ffmpeg version 2021-03-09-git-c35e456f54-essentials_build-www.gyan.dev
Copyright (c) 2000-2021 the FFmpeg developers

built with gcc 10.2.0 (Rev6, 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-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-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-libmfx --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 56. 67.100 / 56. 67.100
libavcodec 58.129.100 / 58.129.100
libavformat 58. 71.100 / 58. 71.100
libavdevice 58. 12.100 / 58. 12.100
libavfilter 7.109.100 / 7.109.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100

Input #0, mp3, from 'sine.mp3':

Metadata:

encoder : Lavf58.71.100

Duration: 00:00:20.04, start: 0.025057, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s

Metadata:

encoder : Lavc58.12

Stream mapping:

Stream #0:0 (mp3float) -> asplit
transpose -> Stream #0:0 (libx264)
amix -> Stream #0:1 (aac)

Press [q] to stop, ? for help
[libx264 @ 00000247f8921ac0] using SAR=1/1
[libx264 @ 00000247f8921ac0] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000247f8921ac0] profile High 4:4:4 Predictive, level 4.0,
4:4:4, 8-bit
[libx264 @ 00000247f8921ac0] 264 - core 161 r3048 b86ae3c - H.264/MPEG-4
AVC codec - Copyleft 2003-2021 - 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=4 threads=12
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=2 keyint=250
keyint_min=20 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 'out.mp4':

Metadata:

encoder : Lavf58.71.100

Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv444p(tv,

progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 20.42 fps, 15680 tbn

Metadata:

encoder : Lavc58.129.100 libx264

Side data:

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

Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo,

fltp, 128 kb/s

Metadata:

encoder : Lavc58.129.100 aac

frame= 408 fps= 34 q=-1.0 Lsize= 10242kB time=00:00:19.96
bitrate=4201.6kbits/s speed=1.66x
video:10100kB audio:128kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.134918%
[libx264 @ 00000247f8921ac0] frame I:2 Avg QP:20.14 size: 59526
[libx264 @ 00000247f8921ac0] frame P:115 Avg QP:26.20 size: 39985
[libx264 @ 00000247f8921ac0] frame B:291 Avg QP:33.51 size: 19329
[libx264 @ 00000247f8921ac0] consecutive B-frames: 2.2% 7.8% 0.7% 89.2%
[libx264 @ 00000247f8921ac0] mb I I16..4: 16.2% 72.5% 11.3%
[libx264 @ 00000247f8921ac0] mb P I16..4: 0.0% 0.2% 0.3% P16..4:
6.0% 4.1% 3.4% 0.0% 0.0% skip:86.0%
[libx264 @ 00000247f8921ac0] mb B I16..4: 0.0% 0.0% 1.1% B16..8:
5.5% 1.7% 2.1% direct: 2.7% skip:86.9% L0:42.1% L1:42.0% BI:15.9%
[libx264 @ 00000247f8921ac0] 8x8 transform intra:29.6% inter:16.4%
[libx264 @ 00000247f8921ac0] coded y,u,v intra: 56.3% 0.0% 0.0% inter:
6.8% 0.0% 0.0%
[libx264 @ 00000247f8921ac0] i16 v,h,dc,p: 98% 0% 1% 0%
[libx264 @ 00000247f8921ac0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 80% 1% 19%
0% 0% 0% 0% 0% 0%
[libx264 @ 00000247f8921ac0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 7% 72% 8%
1% 1% 1% 4% 1% 5%
[libx264 @ 00000247f8921ac0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000247f8921ac0] ref P L0: 65.7% 8.8% 8.2% 17.2%
[libx264 @ 00000247f8921ac0] ref B L0: 94.1% 5.4% 0.4%
[libx264 @ 00000247f8921ac0] ref B L1: 97.3% 2.7%
[libx264 @ 00000247f8921ac0] kb/s:4140.21
[aac @ 00000247f8924e80] Qavg: 60535.746
Exiting normally, received signal 2.
Batchvorgang abbrechen (J/N)?

Change History (4)

comment:1 by Michael Koch, 9 months ago

Known workarounds:
It works correctly if the length of the input file is 12s or shorter.
It also works correctly with a *.wav file of any length.

comment:2 by Michael Koch, 4 months ago

I found a shorter command for reproducing the same problem:

ffmpeg -f lavfi -i "sine=1k:b=2,channelmap=0|0" -t 20 -y sine.mp3

ffmpeg -i sine.mp3 -lavfi "asplit=4[a0][a1][a2][a3];[a0]showwaves=mode=cline:s=1080x480[v0];[a1]adelay=0.2,showwaves=mode=cline:s=1080x480[v1];[a2]adelay=0.4,showwaves=mode=cline:s=1080x480[v2];[a3]showwaves=mode=cline:s=1080x480[v3];[v0][v1][v2][v3]vstack=4" -y out.mp4

FFmpeg writes the correct output file with length 20s, but after it has written the file, FFmpeg never stops.

C:\Users\astro\Desktop>ffmpeg -f lavfi -i "sine=1k:b=2,channelmap=0|0" -t 20 -y sine.mp3
ffmpeg version 2021-07-14-git-ca56299fb3-essentials_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers

built with gcc 10.3.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-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-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-libmfx --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. 0.100 / 57. 0.100
libavcodec 59. 3.101 / 59. 3.101
libavformat 59. 4.100 / 59. 4.100
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.103 / 8. 0.103
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100

Input #0, lavfi, from 'sine=1k:b=2,channelmap=0|0':

Duration: N/A, start: 0.000000, bitrate: 1411 kb/s
Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s

Stream mapping:

Stream #0:0 -> #0:0 (pcm_s16le (native) -> mp3 (libmp3lame))

Press [q] to stop, ? for help
Output #0, mp3, to 'sine.mp3':

Metadata:

TSSE : Lavf59.4.100

Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p

Metadata:

encoder : Lavc59.3.101 libmp3lame

size= 313kB time=00:00:20.01 bitrate= 128.3kbits/s speed= 116x
video:0kB audio:313kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.078609%

C:\Users\astro\Desktop>ffmpeg -i sine.mp3 -lavfi "asplit=4[a0][a1][a2][a3];[a0]showwaves=mode=cline:s=1080x480[v0];[a1]adelay=0.2,showwaves=mode=cline:s=1080x480[v1];[a2]adelay=0.4,showwaves=mode=cline:s=1080x480[v2];[a3]showwaves=mode=cline:s=1080x480[v3];[v0][v1][v2][v3]vstack=4" -y out.mp4
ffmpeg version 2021-07-14-git-ca56299fb3-essentials_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers

built with gcc 10.3.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-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-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-libmfx --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. 0.100 / 57. 0.100
libavcodec 59. 3.101 / 59. 3.101
libavformat 59. 4.100 / 59. 4.100
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.103 / 8. 0.103
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100

Input #0, mp3, from 'sine.mp3':

Metadata:

encoder : Lavf59.4.100

Duration: 00:00:20.04, start: 0.025057, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s

Metadata:

encoder : Lavc59.3.

Stream mapping:

Stream #0:0 (mp3float) -> asplit (graph 0)
vstack (graph 0) -> Stream #0:0 (libx264)
Stream #0:0 -> #0:1 (mp3 (mp3float) -> aac (native))

Press [q] to stop, ? for help
[libx264 @ 000001da9f480bc0] using SAR=1/1
[libx264 @ 000001da9f480bc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001da9f480bc0] profile High 4:4:4 Predictive, level 4.0, 4:4:4, 8-bit
[libx264 @ 000001da9f480bc0] 264 - core 164 r3065 ae03d92 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - 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=4 threads=12 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=2 keyint=250 keyint_min=20 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 'out.mp4':

Metadata:

encoder : Lavf59.4.100

Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv444p(tv, progressive), 1080x1920 [SAR 1:1 DAR 9:16], q=2-31, 20.42 fps, 15680 tbn

Metadata:

encoder : Lavc59.3.101 libx264

Side data:

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

Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s

Metadata:

encoder : Lavc59.3.101 aac

frame= 408 fps= 30 q=-1.0 Lsize= 4051kB time=00:00:19.99 bitrate=1659.9kbits/s speed=1.48x
video:3725kB audio:312kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.341681%
[libx264 @ 000001da9f480bc0] frame I:2 Avg QP:11.95 size: 92274
[libx264 @ 000001da9f480bc0] frame P:112 Avg QP:12.40 size: 19184
[libx264 @ 000001da9f480bc0] frame B:294 Avg QP:28.14 size: 5037
[libx264 @ 000001da9f480bc0] consecutive B-frames: 1.5% 6.9% 1.5% 90.2%
[libx264 @ 000001da9f480bc0] mb I I16..4: 45.3% 37.3% 17.3%
[libx264 @ 000001da9f480bc0] mb P I16..4: 1.6% 0.7% 0.6% P16..4: 2.9% 4.1% 5.5% 0.0% 0.0% skip:84.6%
[libx264 @ 000001da9f480bc0] mb B I16..4: 0.0% 1.0% 1.1% B16..8: 6.9% 1.1% 0.5% direct: 0.4% skip:88.9% L0:45.6% L1:44.9% BI: 9.5%
[libx264 @ 000001da9f480bc0] 8x8 transform intra:40.1% inter:52.4%
[libx264 @ 000001da9f480bc0] coded y,u,v intra: 42.0% 36.0% 38.9% inter: 2.9% 0.6% 1.0%
[libx264 @ 000001da9f480bc0] i16 v,h,dc,p: 95% 5% 0% 0%
[libx264 @ 000001da9f480bc0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 9% 59% 0% 0% 0% 0% 0% 0%
[libx264 @ 000001da9f480bc0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 86% 4% 5% 1% 1% 2% 0% 2% 0%
[libx264 @ 000001da9f480bc0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 000001da9f480bc0] ref P L0: 48.3% 11.6% 27.8% 12.3%
[libx264 @ 000001da9f480bc0] ref B L0: 75.7% 21.4% 2.9%
[libx264 @ 000001da9f480bc0] ref B L1: 94.8% 5.2%
[libx264 @ 000001da9f480bc0] kb/s:1526.88
[aac @ 000001da9f4a7ec0] Qavg: 702.835
Exiting normally, received signal 2.
Batchvorgang abbrechen (J/N)?

comment:3 by Michael Koch, 4 months ago

This is an even shorter example for reproducing the same problem:

ffmpeg -f lavfi -i "sine=1k:b=2,channelmap=0|0" -t 15 -y sine.mp3

ffmpeg -i sine.mp3 -lavfi "asplit=3[a1][a2][a3];[a1]adelay=0,showwaves[v1];[a2]adelay=0,showwaves[v2];[a3]showwaves[v3];[v1][v2][v3]vstack=3" -y out.mp4

Michael

comment:4 by Elon Musk, 3 months ago

Component: undeterminedavfilter
Keywords: framesync added
Reproduced by developer: set
Status: newopen

Looks like bug in framesync to me, workaround seems to set some little bigger timebase prior to asplit filter with asettb filter.

Note: See TracTickets for help on using tickets.