-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LinuxSploit
committed
Oct 13, 2024
0 parents
commit 7a750a3
Showing
14 changed files
with
1,332 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_/* | ||
.env | ||
workflow.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Use an official Golang image as the base | ||
FROM golang:1.22.5-alpine | ||
|
||
# Install dependencies for Go, FFmpeg, and build tools | ||
RUN apk add --no-cache bc ffmpeg bash gcc g++ libc-dev libwebp libwebp-tools libwebp-dev wget curl vim git | ||
|
||
# for storage | ||
RUN mkdir -p /storage/MediaBucket/videos/ | ||
RUN mkdir -p /storage/MediaBucket/hls/ | ||
RUN mkdir -p /storage/MediaBucket/images/ | ||
RUN mkdir -p /storage/MediaBucket/thumbnail/ | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the Go module files and download dependencies | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
RUN go mod tidy | ||
RUN go get -u github.com/kolesa-team/go-webp | ||
|
||
# Build the Go application | ||
RUN go build -o server . | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 8080 | ||
|
||
# Command to run the server | ||
CMD ["./server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
# MediaBucket Video Transcoding Server | ||
|
||
 | ||
|
||
**MediaBucket** is a robust and scalable video transcoding server built with Go. It offers resumable file uploads, automatic video transcoding, and efficient media serving, including thumbnails for both videos and images. Additionally, MediaBucket provides an image upload bucket with automatic thumbnail generation, ensuring seamless media management for your applications. | ||
|
||
## Table of Contents | ||
|
||
- [Features](#features) | ||
- [Prerequisites](#prerequisites) | ||
- [Installation](#installation) | ||
- [Configuration](#configuration) | ||
- [Usage](#usage) | ||
- [API Endpoints](#api-endpoints) | ||
- [Directory Structure](#directory-structure) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
- [Acknowledgements](#acknowledgements) | ||
|
||
## Features | ||
|
||
- **Resumable File Uploads**: Supports TUS protocol for reliable and resumable uploads of large video and image files. | ||
- **Video Transcoding**: Automatically transcodes uploaded videos into HLS format for adaptive streaming. | ||
- **Thumbnail Generation**: | ||
- **Videos**: Generates high quality thumbnails and 500px width thumbnails for each uploaded video. | ||
- **Images**: Generates 500px width thumbnails for each uploaded image. | ||
- **Media Serving**: | ||
- Serves HLS video streams. | ||
- Provides access to video and image thumbnails. | ||
- Hosts an image upload bucket for serving image files. | ||
- **Demo Pages**: | ||
- `/video-demo`: Demonstrates video upload functionality. | ||
- `/image-demo`: Demonstrates image upload functionality. | ||
- **CORS Middleware**: Ensures secure and controlled access to media resources. | ||
|
||
## Prerequisites | ||
|
||
Before setting up MediaBucket, ensure you have the following installed on your system: | ||
|
||
- **Go**: Version 1.16 or higher. [Download Go](https://golang.org/dl/) | ||
- **FFmpeg**: Required for video transcoding. [Install FFmpeg](https://ffmpeg.org/download.html) | ||
- **Git**: For cloning the repository. [Download Git](https://git-scm.com/downloads) | ||
|
||
## Configuration | ||
|
||
MediaBucket uses environment variables for configuration. Below are the essential variables you need to set in your `.env` file: | ||
|
||
| Variable | Description | Example Value | | ||
| ----------------- | ----------------------------------------------- | ------------------------- | | ||
| `ServerURL` | Base URL of the server | `http://example.com` | | ||
| `VideoUploadPath` | Endpoint path for video uploads | `/video/` | | ||
| `ImageUploadPath` | Endpoint path for image uploads | `/image/` | | ||
|
||
**Example `.env` File:** | ||
|
||
```env | ||
ServerURL=http://example.com | ||
VideoUploadPath=/video/ | ||
ImageUploadPath=/image/ | ||
``` | ||
|
||
## Usage | ||
|
||
Once the service is up and running, you can interact with it through the following functionalities: | ||
|
||
### 1. Resumable Video Upload | ||
|
||
Use the `/video/` endpoint to upload videos. The server supports resumable uploads, allowing you to pause and resume uploads as needed. | ||
|
||
### 2. Resumable Image Upload | ||
|
||
Use the `/image/` endpoint to upload images. Similar to video uploads, image uploads are resumable. | ||
|
||
### 3. Accessing Transcoded Videos | ||
|
||
Transcoded HLS video streams are available at the `/hls/` endpoint. For example: | ||
|
||
``` | ||
http://example.com/hls/{video_id}/master.m3u8 | ||
``` | ||
|
||
### 4. Accessing Thumbnails | ||
|
||
- **Video Thumbnails**: Accessible via `/thumbnail/`. | ||
|
||
``` | ||
http://example.com/thumbnail/{video_id}-500w.webp | ||
``` | ||
|
||
- **Image Thumbnails**: Automatically generated with a width of 500px and accessible via the same endpoint. | ||
|
||
``` | ||
http://example.com/thumbnail/{image_id}-500w.webp | ||
``` | ||
|
||
### 5. Demo Pages | ||
|
||
- **Video Upload Demo**: [http://example.com/video-demo](http://example.com/video-demo) | ||
- **Image Upload Demo**: [http://example.com/image-demo](http://example.com/image-demo) | ||
|
||
These pages provide a user-friendly interface to test upload functionalities. | ||
|
||
## API Endpoints | ||
|
||
### Upload Endpoints | ||
|
||
- **Video Upload** | ||
|
||
``` | ||
POST /video/ | ||
``` | ||
|
||
- **Description**: Upload video files using the TUS protocol. | ||
- **Headers**: | ||
- `Content-Type: application/offset+octet-stream` | ||
- **Parameters**: Handled by TUS protocol. | ||
|
||
- **Image Upload** | ||
|
||
``` | ||
POST /image/ | ||
``` | ||
|
||
- **Description**: Upload image files using the TUS protocol. | ||
- **Headers**: | ||
- `Content-Type: application/offset+octet-stream` | ||
- **Parameters**: Handled by TUS protocol. | ||
|
||
### Media Access | ||
|
||
- **HLS Video Streams** | ||
|
||
``` | ||
GET /hls/{video_id}/master.m3u8 | ||
``` | ||
|
||
- **Description**: Access the HLS stream of the transcoded video. | ||
|
||
- **Thumbnails** | ||
|
||
``` | ||
GET /thumbnail/{media_id}-500w.webp | ||
``` | ||
|
||
- **Description**: Retrieve the thumbnail image for the specified media. | ||
|
||
### Demo Pages | ||
|
||
- **Video Upload Demo** | ||
|
||
``` | ||
GET /video-demo | ||
``` | ||
|
||
- **Description**: Serves a web page demonstrating video upload functionality. | ||
|
||
- **Image Upload Demo** | ||
|
||
``` | ||
GET /image-demo | ||
``` | ||
|
||
- **Description**: Serves a web page demonstrating image upload functionality. | ||
|
||
## Directory Structure | ||
|
||
``` | ||
/ | ||
├── app/ | ||
│ ├── main.go # Main application entry point | ||
│ ├── go.mod # Go module file | ||
│ └ * # rest of the application code | ||
├── storage/ | ||
│ ├── MediaBucket/ | ||
│ │ ├── videos/ # Original video uploads | ||
│ │ ├── images/ # Original image uploads | ||
│ │ ├── hls/ # Transcoded HLS streams | ||
│ │ └── thumbnail/ # Generated thumbnails | ||
└── templates/ | ||
├── video-demo.html # Video upload demo page | ||
└── image-demo.html # Image upload demo page | ||
``` | ||
|
||
## Contributing | ||
|
||
We welcome contributions to enhance MediaBucket! Please follow these steps: | ||
|
||
1. **Fork the Repository** | ||
|
||
Click the "Fork" button at the top right of the repository page. | ||
|
||
2. **Create a Feature Branch** | ||
|
||
```bash | ||
git checkout -b feature/YourFeature | ||
``` | ||
|
||
3. **Commit Your Changes** | ||
|
||
```bash | ||
git commit -m "Add your message here" | ||
``` | ||
|
||
4. **Push to Your Fork** | ||
|
||
```bash | ||
git push origin feature/YourFeature | ||
``` | ||
|
||
5. **Open a Pull Request** | ||
|
||
Navigate to the original repository and click "Compare & pull request." | ||
|
||
Please ensure your code follows the project's coding standards and includes relevant tests. | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT License](LICENSE). | ||
|
||
## Acknowledgements | ||
|
||
- [TUS Protocol](https://tus.io/) for providing a reliable resumable upload protocol. | ||
- [FFmpeg](https://ffmpeg.org/) for powerful multimedia processing capabilities. | ||
- [Go](https://golang.org/) for being the programming language behind MediaBucket. | ||
|
||
--- | ||
|
||
For any questions or support, please open an issue on the [GitHub repository](https://github.com/LinuxSploit/MediaBucket/issues). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module github.com/LinuxSploit/MediaBucket | ||
|
||
go 1.22.5 | ||
|
||
require ( | ||
github.com/joho/godotenv v1.5.1 | ||
github.com/kolesa-team/go-webp v1.0.4 | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 | ||
github.com/tus/tusd/v2 v2.4.0 | ||
) | ||
|
||
require ( | ||
github.com/tus/lockfile v1.2.0 // indirect | ||
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect | ||
golang.org/x/net v0.30.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
github.com/Acconut/go-httptest-recorder v1.0.0 h1:TAv2dfnqp/l+SUvIaMAUK4GeN4+wqb6KZsFFFTGhoJg= | ||
github.com/Acconut/go-httptest-recorder v1.0.0/go.mod h1:CwQyhTH1kq/gLyWiRieo7c0uokpu3PXeyF/nZjUNtmM= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= | ||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= | ||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= | ||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= | ||
github.com/kolesa-team/go-webp v1.0.4 h1:wQvU4PLG/X7RS0vAeyhiivhLRoxfLVRlDq4I3frdxIQ= | ||
github.com/kolesa-team/go-webp v1.0.4/go.mod h1:oMvdivD6K+Q5qIIkVC2w4k2ZUnI1H+MyP7inwgWq9aA= | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
github.com/tus/lockfile v1.2.0 h1:92dMoNyeb5zaNi8eQ79WLqt/npUWUFkaM5ZM9kOMIDM= | ||
github.com/tus/lockfile v1.2.0/go.mod h1:JyfWCHNyfd7eGxudGohrkt38kuKRki6L0JH82p2e+mc= | ||
github.com/tus/tusd/v2 v2.4.0 h1:SpXmzQPCtiedkhNPl5Gn4ApQXLChPLdYrWbZQI42uJE= | ||
github.com/tus/tusd/v2 v2.4.0/go.mod h1:X+fc/MU+T+NDD5gNJHHE58jo6cQj1vlMstlT16+xlrg= | ||
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= | ||
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= | ||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= | ||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= | ||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= | ||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= | ||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
Oops, something went wrong.