Proxy RTMP incoming traffic

1. Caddy version (caddy version):

v2.4.5

2. How I run Caddy:

Linux service

a. System environment:

Debian 4.9.0 64 bits

b. Command:

service caddy start

d. My complete Caddyfile or JSON config:

http://pcast.phonetic.com.pt {
        log {
                format console
                output file ./caddylog
        }
        handle_path /api/* {
                reverse_proxy 127.0.0.1:8111
        }
        handle_path /live/* {
                reverse_proxy tcp/localhost:1935
        }
        handle {
                root * /var/www/html
                file_server
        }
}

3. The problem I’m having:

When sending via ffmpeg a stream to the server I received error. On caddy I put a reverse_proxy to the RTMP server, that is an nginx configured to receive the stream.

4. Error messages and/or full log output:

No errors are shown by caddy. Below the result of the ffmpeg command I sent:

D:\Phonetic\PCast>ffmpeg -f dshow -i video="Integrated Webcam":audio="Microfone (Realtek Audio)" -video_size 640x480 -framerate 30 -profile:v high -pix_fmt yuv420p -level:v 4.1 -preset ultrafast -tune zerolatency -vcodec libx264 -r 25 -b:v 512k -s 640x360 -acodec aac -ac 2 -ab 32k -ar 44100 -f aac -b:a 128k -f flv rtmp://pcast.phonetic.com.pt/live/master
ffmpeg version 2021-04-07-git-c06465a70b-full_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-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --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-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 72.100 / 56. 72.100
  libavcodec     58.135.100 / 58.135.100
  libavformat    58. 77.100 / 58. 77.100
  libavdevice    58. 14.100 / 58. 14.100
  libavfilter     7.111.100 /  7.111.100
  libswscale      5. 10.100 /  5. 10.100
  libswresample   3. 10.100 /  3. 10.100
  libpostproc    55. 10.100 / 55. 10.100
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, dshow, from 'video=Integrated Webcam:audio=Microfone (Realtek Audio)':
  Duration: N/A, start: 358159.568000, bitrate: N/A
  Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 30 fps, 30 tbr, 10000k tbn, 10000k tbc
  Stream #0:1: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
[dshow @ 000001c19c4dfe40] real-time buffer [Integrated Webcam] [video input] too full or near too full (101% of size: 3041280 [rtbufsize parameter])! frame dropped!
    Last message repeated 295 times
[tcp @ 000001c1a149bec0] Connection to tcp://pcast.phonetic.com.pt:1935 failed: Error number -138 occurred
[dshow @ 000001c19c4dfe40] real-time buffer [Integrated Webcam] [video input] too full or near too full (101% of size: 3041280 [rtbufsize parameter])! frame dropped!
[rtmp @ 000001c1a149be00] Cannot open connection tcp://pcast.phonetic.com.pt:1935
rtmp://pcast.phonetic.com.pt/live/master: Unknown error
[dshow @ 000001c19c4dfe40] real-time buffer [Integrated Webcam] [video input] too full or near too full (101% of size: 3041280 [rtbufsize parameter])! frame dropped!

5. What I already tried:

Changed ports, put protocol on reverse_proxy.

6. Links to relevant resources:

Caddy is an HTTP proxy. RTMP is not HTTP according to Real-Time Messaging Protocol - Wikipedia. So Caddy’s built-in reverse_proxy module will not be able to proxy RTMP.

If you need to proxy TCP/UDP, then you can use GitHub - mholt/caddy-l4: Layer 4 (TCP/UDP) app for Caddy.

1 Like

Wow! Thanks for your prompt answer.

I’m kind of noob on caddy. Are there some easy documentation that I can explore?

The docs for caddy-l4 are in the README of the plugin on github. Currently, caddy-l4 does not support Caddyfile, so you would need to use JSON config or one of the JSON-like adapters listed in Config Adapters — Caddy Documentation (e.g. YAML, JSON5, JSONC).

This topic was automatically closed after 30 days. New replies are no longer allowed.