[FFmpeg-trac] #11203(avformat:new): Broken input duration may cause unnecessarily hang

FFmpeg trac at avcodec.org
Sat Sep 28 13:26:54 EEST 2024


#11203: Broken input duration may cause unnecessarily hang
----------------------------------+------------------------------------
             Reporter:  milahu    |                    Owner:  (none)
                 Type:  defect    |                   Status:  new
             Priority:  normal    |                Component:  avformat
              Version:  6.1.1     |               Resolution:
             Keywords:  matroska  |               Blocked By:
             Blocking:            |  Reproduced by developer:  0
Analyzed by developer:  0         |
----------------------------------+------------------------------------
Comment (by milahu):

 > 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
 }}}
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/11203#comment:4>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list