Keywords: FFmpeg | RTSP | Video Streaming
Abstract: This article provides a comprehensive guide to RTSP streaming using FFmpeg, focusing on FFserver configuration and modern alternatives. It covers RTSP protocol fundamentals, FFserver configuration file setup, streaming parameter optimization, and client playback settings. The discussion includes advantages of RTSP over UDP streaming, such as support for pause, fast-forward, and other control functions. Practical code examples and configuration instructions help readers quickly set up RTSP streaming environments.
Fundamentals of RTSP Streaming
RTSP (Real Time Streaming Protocol) is a network control protocol specifically designed for controlling streaming media servers. Compared to UDP streaming, RTSP offers richer control functions including play, pause, record operations, making it particularly suitable for mobile device playback.
Detailed FFserver Configuration
FFserver is the streaming server component in the FFmpeg suite. Although no longer maintained in newer versions, its configuration methods remain valuable for reference. Below is a complete configuration example:
HTTPPort 1234
RTSPPort 1235
<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 2M
ACL allow 127.0.0.1
</Feed>
<Stream test1.sdp>
Feed feed1.ffm
Format rtp
Noaudio
VideoCodec libx264
AVOptionVideo flags +global_header
AVOptionVideo me_range 16
AVOptionVideo qdiff 4
AVOptionVideo qmin 10
AVOptionVideo qmax 51
ACL allow 192.168.0.0 192.168.255.255
</Stream>
FFmpeg Encoding and Stream Pushing
Using FFmpeg to encode video files and push to FFserver:
ffmpeg -i space.mp4 -vcodec libx264 -tune zerolatency -crf 18 http://localhost:1234/feed1.ffm
Key parameter explanations:
-vcodec libx264: Use H.264 encoder-tune zerolatency: Optimize for low-latency streaming-crf 18: Constant rate factor, lower values mean higher quality
Client Playback Configuration
After configuration, players like VLC can access the stream using:
rtsp://192.168.0.xxx:1235/test1.sdp
Modern Alternative Solutions
Since FFserver is no longer maintained, consider these alternatives:
ffmpeg -re -stream_loop -1 -i test.mp4 -f rtsp -rtsp_transport tcp rtsp://localhost:8554/live.stream
Combined with RTSP simple servers (like rtsp-simple-server) can provide more stable service.
Common Issues and Solutions
Input/output errors typically stem from network configuration or protocol support issues. Ensure:
- Firewall allows communication on relevant ports
- Correct transport protocol (TCP or UDP) is used
- SDP file is properly configured
Performance Optimization Recommendations
Optimizations for mobile devices:
- Use appropriate video resolution and bitrate
- Enable hardware-accelerated encoding
- Configure suitable buffer sizes
- Consider network bandwidth limitations