You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FFmpeg推流至Facebook RTMP服务器几秒后中断问题求助

Troubleshooting FFmpeg FLV to Facebook RTMP Stream Disconnection

Hey there, let’s break down why your stream is cutting out after just a few seconds—there are a few key issues in your command and setup that are likely causing this.

Key Issues Identified

1. Invalid RTMP URL (Space in Stream Key)

Looking at your log, the output URL has a space: rtmp://live-api.facebook.com:80/rtmp/my key. RTMP URLs do not allow spaces, and this is almost certainly causing the Facebook server to reject the connection prematurely. Double-check your stream key and ensure it’s formatted correctly (no spaces, matches the key from your Facebook Live dashboard).

2. Mismatched Frame Rates

Your input FLV runs at 25fps, but you’re forcing the output to 30fps with -r 30. This makes FFmpeg duplicate frames to hit the higher frame rate, which can cause sync errors and trigger the server to drop the stream. Facebook’s RTMP server is strict about consistent timing, so mismatched frames are a common failure point.

3. Optional: Unnecessary Audio Transcoding

Your input audio is already MP3 at 22050Hz, which Facebook supports. Transcoding it to 44100Hz isn’t required, and adds extra processing that could introduce sync issues. If you don’t need the higher sample rate, you can skip this step entirely.

Fixed Command Example

Here’s a revised command that addresses these issues:

ffmpeg -re -i SampleM.flv \
  -acodec libmp3lame -b:a 128k \
  -pix_fmt yuv420p -profile:v baseline -s 426x240 \
  -bufsize 6000k -vb 400k -maxrate 1500k \
  -deinterlace -vcodec libx264 -preset veryfast -g 50 \
  -vsync vfr -f flv "rtmp://live-api.facebook.com:80/rtmp/your_valid_stream_key"

Changes Made:

  • Removed -r 30 and added -vsync vfr to preserve the input’s 25fps while maintaining smooth playback
  • Adjusted -g 50 (keyframe interval = 2x input frame rate, a standard for live streaming)
  • Fixed the RTMP URL to use a valid, space-free stream key
  • Removed -ar 44100 to keep the original audio sample rate (add it back only if you specifically need 44100Hz)

Additional Troubleshooting Steps

  • Test Local Transcoding First: Run the command without the RTMP output to save a local FLV file. If this file plays without issues, the problem is with the Facebook connection, not your input file or FFmpeg setup.
  • Get Full Logs: Your provided log is truncated. Re-run the command and capture the full output—look for errors like Connection reset by peer or server-specific error codes, which will give clearer clues.
  • Verify Facebook Stream Settings: Ensure your Facebook Live dashboard is set to accept the resolution, frame rate, and codec you’re sending (H.264 video + MP3/AAC audio is required).

内容的提问来源于stack exchange,提问作者Manjot Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:35:39