Why Save RTMP Streams?
Saving an RTMP stream to a local file is essential for scenarios requiring persistent storage of live video feeds. This process, often called "recording" or "archiving," enables:
- Video Surveillance: Continuously record camera feeds for security and monitoring purposes.
- Live Stream Archiving: Keep a permanent copy of your live broadcasts for replay or compliance.
- Content Review: Analyze recorded footage for quality control or incident review.
- Data Backup: Create backups of valuable streaming content.
This guide shows you how to use Happytime stream2file to reliably capture and store RTMP streams on your server.
Configuration Overview
Configure the recording by editing the stream2file.cfg file. The <stream2file> node contains all settings for a single recording task.
Basic Recording Configuration
<stream2file>
<url>rtmp://192.168.3.36/myapp/live</url>
<user>admin</user>
<pass>admin</pass>
<savepath>C:\Recordings\Camera1\</savepath>
<filefmt>MP4</filefmt>
<framerate>0</framerate>
<recordsize>0</recordsize>
<recordtime>0</recordtime>
<fragment>1</fragment>
<fragment_duration>5000</fragment_duration>
</stream2file>
Detailed Configuration Parameters
1. Source Stream (<url>)
The RTMP stream address to be recorded. Example: rtmp://server/app/stream
2. Authentication (<user>, <pass>)
If your RTMP source requires authentication, provide the username and password here.
3. Output Settings
| Parameter | Description | Recommended Value |
|---|---|---|
<savepath> |
Directory path where the recorded files will be saved. Ensure the directory exists and has write permissions. | C:\Recordings\ or /var/media/ |
<filefmt> |
Output file format: MP4 or AVI. MP4 is recommended for better compatibility and smaller file size. |
MP4 |
<framerate> |
Recording frame rate (fps). Use 0 to automatically detect from the source stream. |
0 |
4. Recording Duration & Size Limits
Set limits to manage disk space usage. A value of 0 means no limit.
| Parameter | Description | Unit |
|---|---|---|
<recordsize> |
Maximum recording size per file. When reached, recording stops or a new file starts (if fragmentation is enabled). | Kilobytes (KB) |
<recordtime> |
Maximum recording time per file. When reached, recording stops or a new file starts. | Seconds |
5. Fragmented Recording (<fragment>)
Enable fragmented output for MP4 files. This creates multiple smaller files instead of one large file, which is beneficial for:
- Reliability: If a recording session is interrupted, only the last fragment may be lost.
- Management: Easier to handle, back up, and delete individual segments.
- Playback: Allows viewing of completed segments while recording continues.
| Parameter | Description | Value |
|---|---|---|
<fragment> |
Enable fragment mode: 1 = Enabled, 0 = Disabled. |
1 |
<fragment_duration> |
Duration of each fragment in milliseconds. Common values: 300000 (5 minutes), 1800000 (30 minutes). | Milliseconds |
Complete Configuration Example
A full stream2file.cfg setup for 24/7 surveillance with 5-minute MP4 fragments.
<stream2file>
<url>rtmp://camera-server.com/live/front_door</url>
<user>surv_user</user>
<pass>secure_pass_123</pass>
<savepath>/mnt/nas/camera_archive/</savepath>
<filefmt>MP4</filefmt>
<framerate>0</framerate>
<recordsize>0</recordsize>
<recordtime>3600</recordtime>
<fragment>1</fragment>
<fragment_duration>300000</fragment_duration> <!-- 5 minutes -->
</stream2file>
Best Practices
- Use MP4 Format: MP4 offers better compression and wider compatibility than AVI.
- Enable Fragmentation: Highly recommended for long-term recordings to improve reliability and file management.
- Monitor Disk Space: Regularly check available storage, especially when recording continuously.
- Secure Your Paths: Ensure the
savepathis on a reliable drive with sufficient capacity and proper permissions. - Automate Cleanup: Implement scripts to automatically delete old recordings based on retention policies.
- Test First: Always test your configuration with a short stream before starting long-term recording.