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 128 forks source link

Source failed (no more tracks) stopping output with h264_mp4toannexb #2851

Closed TheRealMattLear closed 1 year ago

TheRealMattLear commented 1 year ago

Describe the bug Switching between a live ffmpeg input and an infallible source (single()) results in a brief disconnection and reconnection of the output [h264_mp4toannexb.consumer_0:3] Source failed (no more tracks) stopping output.... When removing the bitstream filter, the output does not stop.

Have tested with both 2.1.2 and liquidsoap-f845354_2.1.4

To Reproduce

log.level.set(4)
settings.init.allow_root.set(true);
settings.ffmpeg.log.verbosity.set("verbose")
settings.ffmpeg.content.copy.relaxed_compatibility_check.set(true)

live = input.rtmp(listen=true,"rtmp://0.0.0.0:19350/live/test")
live = ffmpeg.filter.bitstream.h264_mp4toannexb(live)

vod = single("/home/vod/sample.mp4")
vod = ffmpeg.filter.bitstream.h264_mp4toannexb(vod)

s = fallback(track_sensitive=false,[live,vod])

output.file(fallible=true,%ffmpeg(format="flv", %audio.copy, %video.copy), "output.mp4", s)

Output

root@localhost:~# liquidsoap ./test.liq
2023/01/14 05:31:57 >>> LOG START
2023/01/14 05:31:54 [main:3] Liquidsoap 2.1.4+git@f845354f8
2023/01/14 05:31:54 [main:3] Using: bytes=[distributed with OCaml 4.02 or above] posix-time2=2.0.0 pcre=7.5.0 sedlex=3.0 menhirLib=20220210 curl=0.9.2 uri=4.2.0 memtrace=v0.2.2 mem_usage=0.0.4 dtools=0.4.4 duppy=0.9.3 cry=0.6.8 mm=0.8.2 xmlplaylist=0.1.5 lastfm=0.3.3 ogg=0.7.3 ogg.decoder=0.7.3 vorbis=0.8.1 vorbis.decoder=0.8.1 opus=0.2.3 opus.decoder=0.2.3 speex=0.4.1 speex.decoder=0.4.1 mad=0.5.2 flac=0.3.1 flac.ogg=0.3.1 flac.decoder=0.3.1 dynlink=[distributed with Ocaml] lame=0.3.6 shine=0.2.3 frei0r=0.1.2 fdkaac=0.3.2 theora=0.4.0 theora.decoder=0.4.0 ffmpeg=1.1.6 bjack=0.1.6 alsa=0.3.0 ao=0.2.4 samplerate=0.1.6 taglib=0.3.10 ssl=0.5.11 magic=0.7.3 camomile=1.0.2 inotify=2.0-58-g1beb568 faad=0.5.2 soundtouch=0.1.9 portaudio=0.2.3 pulseaudio=0.1.5 ladspa=0.2.2 dssi=0.1.5 tsdl=v0.9.9 tsdl-ttf=0.3.2 tsdl-image=0.3.2 camlimages=4.2.6 camlimages.freetype=5.0.4 cohttp-lwt-unix=5.0.0 prometheus-app=1.2 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 irc-client-unix=[unspecified]
2023/01/14 05:31:54 [main:3]
2023/01/14 05:31:54 [main:3] DISCLAIMER: This version of Liquidsoap has been
2023/01/14 05:31:54 [main:3] compiled from a snapshot of the development code.
2023/01/14 05:31:54 [main:3] As such, it should not be used in production
2023/01/14 05:31:54 [main:3] unless you know what you are doing!
2023/01/14 05:31:54 [main:3]
2023/01/14 05:31:54 [main:3] We are, however, very interested in any feedback
2023/01/14 05:31:54 [main:3] about our development code and committed to fix
2023/01/14 05:31:54 [main:3] issues as soon as possible.
2023/01/14 05:31:54 [main:3]
2023/01/14 05:31:54 [main:3] If you are interested in collaborating to
2023/01/14 05:31:54 [main:3] the development of Liquidsoap, feel free to
2023/01/14 05:31:54 [main:3] drop us a mail at <savonet-devl@lists.sf.net>
2023/01/14 05:31:54 [main:3] or to join the slack chat at <http://slack.liquidsoap.info>.
2023/01/14 05:31:54 [main:3]
2023/01/14 05:31:54 [main:3] Please send any bug report or feature request
2023/01/14 05:31:54 [main:3] at <https://github.com/savonet/liquidsoap/issues>.
2023/01/14 05:31:54 [main:3]
2023/01/14 05:31:54 [main:3] We hope you enjoy this snapshot build of Liquidsoap!
2023/01/14 05:31:54 [main:3]
2023/01/14 05:31:54 [clock:3] Using native (high-precision) implementation for latency control
2023/01/14 05:31:57 [frame:4] frame.audio.samplerate set to: 44100
2023/01/14 05:31:57 [frame:4] frame.video.framerate set to: 25
2023/01/14 05:31:57 [frame:4] frame.audio.channels set to: 2
2023/01/14 05:31:57 [frame:4] frame.video.default set to: false
2023/01/14 05:31:57 [frame:4] frame.midi.channels set to: 0
2023/01/14 05:31:57 [frame:4] frame.video.width set to: 1280
2023/01/14 05:31:57 [frame:4] frame.video.height set to: 720
2023/01/14 05:31:57 [frame:4] frame.audio.samplerate set to: 44100
2023/01/14 05:31:57 [frame:3] Using 44100Hz audio, 25Hz video, 44100Hz main.
2023/01/14 05:31:57 [frame:3] Video frame size set to: 1280x720
2023/01/14 05:31:57 [frame:3] Frame size must be a multiple of 1764 ticks = 1764 audio samples = 1 video samples.
2023/01/14 05:31:57 [frame:3] Targeting 'frame.duration': 0.04s = 1764 audio samples = 1764 ticks.
2023/01/14 05:31:57 [frame:3] Frames last 0.04s = 1764 audio samples = 1 video samples = 1764 ticks.
2023/01/14 05:31:57 [sandbox:3] Sandboxing disabled
2023/01/14 05:31:57 [video.converter:3] Using preferred video converter: ffmpeg.
2023/01/14 05:31:57 [audio.converter:3] Using samplerate converter: libsamplerate.
2023/01/14 05:31:57 [clock:4] Currently 3 clock(s) allocated.
2023/01/14 05:31:57 [clock.h264_mp4toannexb.producer_1.child:4] Starting 1 source(s)...
2023/01/14 05:31:57 [source:4] Source h264_mp4toannexb.consumer_1 gets up with content kind: {audio=ffmpeg.audio.copy,video=ffmpeg.video.copy,midi=none}.
2023/01/14 05:31:57 [h264_mp4toannexb.consumer_1:4] Content type is {audio=ffmpeg.audio.copy,video=ffmpeg.video.copy,midi=none}.
2023/01/14 05:31:57 [source:4] Source single_0 gets up with content kind: {audio=ffmpeg.audio.copy,video=ffmpeg.video.copy,midi=none}.
2023/01/14 05:31:57 [single_0:3] "/home/vod/sample.mp4" is static, resolving once for all...
2023/01/14 05:31:57 [decoder.ogg:4] Unsupported file extension for "/home/vod/sample.mp4"!
2023/01/14 05:31:57 [decoder.ogg:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
2023/01/14 05:31:57 [decoder.srt:4] Unsupported file extension for "/home/vod/sample.mp4"!
2023/01/14 05:31:57 [decoder.srt:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
2023/01/14 05:31:57 [decoder:4] Available decoders: FFMPEG (priority: 10), IMAGE (priority: 1)
2023/01/14 05:31:57 [decoder:4] Trying decoder "FFMPEG"
[h264 @ 0x7fc08c009940] Reinit context to 512x288, pix_fmt: yuv420p
2023/01/14 05:31:57 [decoder.ffmpeg:4] ffmpeg recognizes "/home/vod/sample.mp4" as: audio: {codec: aac, 48000Hz, 2 channel(s)}, video: {codec: h264, 512x288, yuv420p} and content-type: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
[AVIOContext @ 0x7fc08c010ac0] Statistics: 615391 bytes read, 2 seeks
2023/01/14 05:31:57 [decoder:4] Selected decoder FFMPEG for file "/home/vod/sample.mp4" with expected kind {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none} and detected content {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}
[h264 @ 0x7fc08c007c40] Reinit context to 512x288, pix_fmt: yuv420p
[AVIOContext @ 0x7fc08c00be80] Statistics: 615391 bytes read, 2 seeks
2023/01/14 05:31:57 [metadata.flac:4] Unsupported file extension for "/home/vod/sample.mp4"!
2023/01/14 05:31:57 [metadata.flac:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
2023/01/14 05:31:57 [metadata.mp4:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
2023/01/14 05:31:57 [decoder.ogg:4] Unsupported file extension for "/home/vod/sample.mp4"!
2023/01/14 05:31:57 [decoder.ogg:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
2023/01/14 05:31:57 [decoder.id3:4] Unsupported file extension for "/home/vod/sample.mp4"!
2023/01/14 05:31:57 [decoder.id3:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
2023/01/14 05:31:57 [decoder.id3:4] Unsupported file extension for "/home/vod/sample.mp4"!
2023/01/14 05:31:57 [decoder.id3:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
2023/01/14 05:31:57 [decoder.id3:4] Unsupported file extension for "/home/vod/sample.mp4"!
2023/01/14 05:31:57 [decoder.id3:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
2023/01/14 05:31:57 [decoder.image.metadata:4] Unsupported file extension for "/home/vod/sample.mp4"!
2023/01/14 05:31:57 [decoder.image.metadata:4] Unsupported MIME type for "/home/vod/sample.mp4": video/mp4!
[h264 @ 0x7fc08c262a40] Reinit context to 512x288, pix_fmt: yuv420p
[AVIOContext @ 0x7fc08c0270c0] Statistics: 615391 bytes read, 2 seeks
[h264 @ 0x7fc08c027b00] Reinit context to 512x288, pix_fmt: yuv420p
2023/01/14 05:31:57 [single_0:3] Prepared "/home/vod/sample.mp4" (RID 0).
2023/01/14 05:31:57 [clock.h264_mp4toannexb.producer_0.child:4] Starting 2 source(s)...
2023/01/14 05:31:57 [source:4] Source input.ffmpeg_0 gets up with content kind: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [source:4] Source h264_mp4toannexb.consumer_0 gets up with content kind: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [h264_mp4toannexb.consumer_0:4] Content type is {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [clock.main:4] Starting 1 source(s)...
2023/01/14 05:31:57 [source:4] Source output.file_0 gets up with content kind: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [output.mp4:4] Content type is {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [source:4] Source switch_0 gets up with content kind: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [source:4] Source h264_mp4toannexb.producer_0 gets up with content kind: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [h264_mp4toannexb.producer_0:4] Content type is {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [source:4] Source h264_mp4toannexb.producer_1 gets up with content kind: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [h264_mp4toannexb.producer_1:4] Content type is {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:31:57 [threads:4] Created thread "clock_main" (1 total).
2023/01/14 05:31:57 [clock:4] Main phase starts.
2023/01/14 05:31:57 [threads:4] Created thread "generic queue #1" (1 total).
2023/01/14 05:31:57 [threads:4] Created thread "generic queue #2" (2 total).
2023/01/14 05:31:57 [threads:4] Created thread "non-blocking queue #1" (3 total).
2023/01/14 05:31:57 [threads:4] Created thread "non-blocking queue #2" (4 total).
2023/01/14 05:31:57 [video.text:3] Using camlimages implementation
2023/01/14 05:31:57 [clock.main:3] Streaming loop starts in auto-sync mode
2023/01/14 05:31:57 [clock.main:3] Delegating synchronisation to CPU clock
2023/01/14 05:31:57 [switch_0:3] Switch to h264_mp4toannexb.producer_1.
[h264 @ 0x7fc07c016c40] Reinit context to 1280x720, pix_fmt: yuvj420p
2023/01/14 05:32:02 [decoder.ffmpeg:4] ffmpeg recognizes "rtmp://0.0.0.0:19350/live/test" as: audio: {codec: aac, 48000Hz, 2 channel(s)}, video: {codec: h264, 1280x720, yuvj420p} and content-type: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:32:02 [switch_0:3] Switch to h264_mp4toannexb.producer_0 with transition.
2023/01/14 05:32:07 [input.ffmpeg_0:4] Feeding failed: Avutil.Error(Input/output error)
2023/01/14 05:32:07 [input.ffmpeg_0:4] Raised by primitive operation at Av.read_input in file "av/av.ml", line 220, characters 2-31
2023/01/14 05:32:07 [input.ffmpeg_0:4] Called from Ffmpeg_decoder.mk_decoder.(fun).f in file "decoder/ffmpeg_decoder.ml", line 669, characters 10-99
[AVIOContext @ 0x7fc07c015fc0] Statistics: 774905 bytes read, 0 seeks
2023/01/14 05:32:07 [input.ffmpeg_0:4] Re-raised at Ffmpeg_decoder.mk_decoder.(fun).f in file "decoder/ffmpeg_decoder.ml", line 702, characters 12-48
2023/01/14 05:32:07 [input.ffmpeg_0:4] Called from Ffmpeg_io.input#get_frame in file "io/ffmpeg_io.ml", line 186, characters 10-24
2023/01/14 05:32:07 [input.ffmpeg_0:4]
2023/01/14 05:32:07 [h264_mp4toannexb.consumer_0:3] Source failed (no more tracks) stopping output...
2023/01/14 05:32:07 [switch_0:3] Switch to h264_mp4toannexb.producer_1 with forgetful transition.
2023/01/14 05:32:07 [source:4] Source replay_metadata_0 gets up with content kind: {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
2023/01/14 05:32:07 [replay_metadata_0:4] Content type is {audio=ffmpeg.audio.copy(sample_rate=48000,sample_format=fltp,channel_layout="stereo",codec="aac"),video=ffmpeg.video.copy(pixel_format=yuv420p,aspect_ratio=1/1,height=288,width=512,codec="h264"),midi=none}.
^C2023/01/14 05:32:17 [main:3] Shutdown started!
2023/01/14 05:32:17 [main:3] Waiting for main threads to terminate...
2023/01/14 05:32:17 [threads:4] Waiting for thread clock_main to shutdown
2023/01/14 05:32:17 [source:4] Source output.mp4 gets down.
[AVIOContext @ 0x7fc08c243600] Statistics: 2 seeks, 9 writeouts
2023/01/14 05:32:17 [source:4] Source switch_0 gets down.
2023/01/14 05:32:17 [source:4] Source h264_mp4toannexb.producer_0 gets down.
2023/01/14 05:32:17 [source:4] Source replay_metadata_0 gets down.
2023/01/14 05:32:17 [source:4] Source h264_mp4toannexb.producer_1 gets down.
2023/01/14 05:32:17 [clock.main:3] Streaming loop stopped.
2023/01/14 05:32:17 [threads:4] Thread "clock_main" terminated (0 remaining).
2023/01/14 05:32:17 [main:3] Main threads terminated.
2023/01/14 05:32:17 [threads:3] Shutting down scheduler...
2023/01/14 05:32:17 [threads:4] Thread "non-blocking queue #2" terminated (3 remaining).
2023/01/14 05:32:17 [threads:4] Thread "non-blocking queue #1" terminated (2 remaining).
2023/01/14 05:32:17 [threads:4] Thread "generic queue #2" terminated (1 remaining).
[rtmp @ 0x7fc070005a00] Cannot open connection tcp://0.0.0.0:19350?listen&listen_timeout=-1000
2023/01/14 05:32:17 [input.ffmpeg_0:4] Connection failed: Avutil.Error(Immediate exit requested)
2023/01/14 05:32:17 [threads:4] Thread "generic queue #1" terminated (0 remaining).
2023/01/14 05:32:17 [threads:3] Scheduler shut down.
2023/01/14 05:32:17 [main:3] Cleaning downloaded files...
2023/01/14 05:32:17 [main:3] Freeing memory...
toots commented 1 year ago

Thanks. The synchronization mechanisms there have some quirks indeed. I'll see what I can do.

TheRealMattLear commented 1 year ago

@toots Confirming this appears to be resolved in Liquidsoap 2.1.4+git@5c4daae3d