使用 ffmpeg 流式传输到 Facebook Live

使用 ffmpeg 流式传输到 Facebook Live

我已经设置了 RTMP/RTSP 流媒体服务媒体MTX在我的桌面上。

然后,我将从 OBS Studio 流式传输到:

Server: rtmp://localhost/
Stream Key: stream

这让我剩下 2 个流:

RTMP: rtmp://localhost/stream
RTSP: rtsp://localhost:8554/stream

然后设置 MediaMTX 使用 将流同时重新分发到 YouTube、Twitch 和 Facebook ffmpeg

流式传输到 YouTube 和 Twitch 没有问题。但每当我尝试流式传输到 Facebook 时,我总是会收到超时错误。

命令

C:/mediamtx_v1.3.0/ffmpeg.exe -i "rtmp://localhost/stream"
-c:v libx264 -b:v 4500k -r 60 -g 120 -f flv "rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAM_KEY"
-c copy -f flv "rtmp://ber.contribute.live-video.net/app/TWITCH_STREAM_KEY"
-c copy -f flv rtmps://live-api-s.facebook.com:443/rtmp/FACEBOOK_STREAM_KEY

这部分代码是失败的:

-c copy -f flv rtmps://live-api-s.facebook.com:443/rtmp/FACEBOOK_STREAM_KEY

让我们尝试仅向 Facebook 广播:

C:/mediamtx_v1.3.0/ffmpeg.exe -i "rtmp://localhost/stream" -c copy -f flv rtmps://live-api-s.facebook.com:443/rtmp/FACEBOOK_STREAM_KEY


    2023/11/19 11:00:43 INF MediaMTX v1.3.0
    2023/11/19 11:00:43 INF configuration loaded from C:\mediamtx_v1.3.0\mediamtx.yml
    2023/11/19 11:00:43 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
    2023/11/19 11:00:43 INF [RTMP] listener opened on :1935
    2023/11/19 11:00:43 INF [HLS] listener opened on :8888
    2023/11/19 11:00:43 INF [WebRTC] listener opened on :8889 (HTTP), :8189 (ICE/UDP)
    2023/11/19 11:00:43 INF [SRT] listener opened on :8890 (UDP)
    2023/11/19 11:00:44 INF [RTMP] [conn [::1]:54189] opened
    2023/11/19 11:00:45 INF [path stream] runOnReady command started
    2023/11/19 11:00:45 INF [RTMP] [conn [::1]:54189] is publishing to path 'stream', 2 tracks (H264, MPEG-4 Audio)
    ffmpeg version N-112782-g07c303b708-20231118 Copyright (c) 2000-2023 the FFmpeg developers
      built with gcc 13.2.0 (crosstool-NG 1.25.0.232_c175b21)
      configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libharfbuzz --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-chromaprint --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libaribcaption --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --enable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20231118
      libavutil      58. 32.100 / 58. 32.100
      libavcodec     60. 33.100 / 60. 33.100
      libavformat    60. 17.100 / 60. 17.100
      libavdevice    60.  4.100 / 60.  4.100
      libavfilter     9. 13.100 /  9. 13.100
      libswscale      7.  6.100 /  7.  6.100
      libswresample   4. 13.100 /  4. 13.100
      libpostproc    57.  4.100 / 57.  4.100
    2023/11/19 11:00:45 INF [RTMP] [conn [::1]:54191] opened
    2023/11/19 11:00:45 INF [RTMP] [conn [::1]:54191] is reading from path 'stream', 2 tracks (H264, MPEG-4 Audio)
    Input #0, flv, from 'rtmp://localhost/stream':
      Duration: N/A, start: 0.066000, bitrate: N/A
      Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 30.30 fps, 30 tbr, 1k tbn
      Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp
    Output #0, flv, to 'rtmps://live-api-s.facebook.com:443/rtmp/FACEBOOK_STREAM_KEY':
      Metadata:
        encoder         : Lavf60.17.100
      Stream #0:0: Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 30.30 fps, 30 tbr, 1k tbn
      Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 48000 Hz, stereo, fltp
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    2023/11/19 11:01:09 INF [RTMP] [conn [::1]:54191] closed: write tcp [::1]:1935->[::1]:54191: i/o timeout
[vost#0:0/copy @ 000002ea9fa8a780] Error submitting a packet to the muxer: End of file
[flv @ 000002ea9fa8d900] Failed to update header with correct duration.
[flv @ 000002ea9fa8d900] Failed to update header with correct filesize.
[out#0/flv @ 000002ea9c93aac0] Error writing trailer: End of file
[out#0/flv @ 000002ea9c93aac0] Error closing file: End of file
[out#0/flv @ 000002ea9c93aac0] video:29kB audio:194kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
size=       4kB time=00:00:08.39 bitrate=   3.6kbits/s speed=0.07x
Conversion failed!
2023/11/19 11:02:56 INF [path stream] runOnReady command exited: command exited with code 0

我想说的是,我曾尝试在 OBS Studio 中专门向 Facebook 进行流式传输,效果很好。因此,我确信我在使用时做错了什么ffmpeg

有人能帮我解决这个难题吗?

答案1

在你的日志中你有

2023/11/19 11:01:09 INF [RTMP] [conn [::1]:54191] closed: write tcp [::1]:1935->[::1]:54191: i/o timeout   

这表明 I/O 超时导致 TCP 连接关闭。此后的所有事件都可能成为连锁反应。

发生这种情况的原因有很多。

防火墙设置不当、缺少文件权限、服务器配置错误、凭据不正确、连接不稳定或客户端或远程机器的资源匮乏。

如果可以,请尝试深入了解您的 OBS 设置,看看您是否为 Facebook 配置了不同内容。

相关内容