Opened 10 days ago
Last modified 5 days ago
#11203 new defect
Broken input duration may cause unnecessarily hang
Reported by: | milahu | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avformat |
Version: | 6.1.1 | Keywords: | matroska |
Cc: | MasterQuestionable | Blocked By: | |
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
with a broken input file
with loudnorm filter
with soxr resampling
ffmpeg hangs after transcoding
with the error message "File ended prematurely"
and the transcoding speed slowly drops to zero
ffmpeg version 6.1.2
repro.sh recording:
https://asciinema.org/a/677569
How to reproduce:
cd $(mktemp -d) aria2c --seed-time=0 "magnet:?xt=urn:btih:3bbabd438d58e83ae8a9d530dc3520b5c7ee1d80&dn=ffmpeg-hangs-at-File-ended-prematurely&tr=udp%3A%2F%2F89.234.156.205%3A451%2Fannounce&tr=udp%3A%2F%2F208.83.20.20%3A6969%2Fannounce&tr=udp%3A%2F%2F156.234.201.18%3A80%2Fannounce&tr=udp%3A%2F%2F185.243.218.213%3A80%2Fannounce&tr=udp%3A%2F%2F23.140.248.9%3A1337%2Fannounce&tr=udp%3A%2F%2F93.158.213.92%3A1337%2Fannounce" cd ffmpeg-hangs-at-File-ended-prematurely chmod +x repro.sh ./repro.sh
repro.sh
#!/bin/sh i=sie.leben.1988.remastered.german.dl.1080p.bluray.x264-contribution.sample.mkv af=loudnorm=i=-23.0:lra=7.0:tp=-2.0:linear=true:measured_i=-24.06:measured_lra=10.20:measured_tp=-6.89:measured_thresh=-34.12:offset=2.73 ffmpeg -hide_banner -i $i -map 0:a:0 -af $af -resampler soxr -ar 48k -f wav - > /dev/null
Change History (6)
follow-up: 4 comment:1 by , 8 days ago
comment:2 by , 8 days ago
Cc: | added |
---|
͏ Can you further ascertain that the audio alone would suffice to reproduce?
͏ And what is the minimal problematic filter? (or maybe happens with random filters..? or even without filter?)
͏ It appears the broken input duration could somehow be more reasonably handled.
comment:3 by , 8 days ago
Component: | undetermined → avformat |
---|---|
Keywords: | matroska added; hang removed |
Summary: | ffmpeg hangs at File ended prematurely → Broken input duration may cause unnecessarily hang |
comment:4 by , 7 days ago
a workaround is to get the actual duration of the audio track
and limit the transcoding process with-to $src_adur
this works only in some cases
in other cases
ffmpeg hangs before the actual audio track duration
there is no "File ended prematurely" error message
but also here, the transcoding speed slowly drops to zero
in all cases:
- input samplerate is 48KHz
- loudnorm filter changes samplerate to 192KHz = 4 * 48KHz
- output samplerate is 48KHz
- resampling is done by soxr
- input duration is an odd number of samples
so my guess is that
soxr is waiting for an even number of samples
but the input is exhausted
and ffmpeg does not send "null samples" to soxr
to produce an even number of samples
it works with temporary files
where soxr can see the end of file
example: ffmpeg hangs at 99.77%
this is with the audio alone
repro2.sh
https://asciinema.org/a/678034
tempfiles2.sh
https://asciinema.org/a/678035
cd $(mktemp -d) aria2c --seed-time=0 "magnet:?xt=urn:btih:384d43609a14132348dcef567bc4ecaa1da3fe96&dn=ffmpeg-hangs-at-File-ended-prematurely-2&tr=udp%3A%2F%2F23.140.248.9%3A1337%2Fannounce" cd ffmpeg-hangs-at-File-ended-prematurely-2 chmod +x repro2.sh ./repro2.sh
repro2.sh
#!/bin/sh # with "-ss 0" ffmpeg hangs at # size= 246429kB time=00:21:54.28 bitrate=1536.0kbits/s speed=0.0518x # time: 21:54.28 of 21:57.31 = 1314.28 of 1317.31 = 99.77% # samples: 1314.28*48000 of 1317.31*48000 = 63085440 of 63230880 # note: in this case, there is no "File ended prematurely" error set -eu # eac3, 48000 Hz, stereo, fltp, 224 kb/s i=American.Dad.S03E05.GERMAN.DL.FS.WEB.720p.h264-TSCC.mkv.a1.mka o=- #o=tmp.wav a=( ffmpeg -hide_banner -nostdin -ss 21:54 # hangs at 0.29 -> 21:54 + 0.29 = 21:54.29 # -to 00:21:57.31 # 21:57.31 - 21:54 = 57.31 - 54 = 3.31 # 3.31 * 48_000 = 158880 # 3.31 * 192_000 = 635520 # 192_000 / 48_000 = 4 # -ss 0 # hangs at 21:54.28 # -ss 21:34 # hangs at 20.29 -> 21:34 + 20.29 = 21:54.29 # -ss 21:35 # -ss 21:36 # -ss 21:37 # hangs at 17.28 -> 21:37 + 17.28 = 21:54.28 # -ss 21:38 # -ss 21:39 # hangs at 15.28 -> 21:39 + 15.28 = 21:54.28 # -ss 21:40 # -ss 21:41 # hangs at 13.29 -> 21:41 + 13.29 = 21:54.29 # -ss 21:42 # -ss 21:43 # hangs at 11.29 -> 21:43 + 11.29 = 21:54.29 # -ss 21:44 # -ss 21:45 # hangs at 9.29 -> 21:45 + 9.29 = 21:54.29 # -ss 21:46 # -ss 21:47 # hangs at 7.29 -> 21:47 + 7.29 = 21:54.29 # -ss 21:48 # -ss 21:49 # -ss 21:50 # -ss 21:51 # -ss 21:52 # hangs at 2.28 -> 21:52 + 2.28 = 21:54.28 # -ss 21:53 # -ss 21:54 # hangs at 0.29 -> 21:54 + 0.29 = 21:54.29 # -ss 21:54.1 # -ss 21:54.2 # -ss 21:54.21 # -ss 21:54.22 # -ss 21:54.23 # -ss 21:54.24 # -ss 21:54.25 # -ss 21:54.26 # -ss 21:54.27 # -ss 21:54.28 # this is needed here to produce an odd number of samples for soxr # actual input duration -to 00:21:57.31 -i "$i" # -map 0:a:1 -af loudnorm=i=-23.0:lra=7.0:tp=-2.0:linear=true:measured_i=-23.09:measured_lra=9.10:measured_tp=-9.54:measured_thresh=-33.71:offset=-0.45 -resampler soxr -ar 48000 -f wav "$o" ) set -x "${a[@]}" >/dev/null
follow-up: 6 comment:5 by , 7 days ago
minimal reproducer
#!/bin/sh # make ffmpeg hang with "-resampler soxr" set -eu i=anullsrc=channel_layout=mono:sample_rate=48000 o=silence.wav if ! [ -e "$o" ]; then ffmpeg -f lavfi -i "$i" -t 30 -f wav "$o" fi i="$o" o=- # many other "to" values make ffmpeg hang, but not all # 3.$RANDOM 4.$RANDOM 5.$RANDOM ... to=3.1001 a=( ffmpeg -hide_banner -nostdin -to $to # input "to" breaks -i "$i" # -to $to # output "to" works -af loudnorm=i=-23.0 -resampler soxr -ar 48000 -f wav "$o" ) "${a[@]}" >/dev/null
by fuzzing, i found some other bad to
values
all are greater than 3 seconds
my first 100 to
values:
3.0004 3.0007 3.0011 3.0013 3.0016 3.0021 3.0030 3.0033 3.0036 3.1001 3.1002 3.1003 3.1004 3.1005 3.1006 3.1007 3.1008 3.1009 3.1010 3.1011 3.1012 3.1013 3.1014 3.1015 3.1016 3.1017 3.1018 3.1019 3.1020 3.1021 3.1022 3.1023 3.1024 3.1025 3.1026 3.1027 3.1028 3.1029 3.1030 3.1031 3.1032 3.1033 3.1034 3.1035 3.1036 3.1037 3.1038 3.1039 3.1040 3.1041 3.1042 3.1043 3.1044 3.1045 3.1046 3.1047 3.1048 3.1049 3.1050 3.1051 3.1052 3.1053 3.1054 3.1055 3.1056 3.1057 3.1058 3.1059 3.1060 3.1061 3.1062 3.1063 3.1064 3.1065 3.1066 3.1067 3.1068 3.1069 3.1070 3.1071 3.1072 3.2001 3.2002 3.2003 3.2004 3.2005 3.2006 3.2007 3.2008 3.2009 3.2010 3.2011 3.2012 3.2013 3.2014 3.2015 3.2016 3.2017 3.2018 3.2019
all to
values smaller than 0.019284 make ffmpeg hang
and when i kill ffmpeg, it says
"Nothing was written into output file, because at least one of its streams received no packets."
some to
values make ffmpeg hang at time=00:00:00.00
comment:6 by , 5 days ago
͏ Summary:
͏ ffmpeg -v debug -hide_banner -nostdin -to 3.1001 -f lavfi -i "anullsrc=mono:48000:d=30" -af "loudnorm" -resampler soxr -ar 48000 -f null -
͏ In-Out same 48K as attempt to trigger no-op.
͏ ͏"loudnorm" processed output appears to be sort of trigger.
͏ Will this actually be 2 independent problems..?
a workaround is to get the actual duration of the audio track
and limit the transcoding process with
-to $src_adur