FFmpeg推流至Facebook RTMP服务器几秒后中断问题求助
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 30and added-vsync vfrto 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 44100to 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 peeror 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

