# Technical Documentation: streamaserver/streama

> ℹ️ **Provenance:** Multi-Tier Ingestion · [CodeWiki Reference](https://codewiki.google/github.com/streamaserver/streama)

### Overview (`README.md`)

# STREAMA



[](https://travis-ci.org/streamaserver/streama) 
[](https://github.com/streamaserver/streama/releases)
[](https://github.com/streamaserver/streama/blob/master/LICENSE.md) 
[](https://discord.gg/CJEHWX9)

  
Docs: https://docs.streama-project.com/  

Ever had a huge bookshelf full of shows and movies? Ever wanted to digitalize them, but didn't have a good way of organizing the files? Worry no more! Streama is your own personal Netflix for just such a purpose!

[](https://github.com/streamaserver/streama/wiki) 
[](https://streama.demo-version.net/) 
[](https://play.google.com/store/apps/details?id=dularion.streama) 

## Live-Demo
https://streama.demo-version.net/   
**credentials: username: demoUser | password: demoUser**  
Feel free to play around there as much as you like (everything is reset at night)  
We will keep this demo updated with our newest releases as they come, so that you can check out new features there first before deciding to deploy them in your own environments. 



## Donate
<span class="badge-patreon"><a href="https://www.patreon.com/user?u=7362340" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span>
<span class="badge-paypal"><a href="https://www.paypal.me/AntoniaEngfors" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-yellow.svg" alt="PayPal donate button" /></a></span>

If you want to donate to the developer via bitcoin use 17rCUEX6KYQ8ZM4w39ttEUL7SUDnGCpcWq  



## Table of contents:
- [Getting Started](#getting-started)
- [Downloads](#downloads)
- [The Application](#the-application)
  - [Settings](#settings)
  - [The Dashboard](#the-dashboard)
  - [The Player](#the-player)
  - [The Admin-Panel](#the-admin-panel)
  - [Accessing existing files](#accessing-existing-files)
  - [The Users](#the-users) 
- [Technical Details](#technical-details)
- [Changelog](#changelog)
- [Roadmap](#roadmap)
- [Known Issues](#known-issues)
- [Contributing](#contributing)
- [License](#license)

# Getting Started
- [Installation and first-time setup](https://docs.streama-project.com/getting-started/installing/)

If you have any issues getting started, feel free to [chat with us on Discord](https://discord.gg/CJEHWX9). We are more than happy to assist and then improve the docs accordingly. 

# Downloads
- **Stable and beta** versions see the GitHub [releases](https://github.com/streamaserver/streama/releases)

# The Application

### Settings


When you first run the application, you will be redirected to the settings page. Here you enter your desired upload directory for the video files, your [theMovieDb.org API key](https://www.themoviedb.org/documentation/api) and a different base URL if so desired (useful for remote hosting).

Once you made adjustments to any of the settings, make sure to validate the value before saving.
- For the API-Key, the validation checks against theMovieDb.org to see if you've entered a valid API-key.
- For the upload directory, the application checks if it has read/write permissions for it.

### The Dashboard


On the dashboard, a user can see their recently watched TV-shows and Movies and their progress (they can continue where they left off) as well start new shows and movies that they haven't yet seen. The "Continue Watching" Feature works by periodically updating the database (only while watching, of course!) with info about the currently watched Video and how far it has been seen.

If a Movie or Episode does not contain any video-files, it won't show up in the dashboard.

### The Player


The Streama-Player is (heavily) inspired by Netflix, so you get all the good stuff from there. For Shows, there is a "next episode" button and a handy episode/season browser. There are also the basics: volume-control, play/pause, and fullscreen. 
Later down the road I will add a feature to add subtitles and switch between video-files (for instance for different quality uploads). 
The player is HTML5-based and has only really been tested in Chrome so far.

##### The Episode Browser
I am especially proud of the Episode-Browser, which aims to function just like on Netflix. By default, the current video files season is selected. The user gets an overview of which other episodes there are in the season, how many seasons there are, and, as an added feature, the user sees all the added episodes, even if no video-files are added to them (thus greyed out).



### The Admin-Panel


One of the most important things to me was to make managing shows, movies, and episodes as easy and fun as possible. For this, I made heavy use of the API from [theMovieDatabase.org](https://www.themoviedb.org/), which auto-fills the episodes, shows and movies with useful information and great images. This eases the user's role in adding content.

For example, creating a new TV-show and the episodes for the first season looks something like this:



Uploading video-files for each episode is as easy as drag-and-drop!

  

### Accessing existing files
If you want to avoid uploading every file, use our new and improved "Local File" Feature instead. You can define a local directory (I use one directly in which I created symlinks to all my mounted drives) and then you can either use the local file browser for individual movies / tv-Shows or you can use the bulk-create feature. 

#### The local file browser
You can access the local file browser from any movie or TV-show (anywhere where you would otherwise upload a file). Note: You need to first define the local directory in the settings.



#### Bulk-Create from File
This MR addresses the issue "Batch Add Files #241".
Note: the TV-Show does not have to be present in order for this to work. Everything will be created by the backend. 

##### Running matcher & previewing the result


##### adding single matched file 


##### adding files in bulk



##### Customizing the Matcher
Just like in Emby or Kodi, the matcher-regex can be altered. The two defaults are 
**Movie**: `/^(?<Name>.*)[_.]\(\d{4}\).*/`  
**TvShow/Episode**: `/^(?<Name>.+)[._]S(?<Season>\d{2})E(?<Episode>\d{2,3}).*/`   

In order to customize the regex, just add the regex in the bottom of the application.yml like so:
```yml
streama:
  regex:
    movies: ^(?<Name>.*)[_.]\(\d{4}\).*
    shows: ^(?<Name>.+)[._]S(?<Season>\d{2})E(?<Episode>\d{2,3}).*

```


### The Users

Users can be invited and managed in the admin panel. By default, they are non-admins, meaning they can only view videos, not create them. You can make them admins with the press of a button. Since there is user-administration in place, I plan on expanding on this a lot! Another feature I want to add is the ability for users to add and administer some form of playlists. There is a lot of potentials to make this even better!

# Technical Details
This application is web-based, the server-side is written on [Grails 3](https://grails.org/) with [SpringSecurity](http://projects.spring.io/spring-security/) for login & user-handling. For all the front-end components, [AngularJS](https://angularjs.org/) is used and the player is completely HTML5-based. The application is essentially split into Grails for a REST-API, and AngularJS for the frontend.

Streama uses the [awesome API](https://www.themoviedb.org/documentation/api) from [theMovieDatabase](https://www.themoviedb.org) for all media-metadata.

# Changelog
Please refer to the description of each [release](https://github.com/streamaserver/streama/releases) or the git log.

# Roadmap
Streama is still very much a work-in-progress. We will be adding new features and bug-fixes often, but this is a hobby project for the core-contributors, so the time that we can spend on it is limited.

For all our feature and bug tracking, we use the [Issues Section](https://github.com/streamaserver/streama/issues). Streama's 'roadmap' is currently to work through the feature requests and improvements that are in the issue tracker.  Take a look at the milestones for what we intend to add for upcoming releases.


# Contributing
### Features, Improvements, and Bugfixes
Streama currently only has ~2-3 core-contributors so we are grateful for any extra contributions. Send through a Pull Request and we will review it ASAP.

If you're not sure what to work on, take a look at the [issues](https://github.com/streamaserver/streama/issues). There are lots to do!

### Translations
If you want to contribute a translation, please follow [the guide here](https://github.com/streamaserver/streama/wiki/Translating-the-app). 

# Known Issues
- There is no video-conversion currently, meaning you are reliant upon HTML5 browser compatibilities. Server-side conversion is on our roadmap. See Issue [#440](https://github.com/streamaserver/streama/issues/440)

# License
Streama is distributed under the terms of the MIT license.
See [LICENSE.md](https://github.com/streamaserver/streama/blob/master/LICENSE.md) for details.

---

### Convert Audio (`docs/convert-audio.md`)

# Converting Audio for Streama Compatibility

This guide explains how to convert audio tracks in video files for better streaming compatibility.

## Why Convert Audio?

Many video files use **EAC3** (Dolby Digital Plus) or **DTS** audio codecs that have poor browser/streaming support. Converting to **AAC** ensures compatibility with web players like Streama.

## Prerequisites

- ffmpeg installed (`brew install ffmpeg` on macOS)

## Step 1: Check Current Audio Format

```bash
ffprobe -v error -show_entries stream=index,codec_name,codec_type,channels:stream_tags=language -of json "video.mkv"
```

Look for the audio stream:
```json
{
  "index": 1,
  "codec_name": "eac3",
  "codec_type": "audio",
  "channels": 6,
  "tags": {
    "language": "eng"
  }
}
```

## Step 2: Convert Audio to AAC

### Basic Conversion (Preserves All Streams)

```bash
ffmpeg -i "input.mkv" \
  -map 0 \
  -c:v copy \
  -c:a aac -b:a 384k -ac 6 \
  -c:s copy \
  "output.mkv"
```

**Explanation:**
- `-map 0` copies all streams from input
- `-c:v copy` keeps video as-is (no re-encoding)
- `-c:a aac -b:a 384k` converts audio to AAC at 384 kbps
- `-ac 6` preserves 5.1 surround (6 channels)
- `-c:s copy` keeps subtitles as-is

### Stereo Downmix (Smaller File)

```bash
ffmpeg -i "input.mkv" \
  -map 0 \
  -c:v copy \
  -c:a aac -b:a 192k -ac 2 \
  -c:s copy \
  "output.mkv"
```

## Audio Codec Compatibility

| Codec | Browser Support | Recommendation |
|-------|-----------------|----------------|
| AAC | Excellent | Best for streaming |
| MP3 | Good | Legacy support |
| AC3 (Dolby) | Poor | Convert to AAC |
| EAC3 (DD+) | Poor | Convert to AAC |
| DTS | None | Convert to AAC |
| FLAC | Limited | Convert to AAC |
| Opus | Good | Modern alternative |

## Recommended Bitrates

| Channels | Quality | Bitrate |
|----------|---------|---------|
| Stereo (2.0) | Good | 128-192 kbps |
| Stereo (2.0) | High | 192-256 kbps |
| Surround (5.1) | Good | 256-384 kbps |
| Surround (5.1) | High | 384-512 kbps |

## In-Place Replacement

To replace the original file:

```bash
ffmpeg -i "video.mkv" -map 0 -c:v copy -c:a aac -b:a 384k -ac 6 -c:s copy "video.fixed.mkv"
mv -f "video.fixed.mkv" "video.mkv"
```

## Batch Processing

Convert all MKV files in a directory:

```bash
for f in *.mkv; do
  ffmpeg -i "$f" -map 0 -c:v copy -c:a aac -b:a 384k -c:s copy "${f%.mkv}.fixed.mkv" -y
  mv -f "${f%.mkv}.fixed.mkv" "$f"
done
```

## Troubleshooting

### Audio out of sync
Add `-async 1` to the ffmpeg command.

### "Discarding too many packets"
Try adding `-max_muxing_queue_size 1024`.

### File size increased significantly
Video was re-encoded. Ensure `-c:v copy` is present.

---

### Extract Subtitles (`docs/extract-subtitles.md`)

# Extracting Subtitles from Video Files

This guide explains how to extract subtitle tracks from MKV video files using ffmpeg.

## Prerequisites

- ffmpeg installed (`brew install ffmpeg` on macOS)

## Step 1: Analyze the Video File

First, check what subtitle tracks are available:

```bash
ffprobe -v error -show_entries stream=index,codec_name,codec_type:stream_tags=language,title -of json "video.mkv"
```

This outputs JSON showing all streams. Look for entries with `"codec_type": "subtitle"`.

Example output:
```json
{
  "index": 3,
  "codec_name": "subrip",
  "codec_type": "subtitle",
  "tags": {
    "language": "eng",
    "title": "English"
  }
}
```

## Step 2: Extract Subtitles

### Extract a Single Subtitle Track

Use the stream index from Step 1:

```bash
ffmpeg -i "video.mkv" -map 0:3 -c:s srt "output.srt" -y
```

- `-map 0:3` selects stream index 3 from input 0
- `-c:s srt` converts to SRT format
- `-y` overwrites output without prompting

### Extract Multiple Subtitle Tracks

Extract multiple tracks in one command:

```bash
ffmpeg -i "video.mkv" \
  -map 0:3 -c:s srt "video.English.srt" \
  -map 0:35 -c:s srt "video.Swedish.srt" \
  -y
```

## Common Subtitle Formats

| Codec | Extension | Notes |
|-------|-----------|-------|
| subrip | .srt | Most compatible, plain text |
| ass/ssa | .ass | Styled subtitles, converts to SRT |
| hdmv_pgs | .sup | Blu-ray image subs, cannot convert to text |
| dvd_subtitle | .sub | DVD image subs, cannot convert to text |

## Tips

- **Finding language codes**: Common codes are `eng` (English), `swe` (Swedish), `ger` (German), `fre` (French)
- **Forced subtitles**: These only show when foreign languages are spoken (marked as "forced" in title)
- **SDH subtitles**: Include descriptions for deaf/hard of hearing viewers

## Troubleshooting

### "Stream not found"
The stream index may have changed. Re-run ffprobe to verify.

### Image-based subtitles
PGS/VOB subtitles are images, not text. You'll need OCR tools like SubtitleEdit to convert them.

---

### Sample Application.Yml (`docs/sample_application.yml`)

# Place this file next to the streama-[version].war and rename to application.yml with your own settings
environments:
    production:
        dataSource:
#            driverClassName:  'com.mysql.jdbc.Driver'
#            url: jdbc:mysql://localhost/streama
#            username: root
#            password:
            driverClassName:  'org.h2.Driver'
            url: jdbc:h2:./streama;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
            username: root
            password:
        server:
            port: 8080

streama:
  regex:
    movies: ^(?<Name>.*)[._ ]\(\d{4}\).*
    shows:
      - ^(?<Name>.+)[._ ][Ss](?<Season>\d{2})[Ee](?<Episode>\d{2,3}).*    # example:  "House.MD.S03E04.h264.mp4"
      - ^(?<Name>.+)[._ ](?<Season>\d{1,2})x(?<Episode>\d{2,3}).*         # example:  "House.MD.03x04.h264.mp4"
      - ^(?<Season>\d{2})-(?<Episode>\d{2,3})-(?<Name>.*?)-.*             # example:  "02-05-Dr. House-Tanz_ums_Feuer-cineonws.mp4"
      - ^(?<Name>.*?)(?<Episode>\d{1,3})x(?<Season>\d{2}).*               # example:  "Castle4x06DaemonsWebdl480pOktober242011rC.mkv(jkuzt).mp4"

---

### Plans 2026 01 03 Audio Transcoding Design (`docs/plans/2026-01-03-audio-transcoding-design.md`)

# On-the-fly Audio Transcoding Feature Design

## Overview

Add on-the-fly audio transcoding to Streama to convert incompatible audio codecs (EAC3, AC3) to browser-compatible AAC format. FFmpeg is optional and the feature is disabled if not installed.

## Architecture

```
┌─────────────────────────────────────────────────────────────────┐
│                        STREAMA SERVER                           │
├─────────────────────────────────────────────────────────────────┤
│  Settings                                                       │
│  ├── ffmpegPath: auto-detected or manual                       │
│  ├── ffprobePath: auto-detected or manual                      │
│  ├── transcodingEnabled: boolean (default false)               │
│  └── transcodeCacheDir: path for cached audio files            │
├─────────────────────────────────────────────────────────────────┤
│  File Domain (extended)                                         │
│  ├── audioCodec: String (eac3, aac, ac3, etc.)                 │
│  ├── needsTranscoding: Boolean                                  │
│  └── transcodedAudioPath: String (path to cached .aac)         │
├─────────────────────────────────────────────────────────────────┤
│  New Services                                                   │
│  ├── FfmpegService        - detect, probe, transcode            │
│  └── TranscodingService   - orchestrate, queue, cache mgmt      │
├─────────────────────────────────────────────────────────────────┤
│  Cache Directory                                                │
│  └── {uploadDir}/transcode-cache/                               │
│      └── {sha256}.aac     - transcoded audio streams            │
└─────────────────────────────────────────────────────────────────┘
```

## User Flows

### Flow 1: Admin enables transcoding
1. Admin goes to Settings
2. System auto-detects FFmpeg in PATH
3. If found, shows "FFmpeg detected at /usr/bin/ffmpeg"
4. If not found, shows manual path input with install instructions
5. Admin enables "Audio Transcoding"
6. System validates FFmpeg works

### Flow 2: File added to video
1. User adds file to Movie/Episode (upload, local file, or existing)
2. If transcoding enabled, system probes file with ffprobe
3. Stores audioCodec in File domain
4. Sets needsTranscoding = true if codec is incompatible (eac3, ac3, dts)

### Flow 3: User plays video needing transcoding
1. User clicks play on video
2. Frontend requests video
3. If file.needsTranscoding && !file.transcodedAudioPath:
   - Return 202 Accepted with transcoding status
   - Frontend shows "Preparing audio..." spinner
   - Server transcodes audio only to AAC (ffmpeg -vn -c:a aac)
   - Stores result in cache directory
   - Updates file.transcodedAudioPath
4. Once ready, serve video with muxed transcoded audio
5. Subsequent plays use cached audio instantly

### Flow 4: Admin pre-transcodes
1. Admin goes to Transcoding admin page
2. Sees list of files needing transcoding
3. Can click "Pre-transcode All" or individual files
4. Background job processes queue
5. Status updates shown in UI

## Technical Implementation

### New Settings
```groovy
[settingsKey: 'FFmpeg Path', name: 'ffmpeg_path', settingsType: 'string', value: '']
[settingsKey: 'FFprobe Path', name: 'ffprobe_path', settingsType: 'string', value: '']
[settingsKey: 'Enable Audio Transcoding', name: 'transcoding_enabled', settingsType: 'boolean', value: 'false']
```

### File Domain Changes
```groovy
class File {
  // ... existing fields ...
  String audioCodec        // detected codec (aac, eac3, ac3, dts, etc.)
  Boolean needsTranscoding // true if browser-incompatible
  String transcodedAudioPath // path to cached .aac file
}
```

### FfmpegService
```groovy
class FfmpegService {
  // Auto-detect ffmpeg/ffprobe in PATH
  Map detectFfmpeg()

  // Probe file for audio codec
  String probeAudioCodec(String filePath)

  // Check if codec needs transcoding
  boolean needsTranscoding(String codec)

  // Transcode audio only to AAC
  String transcodeAudioToAac(String inputPath, String outputPath)

  // Mux original video with transcoded audio on-the-fly
  void streamMuxedVideo(OutputStream output, String videoPath, String audioPath, long rangeStart, long rangeEnd)
}
```

### TranscodingService
```groovy
class TranscodingService {
  // Get cache path for file
  String getCachePath(File file)

  // Check if transcoded version exists
  boolean hasTranscodedAudio(File file)

  // Transcode file (blocking)
  File transcodeFile(File file)

  // Queue file for transcoding
  void queueForTranscoding(File file)

  // Get transcoding status
  Map getTranscodingStatus(File file)

  // Pre-transcode all pending files
  void transcodeAllPending()
}
```

### FileController Changes
```groovy
def serve() {
  // ... existing auth checks ...

  if (file needs transcoding) {
    if (no cached audio) {
      // Return 202 with status, trigger transcoding
      return [status: 'transcoding', progress: transcodingService.getProgress(file)]
    }
    // Serve muxed video+audio
    ffmpegService.streamMuxedVideo(response.outputStream, videoPath, transcodedAudioPath, rangeStart, rangeEnd)
  } else {
    // Existing direct serve logic
  }
}
```

### New TranscodingController
```groovy
class TranscodingController {
  // Get status of FFmpeg detection
  def status()

  // Get list of files needing transcoding
  def pending()

  // Trigger transcoding for a file
  def transcode(File file)

  // Trigger transcoding for all pending
  def transcodeAll()

  // Get progress of current transcoding
  def progress(File file)
}
```

### Frontend Changes

#### Player Service
- Check for 202 response when loading video
- Show transcoding spinner with progress
- Poll for completion
- Auto-reload video when ready

#### Settings UI
- New section for "Audio Transcoding"
- FFmpeg status indicator (detected/not found)
- Manual path override
- Enable/disable toggle
- Install instructions link

#### Admin Transcoding Page (optional)
- List of files needing transcoding
- Current queue status
- Pre-transcode button

## Browser-compatible vs Incompatible Codecs

**Compatible (no transcoding needed):**
- aac
- mp3
- opus
- vorbis
- flac

**Incompatible (needs transcoding):**
- eac3 (Dolby Digital Plus)
- ac3 (Dolby Digital)
- dts
- truehd
- pcm_*

## FFmpeg Commands

**Probe audio codec:**
```bash
ffprobe -v quiet -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 input.mkv
```

**Extract and transcode audio to AAC:**
```bash
ffmpeg -i input.mkv -vn -c:a aac -b:a 384k output.aac
```

**Mux video with new audio (for playback):**
```bash
ffmpeg -i input.mkv -i transcoded.aac -map 0:v -map 1:a -c:v copy -c:a copy -f mp4 -movflags frag_keyframe+empty_moov pipe:1
```

## Implementation Order

1. Add File domain fields + migration
2. Create Settings entries
3. Implement FfmpegService (detect, probe, transcode)
4. Implement TranscodingService (orchestrate, cache)
5. Modify VideoService.addLocalFile to probe on attach
6. Modify FileController.serve for transcoded playback
7. Create TranscodingController
8. Add settings UI for FFmpeg config
9. Add player transcoding spinner
10. Add admin transcoding UI (optional)

---

--- METRICS ---
- Files Extracted: 5
- Estimated Token Budget: ~5584 tokens
- Canonical Reference: https://codewiki.google/github.com/streamaserver/streama
