savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.4k stars 130 forks source link

Error while executing OCaml read callback: Srt.Error(-1013981956, "Non-blocking call failure: transmission timed out") #2330

Closed copy closed 9 months ago

copy commented 2 years ago

Describe the bug

A simple input.srt fails with the above error.

To Reproduce

liquidsoap -v 'output.dummy(mksafe(input.srt(bind_address="0.0.0.0", port=53163)))'    

In another terminal (https://srtlab.github.io/srt-cookbook/apps/ffmpeg/#ffmpeg-example-with-smpte-bars-test-video-source):

ffmpeg -f lavfi -re -i smptebars=duration=60:size=1280x720:rate=30 -f lavfi -re \
       -i sine=frequency=1000:duration=60:sample_rate=44100 -pix_fmt yuv420p \
       -c:v libx264 -b:v 1000k -g 30 -keyint_min 120 -profile:v baseline \
       -preset veryfast -f mpegts "srt://127.0.0.1:53163?pkt_size=1316"

It will output:

2022/04/11 15:28:11 >>> LOG START
2022/04/11 15:28:10 [main:3] Liquidsoap 2.0.3-1
2022/04/11 15:28:10 [main:3] Using: bytes=[distributed with OCaml 4.02 or above] pcre=7.5.0 sedlex=2.6 menhirLib=20211128 dtools=0.4.4 duppy=0.9.2 mm=0.7.4 dynlink=[distributed with Ocaml] ffmpeg=1.1.3 alsa=0.3.0 camomile=1.0.2 pulseaudio=0.1.5 tsdl=v0.9.8 tsdl-image=0.3.2 srt.constants=0.2.1 srt.types=0.2.1 srt.stubs=0.2.1 srt.stubs.locked=0.2.1 srt=0.2.1
2022/04/11 15:28:10 [dynamic.loader:3] Could not find dynamic module for lame encoder.
2022/04/11 15:28:10 [dynamic.loader:3] Could not find dynamic module for fdkaac encoder.
2022/04/11 15:28:10 [clock:3] Using builtin (low-precision) implementation for latency control
2022/04/11 15:28:11 [frame:3] Using 44100Hz audio, 25Hz video, 44100Hz main.
2022/04/11 15:28:11 [frame:3] Video frame size set to: 1280x720
2022/04/11 15:28:11 [frame:3] Frame size must be a multiple of 1764 ticks = 1764 audio samples = 1 video samples.
2022/04/11 15:28:11 [frame:3] Targeting 'frame.duration': 0.04s = 1764 audio samples = 1764 ticks.
2022/04/11 15:28:11 [frame:3] Frames last 0.04s = 1764 audio samples = 1 video samples = 1764 ticks.
2022/04/11 15:28:11 [sandbox:3] Sandboxing disabled
2022/04/11 15:28:11 [video.converter:3] Using preferred video converter: ffmpeg.
2022/04/11 15:28:11 [audio.converter:3] Using samplerate converter: ffmpeg.
2022/04/11 15:28:11 [clock.input.srt:3] Streaming loop starts in auto-sync mode
2022/04/11 15:28:11 [clock.input.srt:3] Delegating synchronisation to CPU clock
2022/04/11 15:28:11 [mksafe:3] Switch to safe_blank.
Error while executing OCaml read callback: Srt.Error(-1013981956, "Non-blocking call failure: transmission timed out")
2022/04/11 15:28:22 [input.srt_0:2] Feeding failed: Avutil.Error(Generic error in an external library)

Expected behavior

It should not fail.

Version details

See the log.

Install method

opam

toots commented 2 years ago

Thanks for the report! I cannot reproduce here. What version of libsrt are you using? What OS/arch?

copy commented 2 years ago

libsrt 2.4.2-1 on Arch Linux.

copy commented 2 years ago

I tried recreating the switch (in case it's related to an upgraded system library or similar), but still getting the same issue.

For reference, my ffmpeg output is:

% ffmpeg -f lavfi -re -i smptebars=duration=60:size=1280x720:rate=30 -f lavfi -re \
       -i sine=frequency=1000:duration=60:sample_rate=44100 -pix_fmt yuv420p \
       -c:v libx264 -b:v 1000k -g 30 -keyint_min 120 -profile:v baseline \
       -preset veryfast -f mpegts "srt://127.0.0.1:53163?pkt_size=1316"
ffmpeg version n5.0 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 11.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-shared --enable-version3
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
Input #0, lavfi, from 'smptebars=duration=60:size=1280x720:rate=30':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 30 tbr, 30 tbn
Input #1, lavfi, from 'sine=frequency=1000:duration=60:sample_rate=44100':
  Duration: N/A, start: 0.000000, bitrate: 705 kb/s
  Stream #1:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> mp2 (native))
Press [q] to stop, [?] for help
[libx264 @ 0x557fe38a8900] using SAR=1/1
[libx264 @ 0x557fe38a8900] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x557fe38a8900] profile Constrained Baseline, level 3.1, 4:2:0, 8-bit
Output #0, mpegts, to 'srt://127.0.0.1:53163?pkt_size=1316':
  Metadata:
    encoder         : Lavf59.16.100
  Stream #0:0: Video: h264, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1000 kb/s, 30 fps, 90k tbn
    Metadata:
      encoder         : Lavc59.18.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: N/A
  Stream #0:1: Audio: mp2, 44100 Hz, mono, s16, 384 kb/s
    Metadata:
      encoder         : Lavc59.18.100 mp2
av_interleaved_write_frame(): Input/output error0:00:00.00 bitrate=N/A speed=   0x    
    Last message repeated 1 times
Error writing trailer of srt://127.0.0.1:53163?pkt_size=1316: Input/output error
frame=   34 fps= 30 q=33.0 Lsize=       7kB time=00:00:00.04 bitrate=1455.5kbits/s speed=0.0369x    
video:4kB audio:2kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 14.669106%
Error closing file srt://127.0.0.1:53163?pkt_size=1316: Input/output error
[libx264 @ 0x557fe38a8900] frame I:2     Avg QP:14.88  size:  3710
[libx264 @ 0x557fe38a8900] frame P:32    Avg QP:14.63  size:   129
[libx264 @ 0x557fe38a8900] mb I  I16..4: 99.1%  0.0%  0.9%
[libx264 @ 0x557fe38a8900] mb P  I16..4:  1.1%  0.0%  0.0%  P16..4:  0.3%  0.0%  0.0%  0.0%  0.0%    skip:98.6%
[libx264 @ 0x557fe38a8900] final ratefactor: 7.23
[libx264 @ 0x557fe38a8900] coded y,uvDC,uvAC intra: 0.2% 1.3% 0.6% inter: 0.0% 0.2% 0.0%
[libx264 @ 0x557fe38a8900] i16 v,h,dc,p: 92%  6%  2%  0%
[libx264 @ 0x557fe38a8900] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 42% 21% 37%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x557fe38a8900] i8c dc,h,v,p: 84%  5% 11%  0%
[libx264 @ 0x557fe38a8900] kb/s:81.44
Conversion failed!
toots commented 2 years ago

Thanks. I'm unable to reproduce with srt 1.4.2 (I assume you meant this version).

Reproduction steps on my end:

Logs:

$ liquidsoap -v 'output.dummy(mksafe(input.srt(bind_address="0.0.0.0", port=53163)))'
2022/04/11 14:49:57 >>> LOG START
2022/04/11 14:49:55 [main:3] Liquidsoap 2.0.4
2022/04/11 14:49:55 [main:3] Using: bytes=[distributed with OCaml 4.02 or above] posix-time2=2.0.0 pcre=7.5.0 sedlex=2.5 menhirLib=20211128 curl=0.9.2 memtrace=v0.2.1.2 mem_usage=0.0.1 dtools=0.4.4 duppy=0.9.2 cry=0.6.8 mm=0.8.0 xmlplaylist=0.1.5 lastfm=0.3.3 ogg=0.7.1 ogg.decoder=0.7.1 vorbis=0.8.1 vorbis.decoder=0.8.1 opus=0.2.2 opus.decoder=0.2.2 speex=0.4.0 speex.decoder=0.4.0 mad=0.5.0 flac=0.3.0 flac.ogg=0.3.0 flac.decoder=0.3.0 dynlink=[distributed with Ocaml] lame=0.3.6 shine=0.2.2 frei0r=0.1.2 fdkaac=0.3.2 theora=0.4.0 theora.decoder=0.4.0 ffmpeg=1.1.3 bjack=0.1.6 alsa=0.3.0 ao=0.2.3 samplerate=0.1.6 taglib=0.3.9 ssl=0.5.9 magic=0.7.3 camomile=1.0.2 inotify=2.3 yojson=1.7.0 faad=0.5.0 soundtouch=0.1.9 portaudio=0.2.3 pulseaudio=0.1.4 ladspa=0.2.0 dssi=0.1.3 tsdl=v0.9.8 tsdl-ttf=0.3.2 tsdl-image=0.3.2 camlimages=4.2.6 cohttp-lwt-unix=5.0.0 prometheus-app=1.1 srt.constants=0.2.2 srt.types=0.2.2 srt.stubs=0.2.2 srt.stubs.locked=0.2.2 srt=0.2.2 lo=0.2.0 gd=1.0a5
2022/04/11 14:49:55 [clock:3] Using native (high-precision) implementation for latency control
2022/04/11 14:49:57 [frame:3] Using 44100Hz audio, 25Hz video, 44100Hz main.
2022/04/11 14:49:57 [frame:3] Video frame size set to: 1280x720
2022/04/11 14:49:57 [frame:3] Frame size must be a multiple of 1764 ticks = 1764 audio samples = 1 video samples.
2022/04/11 14:49:57 [frame:3] Targeting 'frame.duration': 0.04s = 1764 audio samples = 1764 ticks.
2022/04/11 14:49:57 [frame:3] Frames last 0.04s = 1764 audio samples = 1 video samples = 1764 ticks.
2022/04/11 14:49:57 [sandbox:3] Running inside a docker container, disabling sandboxing.
2022/04/11 14:49:57 [video.converter:3] Using preferred video converter: ffmpeg.
2022/04/11 14:49:57 [audio.converter:3] Using samplerate converter: ffmpeg.
2022/04/11 14:49:57 [video.add_text:3] Using sdl implementation
2022/04/11 14:49:57 [clock.input.srt:3] Streaming loop starts in auto-sync mode
2022/04/11 14:49:57 [clock.input.srt:3] Delegating synchronisation to CPU clock
2022/04/11 14:49:57 [mksafe:3] Switch to safe_blank.
2022/04/11 14:50:13 [decoder.ffmpeg.internal:3] Frame format change detected!
2022/04/11 14:50:13 [mksafe:3] Switch to input.srt_0 with transition.
copy commented 2 years ago

I can reproduce in a docker container as you described. For reference, I ran:

docker run -it ubuntu:impish
apt update
apt install wget unzip
wget https://pipelines.actions.githubusercontent.com/...
apt install ./liquidsoap-v2.0.4-preview_2.0.4-ubuntu-impish-2_amd64.deb 
liquidsoap -v 'set("init.allow_root",true); output.dummy(mksafe(input.srt(bind_address="0.0.0.0", port=53163)))'

And:

docker exec -it cb0d57b9a19a /bin/bash
ffmpeg -f lavfi -re -i smptebars=duration=60:size=1280x720:rate=30 -f lavfi -re \
       -i sine=frequency=1000:duration=60:sample_rate=44100 -pix_fmt yuv420p \
       -c:v libx264 -b:v 1000k -g 30 -keyint_min 120 -profile:v baseline \
       -preset veryfast -f mpegts "srt://127.0.0.1:53163?pkt_size=1316"

I guess the fact that we can reproduce this issue with the same versions means that it's either kernel or hardware specific.

toots commented 2 years ago

That would be my guess as well. The SRT library reimplements a lot the low-level stuff that is usually covered by the TCP protocol so I wouldn't be surprised if it is dependent on specific kernel settings.

I would be nice if we could confirm that behavior using only the C library.

copy commented 9 months ago

Let's close this: It's tricky to reproduce and I don't use the hardware any more.