Skip to content

hoangtk0100/stauvise

Repository files navigation

STAUVISE

GO - An Audio/Video Streaming Service

This service implements these main features:

  1. Stream media files.
  2. Create and manage users.
  3. Create and manage categories.
  4. Create and manage videos.

Supported transport protocols

  • HLS
  • RTMP
  • FLV

Supported file extensions

  • Video Formats:

    • mp4 (MPEG-4 Part 14)
    • mov (QuickTime Movie)
    • avi (Audio Video Interleave)
    • mkv (Matroska Video)
    • flv (Flash Video)
    • webm (WebM Video)
  • Audio Formats:

    • mp3 (MPEG Audio Layer III)
    • aac (Advanced Audio Coding)
    • wav (Waveform Audio File Format)
    • flac (Free Lossless Audio Codec)
    • ogg (Ogg Vorbis Audio)
  • Other Formats:

    • ts (Transport Stream)
    • m2ts (Blu-ray BDAV MPEG-2 Transport Stream)
    • 3gp (3GPP Multimedia File)
    • wmv (Windows Media Video)

Infrastructure:

  • App context: AppContext (library packages common components)
  • ffmpeg: ffmpeg
  • Token authentication: PASETO
  • Database migrations: golang-migrate
  • Generate CRUD operations from SQL: GORM
  • Database: PostgreSQL
  • Database documentation: dbdocs
  • Generate SQL schema: dbml2sql
  • Web framework: Gin
  • Containerize: docker | docker compose

1. Quick start

  • Setup ENV:

    make build
    make outenv     # Show ENV on terminal
    make outenvfile # Extract ENV into .env
    
    # Replace ENV variables in `.env` with your configuration
  • Run in background (all in one):

    make up
  • Run on current terminal:

    # Start PostgreSQL database
    make updb
    
    # Run server
    make server

2. Setup local development

Install tools

  • Migrate

    brew install golang-migrate
  • DB Docs

    npm install -g dbdocs
    dbdocs login
    
  • DBML CLI

    npm install -g @dbml/cli
    dbml2sql --version
  • ffmpeg

    brew install ffmpeg
  • Swagger

    go install github.com/swaggo/swag/cmd/swag@latest

Setup infrastructure

  • Start PostgreSQL container:

    make updb
  • Run DB migration up all versions:

    make migrateup
  • Run DB migration up 1 version:

    make migrateup1
  • Run DB migration down all versions:

    make migratedown
  • Run DB migration down 1 version:

    make migratedown1

Documentation

  • Generate DB documentation:

    make dbdocs
  • Access the DB documentation at THIS ADDRESS.

How to generate code

  • List ENV variables on terminal:

    make outenv
  • Extract ENV variables into .env file:

    make outenvfile
  • Generate schema SQL file with DBML:

    make dbschema
  • Create a new DB migration:

    make new_migration name=<migration_name>
  • Generate swagger documents:

    make swagger

How to run

  • Run server on terminal:

    make server
  • Run containers (verbose mode):

    make upv
  • Run containers (detach mode):

    make up
  • Remove containers:

    make down

3. API Docs - Swagger | Postman Collection

Method Path Description Notes
POST /api/v1/users/register Register a new user Receives user details
POST /api/v1/auth/login Login to get access token Receives username and password
GET /api/v1/users/me Retrieve user profile Requires valid access token
POST /api/v1/categories Create a new category Receives category details
GET /api/v1/categories Retrieve all categories Requires valid access token
GET /api/v1/videos/streams/{id}/{id}.m3u8 Stream video segments Requires valid video ID
GET /api/v1/videos Retrieve videos Supports pagination
GET /api/v1/videos/{id} Retrieve video by ID Requires valid video ID
GET /api/v1/videos/{id}/segments Retrieve video segments Requires valid video ID, supports pagination
POST /api/v1/videos Create a new video Receives video details and file

4. Notes

  • To test streaming media use: HLS Demo
  • Input format: {host}/api/v1/videos/streams/{video_path} (video_path: "path" in getting video details response)
  • For example: http://localhost:8080/api/v1/videos/streams/1692794790339777000/1692794790339777000.m3u8

About

An audio/ video streaming service in GO

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published