Save RTSP Stream to File with stream2file

Record RTSP video streams to MP4 or AVI files using Happytime stream2file. Configure continuous, timed, or segmented recording in stream2file.cfg.

Introduction

This guide shows you how to use Happytime stream2file to record an RTSP video stream (e.g., from an IP camera) to a local file on your computer.

The recording behavior is controlled by editing the stream2file.cfg configuration file.

Basic Workflow

  1. Download and install Happytime stream2file.
  2. Locate the stream2file.cfg configuration file.
  3. Edit the <stream2file> section with your stream details.
  4. Start the stream2file application.

Configuration Example

Below is a fully configured example of the stream2file.cfg file with explanations.

stream2file.cfg
<stream2file>
    <!-- RTSP stream URL (required) -->
    <url>rtsp://192.168.3.36/live</url>
    
    <!-- Authentication (if required) -->
    <user>admin</user>
    <pass>admin</pass>
    
    <!-- Save directory (leave empty for current directory) -->
    <savepath></savepath>
    
    <!-- Output file format: AVI or MP4 -->
    <filefmt>MP4</filefmt>
    
    <!-- Recording frame rate (0 = auto) -->
    <framerate>0</framerate>
    
    <!-- Max recording size in KB (0 = no limit) -->
    <recordsize>0</recordsize>
    
    <!-- Max recording time in seconds (0 = no limit) -->
    <recordtime>0</recordtime>
    
    <!-- Enable segmented recording (1 = on, 0 = off) -->
    <fragment>1</fragment>
    
    <!-- Duration of each segment in milliseconds -->
    <fragment_duration>5000</fragment_duration>
</stream2file>

Key Parameters Explained

  • Fragmented Recording: Set <fragment>1</fragment> to split recordings into smaller files (e.g., every 5 seconds with fragment_duration). Ideal for easier management and archiving.
  • Time-Limited: Use <recordtime>3600</recordtime> to record for exactly 1 hour.
  • Size-Limited: Use <recordsize>1048576</recordsize> to stop recording when the file reaches 1GB.
  • Authentication: Only include <user> and <pass> if your RTSP stream requires login.

Recording Scenarios

Continuous Recording: recordtime=0, recordsize=0 → Records until manually stopped.

Timed Recording: recordtime=600 → Records for 10 minutes then switch to new recording.

Segmented Recording: fragment=1, fragment_duration=60000 → Creates a new 1-minute MP4 file every minute.

Best Practices

  • Test First: Verify your RTSP URL works in VLC before configuring stream2file.
  • Disk Space: Ensure sufficient free space, especially for continuous recording.
  • File Format: Choose MP4 for better compatibility and smaller size, AVI for maximum compatibility with older systems.
  • Fragmentation: Use segmented recording for long-term surveillance to avoid huge single files.
  • Security: Store configuration files with passwords securely.