Skip to content

davidyang013/stream-nas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stream-NAS

Stream-NAS is a lightweight, feature-rich media streaming server designed specifically for Network Attached Storage (NAS) systems. It provides a clean web-based interface for browsing and streaming videos from multiple directories with support for thumbnails, searching, and secure access.

Features

  • 🎬 Direct Video Streaming: Stream videos directly in your browser with native HTML5 player
  • 🖼️ Automatic Thumbnails: Preview thumbnails generated from video keyframes
  • 📁 Multi-Directory Support: Organize videos in multiple directories with custom names
  • 🔍 Search Functionality: Quickly find videos by name across all libraries
  • 🔒 Secure Access: Optional HTTPS and admin authentication for private content
  • 📱 Responsive Design: Works seamlessly on mobile, tablet, and desktop devices
  • 🌐 WebDAV Support: Browse and manage files with any WebDAV client
  • 🎛️ Admin Panel: Configure settings through an intuitive web interface

Security Recommendations

This application is primarily designed for use on a local network. When exposing to external networks or the internet:

  1. Always enable HTTPS for encrypted connections
  2. Enable admin authentication for private content
  3. Consider using a reverse proxy with additional security features
  4. Be aware of potential security risks related to exposing media content
  5. Ensure you have rights to share any media content

Quick Start

Option 1: Download and Run

  1. Download the latest release from the Releases page
  2. Extract the archive
  3. Run the executable:
    ./stream

Configuration

You can configure the server by editing the config.json file. Here are the available options:

Config File Options

| Option                | Description                                                                                                 | Default Value   |
|-----------------------|-------------------------------------------------------------------------------------------------------------|-----------------|
| videoDirectories      | List of directories where videos are stored.                                                                | []              |
| port                  | Port number for the server.                                                                                 | "8000"          |
| enableThumbnails      | Enable thumbnail generation for videos.                                                                     | true            |
| logToFile             | Enable logging to a file.                                                                                   | true            |
| logLevel              | Logging level (debug, info, warn, error, fatal).                                                             | "info"          |          
| enableHTTPS           | Enable HTTPS for secure connections.                                                                         | false           |
| httpsPort             | Port number for HTTPS.                                                                                       | "443"           |
| certFile              | Path to the SSL certificate file.                                                                            | "cert/server.crt" |
| keyFile               | Path to the SSL key file.                                                                                     | "cert/server.key" |
| redirectToHTTPS       | Redirect HTTP requests to HTTPS.                                                                             | true            |
| thumbnailQuality      | Quality of generated thumbnails (1-5).                                                                       | 2               |
| enableWebDAV          | Enable WebDAV support.                                                                                       | false           |
| adminAuth             | Admin authentication settings.                                                                               | { enabled: false, username: "admin", passwordHash: "", sessionTimeout: 86400 } |

Command Line Options

| Option                | Description                                                                                                 | Default Value   |
|-----------------------|-------------------------------------------------------------------------------------------------------------|-----------------|
| --config              | Path to the configuration file.                                                                             | "config.json"   |
| --generate-cert       | Generate a self-signed SSL certificate and key.                                                              | false           |
| --cert-file           | Path to the SSL certificate file.                                                                            | "cert/server.crt" |
| --key-file            | Path to the SSL key file.                                                                                     | "cert/server.key" |

Example config.json:

{
  "port": "8000",
  "videoDirectories": [
    {
      "path": "videos",
      "public": true,
      "name": "Public Videos"
    },
    {
      "path": "/path/to/private/videos",
      "public": false,
      "name": "Private Collection"
    }
  ],
  "enableHTTPS": false,
  "httpsPort": "8443",
  "certFile": "cert/server.crt",
  "keyFile": "cert/server.key",
  "redirectToHTTPS": true,
  "logLevel": "info",
  "logToFile": true,
  "enableThumbnails": true,
  "thumbnailQuality": 2,
  "enableWebDAV": false,
  "adminAuth": {
    "enabled": false,
    "username": "admin",
    "passwordHash": "",
    "sessionTimeout": 86400
  }
}

Setting Up HTTPS

To enable HTTPS, you need to generate an SSL certificate. You can use the --generate-cert flag to generate a self-signed certificate.

./stream --generate-cert

This will generate a self-signed certificate and key in the cert directory. You can also provide your own SSL certificate and key using the --cert-file and --key-file flags.

./stream --cert-file cert/server.crt --key-file cert/server.key

Make sure to replace cert/server.crt and cert/server.key with the paths to your SSL certificate and key.

Reverse Proxy Configuration

To use a reverse proxy, you can configure your domain as follows: Caddy example(automatically redirects to HTTPS):

yourdomain.com {
    reverse_proxy localhost:8000
}

To use Nginx as a reverse proxy with HTTPS, you can configure your domain as follows:

server {
    listen 443 ssl;
    server_name yourdomain.com;
    
    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
    
    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Thumbnails and Video Support

The server supports various video formats, including MP4, AVI, MOV, and more. Thumbnails are generated from random keyframes in videos.

Supported Video Formats

The server supports the following video formats:

| File Extension | MIME Type |
|----------------|-----------|
| .mp4           | video/mp4 |
| .avi           | video/x-msvideo |
| .mov           | video/quicktime |
| .wmv           | video/x-ms-wmv |
|.flv           | video/x-flv |
|.webm          | video/webm |
|.mkv           | video/x-matroska |
|.3gp           | video/3gpp |
|.3g2           | video/3gpp2 |
|.ts            | video/mp2t |
|.mts           | video/mp2t |
|.m2ts          | video/mp2t |  

Thumbnail Generation

Thumbnails are automatically generated using FFmpeg. The system:

  • Extracts a random keyframe between 10%-90% of video duration
  • Creates a 640px wide thumbnail
  • Caches thumbnails to avoid regeneration
  • Serves thumbnails as base64-encoded data URI

To use this feature, ensure FFmpeg is installed on your system:

sudo apt-get install ffmpeg

#macOS
brew install ffmpeg

#Windows
#Download from https://ffmpeg.org/download.html

#Chocolatey
choco install ffmpeg

Dependencies

The server uses the following dependencies:

  • Go 1.16+
  • Caddy (for reverse proxy configuration)
  • FFmpeg (for thumbnail generation)
  • HTML5 Video Player
  • WebDAV Protocol

Project Structure

stream/
├── cert/                  # SSL certificates for HTTPS
├── cmd/
│   └── stream/
│       └── main.go        # Main application entry point
├── data/                  # Storage for cache files
├── logs/                  # Application logs
├── pkg/                   # Application packages
│   ├── api/               # HTTP API handlers
│   ├── auth/              # Authentication
│   ├── config/            # Configuration
│   ├── logging/           # Logging
│   ├── media/             # Media processing
│   ├── security/          # Security utilities
│   └── server/            # HTTP server
├── static/                # Static web files
├── templates/             # HTML templates
├── videos/                # Default video directory
├── build.sh               # Build script
├── config.json            # Configuration file
└── README.md              # Documentation

Troubleshooting

Common issues and solutions:

  • FFmpeg not installed: Ensure FFmpeg is installed on your system.
  • Thumbnails not generating: Check if FFmpeg is installed and accessible.
  • WebDAV not working: Ensure your WebDAV client is configured correctly.
  • HTTPS not working: Ensure your SSL certificate and key are configured correctly.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

stream nas is a gadget that integrated home videos

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors